Blame SOURCES/mysql.init.in

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