75032c4
#!/bin/sh
75032c4
#
75032c4
# @DAEMON_NAME@	This shell script takes care of starting and stopping
75032c4
#		the MySQL subsystem (mysqld).
75032c4
#
75032c4
# chkconfig: - 64 36
75032c4
# description:	MySQL database server.
75032c4
# processname: mysqld
75032c4
# config: @sysconfdir@/my.cnf
75032c4
# pidfile: /var/run/@DAEMON_NAME@/@DAEMON_NAME@.pid
75032c4
### BEGIN INIT INFO
75032c4
# Provides: mysqld
75032c4
# Required-Start: $local_fs $remote_fs $network $named $syslog $time
75032c4
# Required-Stop: $local_fs $remote_fs $network $named $syslog $time
75032c4
# Short-Description: start and stop MySQL server
75032c4
# Description: MySQL database server
75032c4
### END INIT INFO
75032c4
75032c4
# Source function library.
75032c4
. /etc/rc.d/init.d/functions
75032c4
75032c4
# Source networking configuration.
75032c4
. /etc/sysconfig/network
75032c4
75032c4
75032c4
exec="@bindir@/mysqld_safe"
75032c4
prog="@DAEMON_NAME@"
75032c4
75032c4
# Set timeouts here so they can be overridden from /etc/sysconfig/@DAEMON_NAME@
75032c4
STARTTIMEOUT=300
75032c4
STOPTIMEOUT=60
75032c4
75032c4
# User and group the daemon will run under
75032c4
MYUSER=mysql
75032c4
MYGROUP=mysql
75032c4
75032c4
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
75032c4
75032c4
lockfile=/var/lock/subsys/$prog
75032c4
75032c4
# get options from my.cnf
75032c4
source "@libexecdir@/mariadb-scripts-common"
75032c4
75032c4
start(){
75032c4
    [ -x $exec ] || exit 5
75032c4
    # check to see if it's already running
75032c4
    MYSQLDRUNNING=0
75032c4
    if [ -f "$pidfile" ]; then
75032c4
	MYSQLPID=`cat "$pidfile" 2>/dev/null`
75032c4
	if [ -n "$MYSQLPID" ] && [ -d "/proc/$MYSQLPID" ] ; then
75032c4
	    MYSQLDRUNNING=1
75032c4
	fi
75032c4
    fi
75032c4
    RESPONSE=`@bindir@/mysqladmin --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1`
75032c4
    if [ $MYSQLDRUNNING = 1 ] && [ $? = 0 ]; then
75032c4
	# already running, do nothing
75032c4
	action $"Starting $prog: " /bin/true
75032c4
	ret=0
75032c4
    elif [ $MYSQLDRUNNING = 1 ] && echo "$RESPONSE" | grep -q "Access denied for user"
75032c4
    then
75032c4
	# already running, do nothing
75032c4
	action $"Starting $prog: " /bin/true
75032c4
	ret=0
75032c4
    else
75032c4
        @libexecdir@/mariadb-prepare-db-dir $MYUSER $MYGROUP || return 4
75032c4
        @libexecdir@/mariadb-check-socket || return 1
75032c4
75032c4
	# Pass all the options determined above, to ensure consistent behavior.
75032c4
	# In many cases mysqld_safe would arrive at the same conclusions anyway
75032c4
	# but we need to be sure.  (An exception is that we don't force the
75032c4
	# log-error setting, since this script doesn't really depend on that,
75032c4
	# and some users might prefer to configure logging to syslog.)
75032c4
	# Note: set --basedir to prevent probes that might trigger SELinux
75032c4
	# alarms, per bug #547485
75032c4
	$exec   --datadir="$datadir" --socket="$socketfile" \
75032c4
		--pid-file="$pidfile" \
75032c4
		--basedir=@prefix@ --user=$MYUSER >/dev/null 2>&1 &
75032c4
	safe_pid=$!
75032c4
75032c4
	# Wait until the daemon is up
75032c4
        @libexecdir@/mariadb-wait-ready "$safe_pid"
75032c4
        ret=$?
75032c4
75032c4
	if [ $ret -eq 0 ]; then
75032c4
	    action $"Starting $prog: " /bin/true
75032c4
	    chmod o+r $pidfile >/dev/null 2>&1
75032c4
	    touch $lockfile
75032c4
	else
75032c4
	    action $"Starting $prog: " /bin/false
75032c4
	fi
75032c4
    fi
75032c4
    return $ret
75032c4
}
75032c4
75032c4
stop(){
75032c4
	if [ ! -f "$pidfile" ]; then
75032c4
	    # not running; per LSB standards this is "ok"
75032c4
	    action $"Stopping $prog: " /bin/true
75032c4
	    return 0
75032c4
	fi
75032c4
	MYSQLPID=`cat "$pidfile" 2>/dev/null`
75032c4
	if [ -n "$MYSQLPID" ]; then
75032c4
	    if ! [ -d "/proc/$MYSQLPID" ] ; then
75032c4
		# process doesn't run anymore
75032c4
		action $"Stopping $prog: " /bin/true
75032c4
		return 0
75032c4
	    fi
75032c4
	    /bin/kill "$MYSQLPID" >/dev/null 2>&1
75032c4
	    ret=$?
75032c4
	    if [ $ret -eq 0 ]; then
75032c4
		TIMEOUT="$STOPTIMEOUT"
75032c4
		while [ $TIMEOUT -gt 0 ]; do
75032c4
		    /bin/kill -0 "$MYSQLPID" >/dev/null 2>&1 || break
75032c4
		    sleep 1
75032c4
		    let TIMEOUT=${TIMEOUT}-1
75032c4
		done
75032c4
		if [ $TIMEOUT -eq 0 ]; then
75032c4
		    echo "Timeout error occurred trying to stop MySQL Daemon."
75032c4
		    ret=1
75032c4
		    action $"Stopping $prog: " /bin/false
75032c4
		else
75032c4
		    rm -f $lockfile
75032c4
		    rm -f "$socketfile"
75032c4
		    action $"Stopping $prog: " /bin/true
75032c4
		fi
75032c4
	    else
75032c4
		# kill command failed, probably insufficient permissions
75032c4
		action $"Stopping $prog: " /bin/false
75032c4
		ret=4
75032c4
	    fi
75032c4
	else
75032c4
	    # failed to read pidfile, probably insufficient permissions
75032c4
	    action $"Stopping $prog: " /bin/false
75032c4
	    ret=4
75032c4
	fi
75032c4
	return $ret
75032c4
}
75032c4
 
75032c4
restart(){
75032c4
    stop
75032c4
    start
75032c4
}
75032c4
75032c4
condrestart(){
75032c4
    [ -e $lockfile ] && restart || :
75032c4
}
75032c4
75032c4
75032c4
# See how we were called.
75032c4
case "$1" in
75032c4
  start)
75032c4
    start
75032c4
    ;;
75032c4
  stop)
75032c4
    stop
75032c4
    ;;
75032c4
  status)
75032c4
    status -p "$pidfile" $prog
75032c4
    ;;
75032c4
  restart)
75032c4
    restart
75032c4
    ;;
75032c4
  condrestart|try-restart)
75032c4
    condrestart
75032c4
    ;;
75032c4
  reload)
75032c4
    exit 3
75032c4
    ;;
75032c4
  force-reload)
75032c4
    restart
75032c4
    ;;
75032c4
  *)
75032c4
    echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
75032c4
    exit 2
75032c4
esac
75032c4
75032c4
exit $?