Blame SOURCES/mysql-check-socket.sh

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