#! /bin/sh
#
# skeleton	example file to build /etc/init.d/ scripts.
#		This file should be used to construct scripts for /etc/init.d.
#
#		Written by Miquel van Smoorenburg <miquels@cistron.nl>.
#		Modified for Debian GNU/Linux
#		by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#
# Version:	@(#)skeleton  1.8  03-Mar-1998  miquels@cistron.nl
#
# This file was automatically customized by dh-make on Fri,  1 Nov 2002 15:11:07 +0100
#set -x
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/metalog
DAEMON_OPTIONS="-B -s -d"
NAME=metalog
DESC=metalog

test -f $DAEMON || exit 0

set -e

pids=`ps aux | awk '/metalog \[(MASTER|KERNEL)\]/{print $2}' | sort -r`

case "$1" in
  start)
	[ -z "$pids" ] || exit 0
	echo -n "Starting $DESC: $NAME"
	$DAEMON $DAEMON_OPTIONS > /dev/null 2>&1
	echo ".";
	;;
  stop)
	echo -n "Stopping $DESC: $NAME"
	[ -z "$pids" ] || kill $pids
	echo "."
	;;
  force-stop)
  	[ -z "$pids" ] && exit 0
        echo -n "Stopping (forced) $DESC: $NAME"
        kill -9 $pids
        echo "."
  	;;
  restart|reload)
	echo -n "Restarting $DESC: $NAME"
	$0 stop
	sleep 1
	$0 start
	echo "."
	;;
  force-reload)
  	echo -n "Restarting (force) $DESC: $NAME"
	$0 force-stop
	sleep 1
	$0 start
	echo "."
	;;
  bufferize)
  	[ -z "$pids" ] && exit 0
  	echo -n "Bufferizing $DESC: $NAME"
  	kill -USR2 $pids
	echo "."
	;;
  synchronize)
  	[ -z "$pids" ] && exit 0
  	echo -n "Synchronizing $DESC: $NAME"
  	kill -USR1 $pids
	echo "."
	;;
  *)
	N=/etc/init.d/$NAME
	# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: $N {start|stop|force-stop|restart|reload|force-reload|bufferize|synchronize}" >&2
	exit 1
	;;
esac

exit 0
