#! /bin/bash
#
# chkconfig: 35 99 12
# Openarchive  Bring up/down  openarchive service
# description: Activates/Deactivates the archd daemon. 
#

# Source function library.

# if the archd binary isn't around we can't function.
[ -x /usr/local/bin/archd ] || exit 1

CWD=$(pwd)
rc=0

# See how we were called.
case "$1" in
  start)
	    rc=0
        /usr/local/bin/archd
        rc=$? 
        if [ $rc -eq 0 ]; then
            touch /var/lock/subsys/archd
        fi
        touch /etc/avahi/services/cvlt.service
        /opt/commvault/MediaAgent/cvavahi.py allow_interfaces
        ;;
  stop)
        pid=`ps -C archd | grep archd | awk '{print $1}'`
        if [ ! -z "$pid" ]; then
            kill -s 9 $pid
        fi
        rm -f /var/lock/subsys/archd
        ;;
  status)
        pid=`ps -C archd | grep archd | awk '{print $1}'`
        if [ ! -z "$pid" ]; then
             echo "/usr/local/bin/archd pid: $pid running"
        fi
	;;
  restart|reload|force-reload)
        cd "$CWD"
	    $0 stop
	    $0 start
	    rc=$?
	;;
  *)
        echo $"Usage: $0 {start|stop|status|restart|reload|force-reload}"
        exit 2
esac

exit $rc
