blob: fb82ef0199b0023ae6dc01dab3aded9909742d81 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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
|