-
-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathbootstrap
executable file
·65 lines (53 loc) · 1.77 KB
/
bootstrap
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
#!/usr/bin/env bash
# Execute by: bash xxx.sh or bash zzz/yyy/xxx.sh or ./xxx.sh or ./zzz/yyy/xxx.sh source xxx.sh
REALPATH=$(realpath ${BASH_SOURCE[0]})
SCRIPT_DIR=$(cd $(dirname ${REALPATH}) && pwd)
WORK_DIR=$(cd $(dirname ${REALPATH}) && pwd)
echo "BASH_SOURCE=${BASH_SOURCE}, REALPATH=${REALPATH}, SCRIPT_DIR=${SCRIPT_DIR}, WORK_DIR=${WORK_DIR}"
cd ${WORK_DIR}
APP_ARGS=$@
echo "Run srs-stack with args: ${APP_ARGS}, WORK_DIR:${WORK_DIR}"
# Start redis.
bash auto/start_redis
if [[ $? -ne 0 ]]; then echo "Start redis failed"; exit 1; fi
# Start SRS.
bash auto/start_srs
if [[ $? -ne 0 ]]; then echo "Start SRS failed"; exit 1; fi
# Start the platform.
./platform $APP_ARGS &
if [[ $? -ne 0 ]]; then echo "Start platform failed"; exit 1; fi
stop_services() {
# Quickly save data before stopping, as the process termination may
# potentially result in a timeout.
bash auto/before_stop
if [[ $(ps aux |grep platform |grep -v grep |grep -v usr |grep -q platform && echo yes) == yes ]]; then
kill -s SIGTERM $(pidof platform)
fi
bash auto/stop_redis
bash auto/stop_srs
}
handle_signals() {
echo "Signal $1 received. Cleaning up and exiting..."
stop_services
exit 0
}
trap 'handle_signals SIGTERM' SIGTERM
trap 'handle_signals SIGINT' SIGINT
while true; do
sleep 3
if [[ $(ps aux |grep redis |grep -q server || echo no) == no ]]; then
echo "Redis server stopped, exit."
break
fi
if [[ $(ps aux |grep srs |grep -q conf || echo no) == no ]]; then
echo "SRS server stopped, exit."
break
fi
if [[ $(ps aux |grep platform |grep -v grep |grep -v usr |grep -q platform || echo no) == no ]]; then
echo "Platform stopped, exit."
break
fi
done
# Quit by itself.
stop_services
exit 1