Skip to content

Instantly share code, notes, and snippets.

@tongueroo
Last active Jul 20, 2017
Embed
What would you like to do?
# cat eb-docker.conf
description "Elastic Beanstalk Default Docker Container"
author "Elastic Beanstalk"
start on started docker
stop on stopping docker
respawn
script
# Wait for docker to finish starting up first.
FILE=/var/run/docker.sock
while [ ! -e $FILE ]; do
sleep 2
done
EB_CONFIG_DOCKER_CURRENT_APP=`cat /etc/elasticbeanstalk/.aws_beanstalk.current-container-id | cut -c 1-12`
if ! docker ps | grep $EB_CONFIG_DOCKER_CURRENT_APP; then
docker start $EB_CONFIG_DOCKER_CURRENT_APP
fi
EB_CONFIG_DOCKER_PORT_FILE=`/opt/elasticbeanstalk/bin/get-config container -k port_file`
EB_CONFIG_NGINX_UPSTREAM_IP=`docker inspect $EB_CONFIG_DOCKER_CURRENT_APP | jq -r .[0].NetworkSettings.IPAddress`
EB_CONFIG_NGINX_UPSTREAM_PORT=`cat $EB_CONFIG_DOCKER_PORT_FILE`
if ! cat /etc/nginx/conf.d/elasticbeanstalk-nginx-docker-upstream.conf | grep -q $EB_CONFIG_NGINX_UPSTREAM_IP; then
sed -i "s/server.*;/server $EB_CONFIG_NGINX_UPSTREAM_IP:$EB_CONFIG_NGINX_UPSTREAM_PORT;/" /etc/nginx/conf.d/elasticbeanstalk-nginx-docker-upstream.conf
service nginx restart
fi
docker logs -f $EB_CONFIG_DOCKER_CURRENT_APP >> /var/log/eb-docker/containers/eb-current-app/$EB_CONFIG_DOCKER_CURRENT_APP-stdouterr.log 2>&1
exec docker wait $EB_CONFIG_DOCKER_CURRENT_APP
end script
post-stop script
EB_CONFIG_DOCKER_CURRENT_APP=`cat /etc/elasticbeanstalk/.aws_beanstalk.current-container-id | cut -c 1-12`
if docker ps | grep $EB_CONFIG_DOCKER_CURRENT_APP; then
docker stop $EB_CONFIG_DOCKER_CURRENT_APP
fi
end script
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment