#!/bin/bash
#
# Copyright (c) 2007-2009 ZeroC, Inc. All rights reserved.
#
# icegridnode   This shell script takes care of starting and 
#               stopping the icegridnode daemon.
#
# chkconfig: - 61 75
# description: The IceGrid node daemon. \
# IceGrid is the server deployment and monitoring for the Internet \
# Communications Engine (Ice). An IceGrid domain consists of one master \
# registry, zero or more slave registries, and zero or more IceGrid nodes.

WITHOUT_RC_COMPAT=1

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

#
# The IceGrid node user; root is allowed, but not necessary, therefore
# it is recommended to use a non-root account.
#
user=ice

#
# Ask for a password at startup?
#
prompt=no

#
# The IceGrid node configuration file
#
nodeconf="/etc/icegridnode.conf"

prog="/usr/bin/icegridnode"

progbase=${prog##*/}
pidfile=/var/run/$progbase.pid

options="--daemon --pidfile $pidfile --Ice.Config=$nodeconf"

RETVAL=0
LOCKFILE=/var/lock/subsys/$progbase

daemonoptions="--lockfile $LOCKFILE"
if [ "$user" != "root" ]
    then
    daemonoptions="$daemonoptions --expect-user $user"
fi

start() {
        if [ "$user" != "root" ]
            then
            if [ ! -e $pidfile ]
                then
                touch $pidfile
            fi
            chown $user $pidfile
        fi

        start_daemon $daemonoptions -- $prog $options
        RETVAL=$?
        return $RETVAL
}

stop() {
        stop_daemon $daemonoptions -- $prog
        RETVAL=$?
        return $RETVAL
}


# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status $daemonoptions $prog
        RETVAL=$?
        ;;
  restart|reload)
        stop
        start
        RETVAL=$?
        ;;
  condrestart)
        if [ -f $LOCKFILE ]; then
            stop
            start
            RETVAL=$?
        fi
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|condrestart|status}"
        exit 1
esac

exit $RETVAL
