Last active
August 29, 2015 14:21
-
-
Save shreeve/d758b38ef9cad88fd266 to your computer and use it in GitHub Desktop.
docker start script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
watch=/tmp/watch | |
ready=/tmp/ready | |
rm -f $watch $ready | |
mkfifo $watch | |
# reap all on exit | |
trap "exit" INT TERM | |
trap "kill 0" EXIT | |
# spawn app | |
( | |
echo "buildpack=nginx at=start-app cmd='$@'" | |
cd api && $@ | |
echo "app" > $watch | |
) & | |
# await app | |
for ((tries=10; tries>0; tries--)); do | |
sleep 1 | |
echo "buildpack=nginx at=app-initialization" | |
[ -f "$ready" ] && break | |
done | |
# report status | |
if [ $tries -eq 0 ]; then | |
echo "buildpack=nginx at=app-failed-init" | |
exit 1 | |
else | |
echo "buildpack=nginx at=app-initialized" | |
fi | |
# spawn logger | |
( | |
mkdir -p nginx/logs | |
touch nginx/logs/{access,error}.log | |
echo "buildpack=nginx at=logs-initialized" | |
tail -qF -n 0 nginx/logs/*.log | |
echo "logger" > $watch | |
) & | |
# spawn nginx (we expect a socket at /tmp/nginx.socket) | |
( | |
erb nginx/nginx.conf.erb > nginx/nginx.conf | |
echo "buildpack=nginx at=nginx-start" | |
nginx/nginx -p nginx -c nginx.conf | |
echo "nginx" > $watch | |
) & | |
# watch for termination | |
read blame < $watch | |
echo "buildpack=nginx at=exit process=$blame" | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment