#!/bin/bash
#
# sip-redirect Startup script for the sip-redirect server
#
# chkconfig: - 95 15
# description: Tiny IPv4 and IPv6 SIP redirect server written in Perl
# processname: sip-redirect
# config: /etc/sip-redirect.conf
# pidfile: /var/run/sip-redirect.pid

### BEGIN INIT INFO
# Provides: sip-redirect
# Required-Start: $local_fs $network $named $remote_fs $syslog
# Required-Stop: $local_fs $network $named $remote_fs $syslog
# Short-Description: Startup script for the sip-redirect server
# Description: Tiny IPv4 and IPv6 SIP redirect server written in Perl
### END INIT INFO

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

# Paths to the scripts and files
sip=/usr/bin/sip-redirect
prog=sip-redirect
user=${USER-sip}
pidfile=${PIDFILE-/var/run/sip-redirect.pid}
lockfile=${LOCKFILE-/var/lock/subsys/sip-redirect}
RETVAL=0

start() {
	echo -n $"Starting $prog: "
	daemon --user $user --pidfile $pidfile $sip $OPTIONS
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && touch ${lockfile}
	return $RETVAL
}

stop() {
	echo -n $"Stopping $prog: "
	killproc $sip
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
	status $sip
	RETVAL=$?
	;;
  restart|reload)
	stop
	start
	;;
  condrestart)
	if [ -f ${pidfile} ] ; then
		stop
		start
	fi
	;;
  reload)
	reload
	;;
  *)
	echo $"Usage: $prog {start|stop|restart|condrestart|reload|status}"
	exit 1
esac

exit $RETVAL
