#!/bin/sh
#
# Init file for OpenSCADA system demon.
#
# chkconfig: - 99 05
# description: Open SCADA System server daemon
#
# processname: openscada
# config: /etc/oscada.xml

WITHOUT_RC_COMPAT=1

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

PIDFILE=/var/run/openscada.pid
LOCKFILE=/var/lock/subsys/openscada
OPENSCADA=/usr/bin/openscada
ARGS="--projName=server --projUserDir --demon --pidFile=$PIDFILE"
RETVAL=0

start()
{
    export LANG=en_US.UTF-8
    start_daemon --lockfile "$LOCKFILE" --pidfile "$PIDFILE" --expect-user root -- $OPENSCADA $ARGS
    RETVAL=$?
    return $RETVAL
}

stop()
{
    stop_daemon --lockfile "$LOCKFILE" --pidfile "$PIDFILE" --expect-user root --retry TERM/30/KILL/5 -- $OPENSCADA
    RETVAL=$?
    return $RETVAL
}

restart()
{
    stop
    start
}

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

exit $RETVAL
