Blame SOURCES/mysql-check-socket.sh

a41a5b
#!/bin/sh
a41a5b
a41a5b
# We check if there is already a process using the socket file,
a41a5b
# since otherwise the systemd service file could report false
a41a5b
# positive result when starting and mysqld_safe could remove
a41a5b
# a socket file, which is actually being used by a different daemon.
a41a5b
a41a5b
source "`dirname ${BASH_SOURCE[0]}`/mysql-scripts-common"
a41a5b
a41a5b
if test -e "$socketfile" ; then
a41a5b
    echo "Socket file $socketfile exists." >&2
a41a5b
a41a5b
    # no write permissions
a41a5b
    if ! test -w "$socketfile" ; then
a41a5b
        echo "Not enough permission to write to the socket file $socketfile, which is suspicious." >&2
a41a5b
        echo "Please, remove $socketfile manually to start the service." >&2
a41a5b
        exit 1
a41a5b
    fi
a41a5b
a41a5b
    # not a socket file
a41a5b
    if ! test -S "$socketfile" ; then
a41a5b
        echo "The file $socketfile is not a socket file, which is suspicious." >&2
a41a5b
        echo "Please, remove $socketfile manually to start the service." >&2
a41a5b
        exit 1
a41a5b
    fi
a41a5b
a41a5b
    # some process uses the socket file
a41a5b
    response=`@bindir@/mysqladmin --no-defaults --socket="$socketfile" --user=UNKNOWN_MYSQL_USER --connect-timeout="${CHECKSOCKETTIMEOUT:-10}" ping 2>&1`
a41a5b
    if [ $? -eq 0 ] || echo "$response" | grep -q "Access denied for user" ; then
a41a5b
        echo "Is another MySQL daemon already running with the same unix socket?" >&2
a41a5b
        echo "Please, stop the process using the socket $socketfile or remove the file manually to start the service." >&2
a41a5b
        exit 1
a41a5b
    fi
a41a5b
a41a5b
    # socket file is a garbage
a41a5b
    echo "No process is using $socketfile, which means it is a garbage, so it will be removed automatically." >&2
a41a5b
fi
a41a5b
a41a5b
exit 0