#!/bin/sh
# -*- sh -*-
# Copyright (c) 2002 Evalesco ApS
#
# /etc/init.d/soagent
#
#### BEGIN INIT INFO
# Provides:       soagent
# Required-Start: $network $named $remote_fs $syslog 
# Required-Stop:  $local_fs $network $named $remote_fs $syslog 
# Default-Start:  3 5
# Default-Stop:
# Description:    Start the SysOrb Agent daemon
### END INIT INFO

. /etc/rc.config
. /etc/rc.status

#
# You can change this setting if you do now want the sysorb
# client to run as root.  This will cause various checks to
# not function (!)
#
ALLOW_ROOT=YES


base=${0##*/}
link=${base#*[SK][0-9][0-9]}
test $link = $base && START_SOAGENT="yes"
test "$START_SOAGENT" = yes || exit 0

SOAGENT_BIN=/usr/sbin/soagent
SOAGENT_CONF=/etc/sysorb/agent.conf
SOAGENT_PID=/var/run/soagent.pid
test -x $SOAGENT_BIN || exit 5

rc_reset

case "$1" in
    start)
        echo -n "Starting SysOrb Agent: "
        if [ ! -e ${SOAGENT_CONF} ]; then
            echo "Missing ${SOAGENT_CONF} file";
            exit 6
        fi
	if test "$ALLOW_ROOT" = YES; then
	    startproc -f -p ${SOAGENT_PID} ${SOAGENT_BIN} 
	else
	    startproc -f -p ${SOAGENT_PID} -u sysorb ${SOAGENT_BIN} 
	fi
	rc_status -v
        ;;
    stop)
        echo -n "Shutting down SysOrb Agent: "
        killproc -INT -p ${SOAGENT_PID} ${SOAGENT_BIN} 
	rc_status -v
        ;;
    try-restart)
	$0 stop && $0 start

	rc_status
	;;
    restart)
	$0 stop
	$0 start

	rc_status
        ;;
    force-reload)
	echo -n "Reload service soagent"
	$0 stop && $0 start
	rc_status
	;;
    reload)
	echo -n "Reload service soagent"
	echo ": not supported"
	exit 3
	;;
    status)
        echo -n "Checking for soagent: "
	checkproc -p ${SOAGENT_PID} ${SOAGENT_BIN}; rc=$?
	if test $rc = 0; then echo "OK"
	else
	    echo "No process"
	    exit 3
	fi
        ;;
    probe)
	;;
    *)
        echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
        exit 1
	;;
esac

rc_exit

