Skip to content

Commit 68c4d20

Browse files
committed
🎨补充服务检查脚本
1 parent 1fd7f79 commit 68c4d20

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
function get_target_process(){
4+
proc_name=$1
5+
pids=`ps -ef | grep "$proc_name" | grep -v grep | awk '{print $2}'`
6+
echo $pids
7+
}
8+
9+
function check_target_process_exist() {
10+
proc_name=$1
11+
pids=$( get_target_process "$proc_name" )
12+
ret=""
13+
if [ ! -n "$pids" ]; then
14+
ret="false"
15+
else
16+
ret="true"
17+
fi
18+
echo "$ret"
19+
}
20+
21+
function ping_celery() {
22+
celery -A codedog inspect ping -d celery@$HOSTNAME 2>&1 >/dev/null
23+
echo $?
24+
}
25+
26+
function check_celery_healthy() {
27+
result=0
28+
for((i=1;i<=3;i++)); do
29+
result=`ping_celery`
30+
echo "check celery result: $result"
31+
if [ "$result" == "0" ]; then
32+
break
33+
fi
34+
sleep 10
35+
done
36+
37+
if [ "$result" != "0" ]; then
38+
pids=`get_target_process 'celery -A codedog'`
39+
kill -HUP $pids
40+
fi
41+
}
42+
43+
check_celery_healthy
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
function get_target_process(){
4+
proc_name=$1
5+
pids=`ps -ef | grep "$proc_name" | grep -v grep | awk '{print $2}'`
6+
echo $pids
7+
}
8+
9+
function check_target_process_exist() {
10+
proc_name=$1
11+
pids=$( get_target_process "$proc_name" )
12+
ret=""
13+
if [ ! -n "$pids" ]; then
14+
ret="false"
15+
else
16+
ret="true"
17+
fi
18+
echo "$ret"
19+
}
20+
21+
function ping_celery() {
22+
celery -A codedog inspect ping -d celery@$HOSTNAME 2>&1 >/dev/null
23+
echo $?
24+
}
25+
26+
function check_celery_healthy() {
27+
result=0
28+
for((i=1;i<=3;i++)); do
29+
result=`ping_celery`
30+
echo "check celery result: $result"
31+
if [ "$result" == "0" ]; then
32+
break
33+
fi
34+
sleep 10
35+
done
36+
37+
if [ "$result" != "0" ]; then
38+
pids=`get_target_process 'celery -A codedog'`
39+
kill -HUP $pids
40+
fi
41+
}
42+
43+
check_celery_healthy

0 commit comments

Comments
 (0)