Skip to content

Instantly share code, notes, and snippets.

@siers
Forked from samalba/etc-init.d-docker-compose
Last active April 7, 2017 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siers/5441b9c3140c91d653d5283c662d79f9 to your computer and use it in GitHub Desktop.
Save siers/5441b9c3140c91d653d5283c662d79f9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
### BEGIN INIT INFO
# Provides: dockercompose
# Required-Start: $docker
# Required-Stop: $docker
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Docker Services
### END INIT INFO
set -eu
export WEB_PORT="8080" # for docker compose in case of multiple roots
PROJECT_NAME='project'
MAIN_YAML='/project/root/docker-compose.yml'
OVERRIDE_YAML='/project/root/docker-compose.server.yml'
OPTS=(-p "$PROJECT_NAME" -f "$MAIN_YAML")
UPOPTS=(-d --build)
if [ -e "$OVERRIDE_YAML" ]; then
OPTS=("${OPTS[@]}" -f "$OVERRIDE_YAML")
fi
. /lib/lsb/init-functions
case "$1" in
restart)
docker-compose "${OPTS[@]}" stop
restart=1
;&
stop)
log_daemon_msg "Stopping Docker Compose" "dockercompose" || true
docker-compose "${OPTS[@]}" stop
[ -n "${restart:-}" ] || exit 0
;&
reload)
;&
start)
log_daemon_msg "Starting Docker Compose" "dockercompose" || true
docker-compose "${OPTS[@]}" up "${UPOPTS[@]}"
;;
*)
log_action_msg "Usage: /etc/init.d/dockercompose {start|stop|restart|reload}" || true
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment