-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·53 lines (44 loc) · 1.04 KB
/
start.sh
File metadata and controls
executable file
·53 lines (44 loc) · 1.04 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
48
49
50
51
52
53
#!/bin/bash
#set -ex
# this script for heroku docker
# when supervisor stops a container it sends SIGTERM all processes, not only root process.
# when argument exists run it.
if [ "$*" != "" -a "$*" != "./start.sh" ]; then
"$@"
exit
fi
# starting daemon...
for s in apps/*/setup.sh; do
if [ -x $s ]; then
(cd $(dirname $s) && ./setup.sh)
fi
done
_term() {
echo "caught SIGTERM in start.sh"
}
trap _term SIGTERM
_exit() {
echo "on exit"
}
trap _exit EXIT
node index.js -p $PORT -a &
child=$!
while :
do
# SIGTERMを送った瞬間にwaitから$?=143(=128+15)で帰ってきてしまうが
# その時点はプロセスは終了しておらず
# 再度waitする必要がある
# 調べたけれど、なんでこうなるのかは不明
echo "waiting $child..."
wait $child
code=$?
echo "wait returned by code=$code"
if [ $code -eq 143 ]; then
echo "but should ignore."
else
echo "node terminated by code=$code"
break
fi
done
echo "exiting..."
exit 0