Blame SOURCES/mysql.init.in

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