#!/bin/bash
### BEGIN INIT INFO
# Provides:          isecspdaemon
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Should-Start:      $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: VPN Client Daemon
# Description:       VPN Client Daemon
### END INIT INFO
# start on filesystem
# stop on runlevel [06]

CLIENT_DAEMON_PROGRAM_NAME="isecspdaemon"
vpnd_path="/usr/bin/$CLIENT_DAEMON_PROGRAM_NAME"

case "$1" in
start) 
	if ! pgrep -x "$CLIENT_DAEMON_PROGRAM_NAME" > /dev/null; then
		$vpnd_path &
		for i in {1..10}; do
			sleep 1
			if pgrep -x "$CLIENT_DAEMON_PROGRAM_NAME" > /dev/null; then
				break
			fi
		done
	fi
;;
stop)                                                                               
pkill -9 -x $CLIENT_DAEMON_PROGRAM_NAME
;;                                                                              
restart|force-reload)                                                                                                         
pkill -9 -x $CLIENT_DAEMON_PROGRAM_NAME
$vpnd_path &
;;
status)
	if pgrep -x "$CLIENT_DAEMON_PROGRAM_NAME" > /dev/null; then
		echo "$CLIENT_DAEMON_PROGRAM_NAME is running..."
	else
		echo "$CLIENT_DAEMON_PROGRAM_NAME is not running."
	fi
;; 
*)                                                                                               
echo "Usage: /etc/init.d/isecmanager {start|stop|restart|force-reload|status}"
exit 1             
esac                                                                                                                                                                                                                                                                                                                                      
exit 0 


