-
Notifications
You must be signed in to change notification settings - Fork 1
/
monitor_mambasrv.sh
executable file
·57 lines (48 loc) · 1.4 KB
/
monitor_mambasrv.sh
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
#!/bin/bash
## Look for duplicated deadman files for the same port/web service:
## remove them and kill their processes
cd /tmp/
for deadman in `ls deadman* | sort | uniq --check-chars=13 -c | grep -v '1 ' | awk '{print $2}' `
do
# echo $deadman # only keep this copy
find -type f -name "${deadman::13}*" ! -name $deadman -exec bash -c ' kill `echo {} | cut -d. -f4` ; rm {} ' \; 2>/dev/null
done
# change to correct directory
cd /data/string_v11/mamba
# check for deadman files
for f in /tmp/*
do
filename=$(echo $f | cut -d'.' -f1)
if [[ $filename == "/tmp/deadman" ]]
then
my_port=$(echo $f | cut -d'.' -f2)
#echo "check for port "$my_port
my_pid=$(echo $f | cut -d'.' -f3)
#echo "found deadman file for "$my_pid
uname=$(stat -c '%U' $f)
#echo "deadman file created by "$uname
found_process=$(ps aux | grep $my_pid | grep -v grep)
#echo $found_process
if [[ $found_process == "" ]]
then
#echo "Server not running. Start server."
start_command=`cat $f`
rm $f
#eval "$start_command" &
eval "sudo -u $uname $start_command &"
else
status=$(curl -s -w '%{http_code}' -o /dev/null --connect-timeout 5 --max-time 10 http://localhost:$my_port/GetStatus)
if [[ ! $status == "200" ]]
then
#echo "Server restart needed."
start_command=`cat $f`
kill -9 $my_pid
rm $f
eval "sudo -u $uname $start_command &"
#eval "$start_command" &
#else
#echo "All fine."
fi
fi
fi
done