-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice-check-active-calls-restart-cis-agi
116 lines (90 loc) · 3.13 KB
/
service-check-active-calls-restart-cis-agi
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
#!/bin/bash
#
# check-cis-agi This shell script takes care of starting and stopping check-cis-agi
#
# chkconfig: - 80 20
#
### BEGIN INIT INFO
# Provides: Nguyen Ngoc Tai
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start:
# Default-Stop:
# Description: Release implementation for Servlet 2.5 and JSP 2.1
# Short-Description: start and stop check-cis-agi
### END INIT INFO
## Source function library.
#. /etc/rc.d/init.d/functions
RED='\033[0;31m'
NC='\033[0m'
GREEN='\033[0;32m'
CURRENT_DIR="/var/lib/check-active-calls-restart-cis-agi"
function check_check_call(){
ps -ef | grep check-active-calls-restart-cis-agi | grep -v "grep" | grep -v "service-check-active-calls-restart-cis-agi" | awk '{print $2}' | wc -l
}
function get_process_pid_check_call(){
ps -ef | grep check-active-calls-restart-cis-agi | grep -v "grep" | grep -v "service-check-active-calls-restart-cis-agi" | awk '{print $2}' | awk '{ORS=(NR%3?FS:RS)}1'
}
function kill_process_pid_check_call(){
value_test=`ps -ef | grep check-active-calls-restart-cis-agi | grep -v "grep" | grep -v "service-check-active-calls-restart-cis-agi" | awk '{print $2}' | awk '{ORS=(NR%3?FS:RS)}1'`
list_pid=(${value_test[@]})
for i in "${!list_pid[@]}";
do
if [ "${list_pid[$i]}" -gt "0" ]
then
kill -9 ${list_pid[$i]}
fi
done
}
function start_check_call(){
if [ `check_check_call` -eq 0 ]
then
echo -e "${RED}Service check active call is not running....................${NC}"
"$CURRENT_DIR"/check-active-calls-restart-cis-agi.sh
echo -e "${RED}Starting service check active call: [${NC} ${GREEN}OK${NC} ${RED}]${NC}"
else
echo -e "${RED}Service check call is running....................${NC}"
echo -e "${RED}Starting service check active call: [${NC} ${GREEN}OK${NC} ${RED}]${NC}"
fi
}
function stop_check_call(){
if [ `check_check_call` -eq 0 ];
then
echo -e "${RED}Stopping service check active call: [${NC} ${GREEN}OK${NC} ${RED}]${NC}"
else
sleep 2
echo -e "${RED}Stopping service check active call: waiting for processes${NC} ${GREEN}`get_process_pid_check_call`${NC} ${RED}to exit [${NC} ${GREEN}OK${NC} ${RED}]${NC}"
kill_process_pid_check_call
fi
}
function restart_check_call(){
stop_check_call
sleep 2
start_check_call
}
function status_check_call(){
if [ `check_check_call` -eq 0 ];
then
echo -e "${RED}Service check active call is stopped [${NC} ${GREEN}OK${NC} ${RED}]${NC}"
else
echo -e "${RED}Sercive check active call ${NC}${GREEN}pid `get_process_pid_check_call`${NC}${RED} is running... [${NC} ${GREEN}OK${NC} ${RED}]${NC}"
fi
}
case "$1" in
start)
start_check_call
;;
stop)
stop_check_call
;;
restart)
restart_check_call
;;
status)
status_check_call
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0