#!/bin/sh
#set -u  # force better programming and ability to use check for not set
if [ "${1:-}" = "-x" ] ; then set -xv; shift; fi

# Starts monitor server after a machine boots
if [ -f /usr/local/etc/setups.sh ]; then
    # this check is required by current rpm build process, do not remove!!!!
    . /usr/local/etc/setups.sh
    setup enstore
fi

estat=0

case "$1" in

  start)
        echo "Starting monitor server"
        $ENSTORE_DIR/bin/monitor_server start
        ;;

  stop)
        echo "Stoping monitor server"
        $ENSTORE_DIR/bin/monitor_server stop
        ;;

  install)
        x=/etc/rc.d/init.d/monitor_server-boot
        rm -f $x; cp $ENSTORE_DIR/bin/monitor_server-boot $x
        cd /etc/rc.d/rc3.d
        x=S99zzzmonitor_server-boot
        rm -f $x; ln -s ../init.d/monitor_server-boot $x
        cd /etc/rc.d/rc6.d
        x=K01aaamonitor_server-boot
        rm -f $x; ln -s ../init.d/monitor_server-boot $x
        ;;
  *)
        echo "Usage: /etc/rc.d/init.d/monitor_server-boot {start|stop}"
        estat=1
        ;;
esac

exit $estat
