-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshadow_monitor.sh
More file actions
47 lines (39 loc) · 1.07 KB
/
shadow_monitor.sh
File metadata and controls
47 lines (39 loc) · 1.07 KB
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
#!/bin/sh
#############################################################
# monitor server running #
# restart server if detect it is not running #
# monitor.sh must be in the same directory with the server #
#############################################################
shell_dir=$(dirname $0)
shell_dir=${shell_dir/\./$(pwd)}
log_dir=/data/logs/shadow/
run_dir=/var/run/shadow/
function monitor_pid() {
mkdir -p $log_dir
mkdir -p $run_dir
cd $shell_dir
pid=`cat /var/run/shadow/agent.pid`
process_count=`ps aux| grep $1 | grep ' '$pid' ' | grep -v shadow_monitor.sh | grep -v grep| wc -l`
if [ $process_count == 0 ]; then
date >> $log_dir/restart.log
echo "server stopped, process_cnt=$process_count" >> $log_dir/restart.log
./daemon_handle ./$1 -cnf_basedir=/var/workspace-go/src/shadow/agent/cnf/
fi
}
function monitor() {
cd $shell_dir
while true
do
monitor_pid $1
sleep 5
done
}
case $1 in
agent)
monitor $1
;;
*)
echo "Usage: "
echo " ./shadow_monitor.sh (agent)"
;;
esac