#!/bin/sh
#
# opensips		This shell script takes care of starting and stopping opensips
#
# chkconfig:	2345 20 80
# description:	opensips
# processname:	opensips

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

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
if is_yes "${NETWORKING}"; then
	if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
		msg_network_down opensips
		exit 1
	fi
else
	exit 0
fi

start() {
	# Start daemons.
	if [ ! -f /var/lock/subsys/opensips ]; then
		msg_starting opensips
		daemon opensips -P /var/run/opensips.pid
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/opensips
	else
		msg_already_running opensips
	fi
}

stop() {
	# Stop daemons.
	if [ -f /var/lock/subsys/opensips ]; then
		msg_stopping opensips
		killproc opensips
		rm -f /var/lock/subsys/opensips >/dev/null 2>&1
	else
		msg_not_running opensips
	fi
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart|force-reload)
	stop
	start
	;;
  status)
	status opensips
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
