-
Notifications
You must be signed in to change notification settings - Fork 2
/
start-nginx-solo
executable file
·48 lines (41 loc) · 1.15 KB
/
start-nginx-solo
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
#!/usr/bin/env bash
psmgr=/tmp/nginx-buildpack-wait
rm -f $psmgr
mkfifo $psmgr
# Evaluate config to get $PORT
erb config/nginx.conf.erb > config/nginx.conf
n=1
while getopts :f option ${@:1:2}
do
case "${option}"
in
f) FORCE=$OPTIND; n=$((n+1));;
esac
done
# Initialize log directory.
mkdir -p logs/nginx
touch logs/nginx/access.log logs/nginx/error.log
echo 'buildpack=nginx at=logs-initialized'
# Start log redirection.
(
# Redirect nginx logs to stdout.
tail -qF -n 0 logs/nginx/*.log
echo 'logs' >$psmgr
) &
# Start nginx
(
#We expect nginx to run in foreground.
#We also expect a socket to be at /tmp/nginx.socket.
echo 'buildpack=nginx at=nginx-start'
bin/nginx -p . -c config/nginx.conf
echo 'nginx' >$psmgr
) &
# This read will block the process waiting on a msg to be put into the fifo.
# If any of the processes defined above should exit,
# a msg will be put into the fifo causing the read operation
# to un-block. The process putting the msg into the fifo
# will use it's process name as a msg so that we can print the offending
# process to stdout.
read exit_process <$psmgr
echo "buildpack=nginx at=exit process=$exit_process"
exit 1