Blame SOURCES/mysql.init.in

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