Blame SOURCES/mysql.init.in

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