#! /bin/sh
# Mooix LSB init script.

# This is to make it work with the broken Mandrake 9.1 excuse for 
# a lsb compliant init system.
# chkconfig: 2345 60 60
# description: Unix is the moo.
# processname: mood
# config: /etc/mooix.conf
# pidfile: /var/run/moodd.pid

### BEGIN INIT INFO
# Short-Description: Mooix
# Required-Start: $local_fs $remote_fs $syslog
# Default-Start: 2 3 5
# Default-Stop: 0 1 6
### END INIT INFO

DAEMON=mood
test -f /usr/sbin/$DAEMON || exit 5

# Source LSB functions.
. /lib/lsb/init-functions

# Umask for the moo. Important that this *not* be 002; group-writables
# files have special semantics in the moo.
umask 022

# Source conffile, for starthook and stophook.
if [ -e /etc/mooix.conf ]; then
	. /etc/mooix.conf
fi

case "$1" in
  start)
	# For robustness.
	install -d /var/run/mooix
 
	# Don't start the moo id the daemon is already running.
	if [ -n "$(pidofproc $DAEMON)" ]; then
		log_success_msg "already running"
		exit 0
	fi
	
	start_daemon $DAEMON
	eval $STARTHOOK >/dev/null
	log_success_msg "started"
	;;
  stop)
  	# Only run stophook if daemon is running.
	if [ -n "$(pidofproc $DAEMON)" ]; then
  		eval $STOPHOOK >/dev/null
	else
		log_success_msg "not running"
		exit 0
	fi
	killproc $DAEMON
	rm -f /var/run/mood.pid
	log_success_msg "stopped"
	;;
  restart|force-reload)
  	$0 stop
	$0 start
	;;
  status)
	if [ -n "$(pidofproc $DAEMON)" ]; then
		echo "running"
		exit 0
	else
		echo "stopped"
		exit 3
	fi
  	;;
  *)
	log_failure_msg "Usage: /etc/init.d/$NAME {start|stop|restart|force-reloaad|status}" >&2
	exit 2
	;;
esac

exit 0
