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