-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·50 lines (42 loc) · 1.06 KB
/
entrypoint.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
#!/bin/sh
child=1
exit_code=0
TERM_SIGNAL=${TERM_SIGNAL:-"QUIT"}
_watch_files() {
if [ -z "${WATCH_FILES}" ]; then
return
fi
inotifywait \
-e modify \
-m \
${WATCH_FILES} \
| while read path action file; do
echo "Sending $RELOAD_SIGNAL to $child as file $file has $action."
if nginx -t; then
echo "New configuration is valid, reloading nginx"
nginx -s reload
else
echo "Detected configuration is invalid. Refusing to reload."
fi
done
}
_handle_term() {
echo "Caught SIGTERM, sending $TERM_SIGNAL to pid $child"
kill -"$TERM_SIGNAL" "$child" 2>/dev/null
}
trap _handle_term SIGTERM
trap _handle_term SIGINT
wrap() {
echo "Starting child process..."
echo "Executing: $@ &"
$@ &
child=$!
_watch_files &
echo "Child process started with pid $child"
wait $child
wait $child
exit_code=$?
echo "Child process $child exited with status $exit_code"
}
wrap nginx $@
exit $exit_code