Blame SOURCES/mysql-check-socket.sh

dbc8c5
#!/bin/sh
dbc8c5
dbc8c5
# We check if there is already a process using the socket file,
dbc8c5
# since otherwise the systemd service file could report false
dbc8c5
# positive result when starting and mysqld_safe could remove
dbc8c5
# a socket file, which is actually being used by a different daemon.
dbc8c5
dbc8c5
source "`dirname ${BASH_SOURCE[0]}`/mysql-scripts-common"
dbc8c5
dbc8c5
if test -e "$socketfile" ; then
dbc8c5
    echo "Socket file $socketfile exists." >&2
dbc8c5
dbc8c5
    # no write permissions
dbc8c5
    if ! test -w "$socketfile" ; then
dbc8c5
        echo "Not enough permission to write to the socket file $socketfile, which is suspicious." >&2
dbc8c5
        echo "Please, remove $socketfile manually to start the service." >&2
dbc8c5
        exit 1
dbc8c5
    fi
dbc8c5
dbc8c5
    # not a socket file
dbc8c5
    if ! test -S "$socketfile" ; then
dbc8c5
        echo "The file $socketfile is not a socket file, which is suspicious." >&2
dbc8c5
        echo "Please, remove $socketfile manually to start the service." >&2
dbc8c5
        exit 1
dbc8c5
    fi
dbc8c5
dbc8c5
    # some process uses the socket file
dbc8c5
    if fuser "$socketfile" &>/dev/null ; then
dbc8c5
        socketpid=$(fuser "$socketfile" 2>/dev/null)
dbc8c5
        echo "Is another MySQL daemon already running with the same unix socket?" >&2
dbc8c5
        echo "Please, stop the process $socketpid or remove $socketfile manually to start the service." >&2
dbc8c5
        exit 1
dbc8c5
    fi
dbc8c5
dbc8c5
    # socket file is a garbage
dbc8c5
    echo "No process is using $socketfile, which means it is a garbage, so it will be removed automatically." >&2
dbc8c5
fi
dbc8c5
dbc8c5
exit 0