forked from Rock-Candy-Tea/hexo-circle-of-friends
-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker.sh
35 lines (35 loc) · 1.01 KB
/
docker.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
#!/bin/bash
# Start the first process
nohup python3 -u ./hexo_circle_of_friends/run.py > /tmp/crawler.log 2>&1 &
ps aux |grep run |grep -q -v grep
PROCESS_1_STATUS=$?
echo "run.py status..."
echo $PROCESS_1_STATUS
if [ $PROCESS_1_STATUS -ne 0 ]; then
echo "Failed to start run.py: $PROCESS_2_STATUS"
exit $PROCESS_1_STATUS
fi
sleep 5
# Start the second process
nohup python3 -u ./api/main.py > /tmp/api.log 2>&1 &
ps aux |grep main |grep -q -v grep
PROCESS_2_STATUS=$?
echo "main.py status..."
echo $PROCESS_2_STATUS
if [ $PROCESS_2_STATUS -ne 0 ]; then
echo "Failed to start main.py: $PROCESS_2_STATUS"
exit $PROCESS_2_STATUS
fi
# 每隔60秒检查进程是否运行
while sleep 60; do
ps aux |grep run |grep -q -v grep
PROCESS_1_STATUS=$?
ps aux |grep main |grep -q -v grep
PROCESS_2_STATUS=$?
# If the greps above find anything, they exit with 0 status
# If they are not both 0, then something is wrong
if [ $PROCESS_1_STATUS -ne 0 -o $PROCESS_2_STATUS -ne 0 ]; then
echo "One of the processes has already exited."
exit 1
fi
done