ganapathi / rpms / mariadb

Forked from rpms/mariadb 4 years ago
Clone

Blame SOURCES/mysql-check-socket.sh

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