Blame SOURCES/mysql.init.in

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