summaryrefslogtreecommitdiff
path: root/start-cisco678polld.sh
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xstart-cisco678polld.sh117
1 files changed, 117 insertions, 0 deletions
diff --git a/start-cisco678polld.sh b/start-cisco678polld.sh
new file mode 100755
index 0000000..fb82ef0
--- /dev/null
+++ b/start-cisco678polld.sh
@@ -0,0 +1,117 @@
+#!/bin/sh
+
+### check to see if cisco678polld.sh is running, start if needed
+
+#clear
+#reset
+
+### execution tracing ON
+#set -x
+
+DAEMON=cisco678polld.sh
+DPATH=~/mon_rrd
+DLOCK=/var/tmp/${DAEMON}.lock
+
+
+### check lock file
+cklock() {
+ if [ -f ${1} ] ; then
+ if [ -r ${1} ] ; then
+ DPID=$( cat ${1} )
+ else
+ echo lock is not readable
+ fi
+ else
+ echo lock does not exist
+ fi
+}
+
+
+### check lock pid
+cklockpid() {
+ if [ ${1} ] ; then
+ CKPID=$( ps ax |\
+ grep ${1} |\
+ grep -v 'grep' |\
+ awk '{print $1}' )
+ if [ ${CKPID} ] && [ ${1} -eq ${CKPID} ] ; then
+ echo proc is running, lock is valid
+ fi
+ else
+ echo lock pid does not exist
+ fi
+}
+
+
+### check for running procs by name
+ckprox() {
+ PSPIDZ=$( ps ax |\
+ grep ${DAEMON} |\
+ grep -v 'grep' |\
+ awk '{print $1}' )
+}
+
+
+start_daemon() {
+ ( ${DPATH}/${DAEMON} ) &
+ cklock ${DLOCK}
+ cklockpid ${DPID}
+}
+
+
+stop_daemon(){
+ ### remove lock, script should exit on its own
+ cklock ${DLOCK}
+ cklockpid ${DPID}
+ if [ -f ${DLOCK} ] ; then
+ rm -fv ${DLOCK}
+ fi
+}
+
+
+terminate_daemon() {
+ cklock ${DLOCK}
+ cklockpid ${DPID}
+ kill -9 ${DPID}
+}
+
+
+exterminate_daemons() {
+ ### EXTERMINATE!
+ ckprox ${DAEMON}
+ for PID in PSPIDZ ; do
+ kill -9 ${PID}
+ done
+}
+
+
+case "${1}" in
+ 'start')
+ start_daemon
+ ;;
+ 'stop')
+ stop_daemon
+ terminate_daemon
+ ;;
+ 'terminate')
+ stop_daemon
+ terminate_daemon
+ ;;
+ 'exterminate')
+ stop_daemon
+ terminate_daemon
+ exterminate_daemons
+ ;;
+ 'restart')
+ stop_daemon
+ terminate_daemon
+ start_daemon
+ ;;
+ *)
+ echo "Usage: $0 {start|stop|terminate|exterminate|restart}"
+ ;;
+esac
+
+### execution tracing OFF
+set +x
+