#!/bin/bash
# chkconfig: - 64 36
# description:  Vtiger Asterisk integration daemon

# Init script for AsteriskClient
# AsteriskClient is a PHP script which must be running
# all the time to provide informations about incoming calls in Vtiger CRM

. /etc/rc.d/init.d/functions


start(){
	/usr/sbin/vtiger_safe_astclient
}

stop(){
    kill -9 $(pgrep -f vtiger_safe_astclient) $(pgrep -f AsteriskClient.php)
}


case "$1" in
  start)
        echo -n $"Starting Vtiger CRM AsteriskClient: "
        start
        RETVAL=$?
        ;;
  stop)
        echo -n $"Stoping Vtiger CRM AsteriskClient: "
        stop
        RETVAL=$?
        ;;
  restart)
        echo -n $"Restarting Vtiger CRM AsteriskClient: "
        stop && start
        RETVAL=$?
        ;;
  status)
        status
        ;;
  *)
        echo "Usage: $0 start|stop|restart|status"
  ;;
esac

if [ $RETVAL -eq 0 ]; then
        echo_success
else
        echo_failure
fi
echo

exit $RETVAL

