Skip to content

Commit

Permalink
Adding start-nginx-solo
Browse files Browse the repository at this point in the history
  • Loading branch information
darbyfrey committed Aug 21, 2015
1 parent bfacddd commit f14698e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ nginx_version=$(./bin/nginx-$STACK -V 2>&1 | head -1 | awk '{ print $NF }')
echo "-----> nginx-buildpack: Installed ${nginx_version} to app/bin"
cp bin/start-nginx "$1/bin/"
echo '-----> nginx-buildpack: Added start-nginx to app/bin'
cp bin/start-nginx-solo "$1/bin/"
echo '-----> nginx-buildpack: Added start-nginx-solo to app/bin'
cp scripts/build_nginx.sh "$1/scripts/"
echo '-----> nginx-buildpack: Added build_nginx.sh to app/scripts'

Expand Down
52 changes: 52 additions & 0 deletions bin/start-nginx-solo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/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

#Evaluate to write port file
erb config/port_config.erb > config/port_config

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

0 comments on commit f14698e

Please sign in to comment.