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