#!/bin/sh
#
# This script manages the Scmbug daemon.

# chkconfig: 35 85 15
# description: Integration of Software Configuration Management with Bug-tracking.
# pidfile: /var/run/scmbug_daemon.pid
# config: /etc/scmbug/daemon.conf

# Basic support for the Linux Standard Base Specification 1.0.0
### BEGIN INIT INFO
# Provides: Scmbug
# Required-Start: $network
# Required-Stop:
# Default-Start: 3 5
# Default-Stop:
# Description: Integration of Software Configuration Management with Bug-tracking.
### END INIT INFO

PID_FILE=`cat /etc/scmbug/daemon.conf | grep -i daemon_pidfile | sed -e 's/.*=> "//g' | sed -e 's/".*//'`

if ! [ -x /usr/sbin/scmbug_daemon.pl ]; then
    echo "Daemon file is missing"
    exit 0
fi

case "$1" in
    start)
	echo -n "Starting SCM to bug-tracking integration daemon:"
	echo -n " scmbug_daemon"; /usr/sbin/scmbug_daemon.pl /etc/scmbug/daemon.conf
	echo "."
	;;
    stop)
	echo -n "Stopping SCM to bug-tracking integration daemon:"
	echo -n " scmbug_daemon"; kill -KILL `cat ${PID_FILE}` && rm ${PID_FILE}
	echo "."
	;;
    restart|force-reload)
	$0 stop
	$0 start
	echo "."
	;;
    *)
	echo "Usage: /etc/init.d/scmbug-server {start|stop|restart|force-reload}"
	exit 1
	;;
esac

exit 0

