#!/bin/sh
# /etc/init.d/soagent: start SysOrb monitoring agent.
#
# $Id: soagent.debian22.in,v 1.4 2002/03/10 18:57:18 ksm Exp $
#
# (C) 1999, 2000, 2001, 2002 - Evalesco ApS.
#
# Agent init-script for SysOrb 2.6 (build-2556)
#
# For Debian GNU/Linux 2.2
#

SOAGENT=/usr/sbin/soagent

#
# 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

#
# No user serviceable parts below
#
test -x "$SOAGENT" || exit 0

case "$1" in
  start)
	echo -n "Starting SysOrb Agent: "

	if test "$ALLOW_ROOT" == YES; then
	    OUTPUT="`$SOAGENT 2>&1`"
	else
	    OUTPUT="`su -c \"$SOAGENT 2>&1\" -s /bin/sh sysorb`"
	fi
	if test -n "$OUTPUT"; then
		echo
		echo "Error starting SysOrb agent:"
		echo "$OUTPUT"
		exit 1
	    fi
	echo "soagent."
	touch /var/run/soagent
	;;
  stop)
        echo -n "Shutting down SysOrb Agent: "
	if test "$ALLOW_ROOT" == YES; then
	    start-stop-daemon --stop --exec "$SOAGENT" --user root
	else
	    start-stop-daemon --stop --exec "$SOAGENT" --user sysorb
	fi
	echo "done."
        rm -f /var/run/soagent
        ;;
  restart)
	$0 stop 
	$0 start
	;;
  status)
	if test -f /var/run/soagent; then
	    echo "The SysOrb Agent is running"
	else
	    echo "The SysOrb Agent is stopped"
	fi
	;;
  *)
        echo "Usage: soagent {start|stop|restart|status}"
        exit 1
esac

exit 0