#!/bin/bash
#
# Startup script for OpenSER
#
# chkconfig: 345 85 15
# description: OpenSER is a fast SIP Proxy.
#
# processname: openser
# pidfile: /var/run/openser.pid
# config: /etc/openser/openser.cfg

# Source function library.
. /etc/rc.d/init.d/functions

oser=/usr/sbin/openser
prog=openser
RETVAL=0

[ -f /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

start() {
	gprintf "Starting %s: " "$prog"
	# there is something at end of this output which is needed to
	# report proper [ OK ] status in Fedora scripts
	daemon $oser $OPTIONS 2>/dev/null | tail -1
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && touch /var/lock/subsys/$prog
}

stop() {
	gprintf "Stopping %s: " "$prog"
	killproc $oser
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && rm -f /var/lock/subsys/$prog /var/run/$prog.pid
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	status)
		status $oser
		RETVAL=$?
		;;
	restart)
		stop
		start
		;;
	condrestart)
		if [ -f /var/run/openser.pid ] ; then
			stop
			start
		fi
		;;
	*)
		gprintf "Usage: %s {start|stop|restart|condrestart|status|help}\n" "$prog"
		exit 1
esac

exit $RETVAL
