#!/bin/sh
# Begin $rc_base/init.d/mysql

# Based on sysklogd script from LFS-3.1 and earlier.
# Rewritten by Gerard Beekmans  - gerard@linuxfromscratch.org

. /etc/sysconfig/rc
. $rc_functions

pid_file=/var/lib/mysql/`/bin/hostname`.pid

case "$1" in
	start)
		echo "Starting MySQL daemon..."
		failure=0
		if test -f "$pid_file"
		then
			if /bin/ps p `cat $pid_file` | grep mysqld >/dev/null
			then
				print_status warning running
				exit 0
			else
				rm -f $pid_file
				if test -f $pid_file
				then
					failure=1
				fi
			fi
		fi
		if [ $failure = 1 ]
		then
			print_status failure
		else
			/usr/bin/mysqld_safe --user=mysql 2>&1 >/dev/null &
			evaluate_retval
		fi
		;;

	stop)
		echo "Stopping MySQL daemon..."
		if test -s "$pid_file"
		then
			kill `cat $pid_file`
			sleep 1
			failure=0
			while [ -s $pid_file -a "$flags" != aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ]
			do
				[ -z "$flags" ]
				flags=a$flags
				sleep 1
			done
			if [ -s $pid_file ]
				then failure=1
			fi
			(exit $failure)
			evaluate_retval
		else
			print_status warning not_running
		fi
		;;

	restart)
		$0 stop
		sleep 1
		$0 start
		;;

	status)
		statusproc /usr/sbin/mysqld
		;;

	*)
		echo "Usage: $0 {start|stop|restart|status}"
		exit 1
		;;
esac

# End $rc_base/init.d/mysql
