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