#!/bin/sh
#
### BEGIN INIT INFO
# Provides:  plesk-billing-plugins
# Required-Start: $remote_fs $network
# Required-Stop:  $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start Plesk CBM plugins FastCGI server
# Description:       Startup script Plesk CBM plugins FastCGI server
### END INIT INFO


PATH=/sbin:/usr/sbin:/bin:/usr/bin

DESC="Plesk CBM plugins FastCGI server"
NAME="plesk-billing-plugins-fcgi"
DAEMON="/usr/sbin/$NAME"
PROG_NAME="hspc-plugin-rpc.fcgi"
PROG="/usr/sbin/$PROG_NAME"
PIDFILE="/var/run/$NAME.pid"
OPTIONS="-u hspc -g sw-cp-server -a 127.0.0.1 -p 19004 -S -M 0775 -C 32 -F 1 -P ${PIDFILE} /usr/sbin/hspc-plugin-rpc.fcgi"

[ -x "$DAEMON" ] || exit 0

. /lib/lsb/init-functions

case "$1" in
    start)
        log_daemon_msg "Starting $DESC" $NAME
        if start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --exec $PROG --startas $DAEMON -- $OPTIONS ; then
            log_end_msg 0
        else
            log_end_msg 1
        fi
        ;;
    stop)
        log_daemon_msg "Stopping $DESC" $NAME
        if ! status_of_proc -p $PIDFILE "$PROG" $PROG_NAME >/dev/null 2>&1; then
            exit 0
        fi

        if start-stop-daemon --stop --quiet --pidfile $PIDFILE; then
            log_end_msg 0
        else
            log_end_msg 1
        fi
        ;;
    restart|reload|force-reload)
        $0 stop
        $0 start
        ;;
    status)
        status_of_proc -p $PIDFILE "$PROG" $PROG_NAME && exit 0 || exit $?
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|reload|force-reload}"
        exit 1
esac
exit $?
