#!/bin/bash
#
# Copyright (c) 2007-2009 ZeroC, Inc. All rights reserved.
#
# glacier2router    This shell script takes care of starting and 
#                   stopping the glacier2router daemon.
#
# chkconfig: - 62 74
# description: The Glacier2 router daemon. \
# Glacier2 is the firewall traversal service for the Internet \ 
# Communications Engine (Ice).

WITHOUT_RC_COMPAT=1

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

#
# The Glacier2 router 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 Glacier2 router configuration file
#
routerconf="/etc/glacier2router.conf"

prog="/usr/bin/glacier2router"

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

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

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
