#! /bin/sh
### BEGIN INIT INFO
# Provides: OpenSCADA
# Required-Start:
# Should-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OpenSCADA
# Description: Start OpenSCADA
### END INIT INFO

DESC="OpenSCADA"
NAME=openscada
PIDFILE=/var/run/$NAME.pid
DAEMON=/usr/bin/$NAME
DAEMON_ARGS="--demon --pid-file=$PIDFILE"

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
    LANG=en_US.UTF-8
    log_action_begin_msg "Starting $DESC"
    start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS && log_action_end_msg $?
}

#
# Function that stops the daemon/service
#
do_stop()
{
    log_action_begin_msg "Stopping $DESC"
    start-stop-daemon --stop --pidfile $PIDFILE --retry=TERM/30/KILL/5 --name $NAME && log_action_end_msg $?
}

case "$1" in
    start)
	do_start
	;;
    stop)
	do_stop
	;;
    status)
	status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
	;;
    restart|reload|force-reload)
	do_stop
	do_start
	;;
    *)
	echo "Usage: $0 {start|stop|status|restart|force-reload}"
	exit 3
	;;
esac

:
