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