#!/bin/sh
#
# shellinabox   This shell script takes care of starting and stopping
#               shellinabox.
#
# chkconfig: 345 95 05
# description: Publish command line shell through AJAX interface.
# config: /etc/template.conf
# pidfile: /var/run/shellinaboxd.pid

### BEGIN INIT INFO
# Provides: shellinabox
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: Publish command line shell through AJAX interface.
# Description: Publish command line shell through AJAX interface.
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

RUN_AS=_shellinaboxd
PIDFILE=/var/run/shellinaboxd.pid
SourceIfExists /etc/sysconfig/shellinaboxd

LOCKFILE=/var/lock/subsys/shellinabox
RETVAL=0

start()
{
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user "$RUN_AS" -- shellinaboxd --background=$PIDFILE $OPTIONS
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user "$RUN_AS" -- shellinaboxd
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

reload()
{
	msg_reloading shellinaboxd
	stop_daemon --pidfile "$PIDFILE" --expect-user "$RUN_AS" -HUP -- shellinaboxd
	RETVAL=$?
	return $RETVAL
} 

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user "$RUN_AS" -- shellinaboxd
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
