Blame SOURCES/mysql.init.in

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