#!/bin/sh
#
### BEGIN INIT INFO
# Provides:          Parallels Premium Outgoing Antispam
# Required-Start:    $syslog $remote_fs
# Required-Stop:     $syslog $remote_fs
# Should-Start:      $network $named $syslog
# Should-Stop:       $network $named $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Parallels Premium Outgoing Antispam
# Description:       Startup script for Parallels Premium Outgoing Antispam
#
### END INIT INFO

DESC="Parallels Premium Outgoing Antispam"
NAME=ctasd
DAEMON=/opt/ctch/ctasd/$NAME
BINARY="/opt/ctch/ctasd/ctasd.bin"
PIDFILE=/var/run/$NAME/$NAME.pid
DAEMON_ARGS="-c /etc/ctasd/ctasd-out.conf --pid $PIDFILE"
SCRIPTNAME=/etc/init.d/ctasd_intd

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

. /etc/rc.status
rc_reset

case "$1" in
    start)
		if [ ! -d `dirname $PIDFILE` ]; then
			mkdir -p `dirname $PIDFILE`
			chown nobody `dirname $PIDFILE`
		fi

		if [ -e $pidfile ]; then
			/sbin/checkproc -p $PIDFILE $BINARY
			ret=$?
			if [ $ret = 1 ]; then
				echo "Warning: found stale pidfile"
			elif [ $ret = 0 ]; then
				echo "$DESC is already running ($PIDFILE)"
				rc_failed $ret
				rc_status -v1
				rc_exit
			fi
		fi

		echo -n "Starting $DESC "
		/sbin/start_daemon $DAEMON $DAEMON_ARGS
		rc_status -v
	;;
    stop)
		echo -n "Shutting down $DESC "
		/sbin/killproc -p $PIDFILE $BINARY
		rc_status -v
	;;
    try-restart|condrestart)
		$0 status
		if test $? = 0; then
			$0 restart
		else
			rc_reset
		fi
		rc_status
	;;
    restart|force-reload)
		$0 stop
		$0 start

		rc_status
	;;
    status)
		echo -n "Checking for service $DESC "
		/sbin/checkproc -p $PIDFILE $BINARY
		rc_status -v
	;;
    *)
		echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload}"
		exit 1
	;;
esac
rc_exit
