#!/bin/sh
#
# plesk-agent
### BEGIN INIT INFO
# Provides:  plesk-agent
# Required-Start: $remote_fs $network
# Required-Stop:  $remote_fs $network
# chkconfig:   - 80 20
# Default-Start: 2 3 4 5 
# Default-Stop: 0 1 6
# Short-Description: start Plesk Agent FastCGI server
# Description:       Startup script of Plesk Agent FastCGI server
### END INIT INFO

prog="agent.cgi"
binary="/opt/psa_agent/www/agent.cgi"
pidfile="/var/run/${prog}.pid"
options="-s /var/run/agent.sock -P $pidfile -U sw-cp-server -M 0700"

test -x $binary || { echo "$binary not installed"; 
		if [ "$1" = "stop" ]; then exit 0;
		else exit 5; fi; }

. /etc/rc.status

# Reset status of this service
rc_reset

case "$1" in
	start)
		echo -n "Starting $prog "
		$binary $options
		rc_status -v
		;;
	stop)
		echo -n "Shutting down $prog "
		/sbin/killproc -p $pidfile -TERM $prog
		rc_status -v
		;;
	try-restart|condrestart)
		$0 status
		if test $? = 0; then
			$0 restart
		else
			rc_reset		# Not running is not a failure.
		fi
		rc_status
		;;
	restart|reload|force-reload)
		$0 stop
		$0 start
		rc_status
		;;
	status)
		echo -n "Checking for service $prog "
		/sbin/checkproc -p $pidfile $prog
		rc_status -v
		;;
	*)
		echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}"
		exit 1
		;;
esac
rc_exit
