Skip to content

Instantly share code, notes, and snippets.

@mwt
Forked from r0l1/README.md
Last active May 3, 2023 00:36
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 mwt/241866323cdcda42a870c7add0068b0c to your computer and use it in GitHub Desktop.
Save mwt/241866323cdcda42a870c7add0068b0c to your computer and use it in GitHub Desktop.
Running docker-compose as a systemd service

Running snikket as a systemd service

Files

File Purpose
/etc/snikket/docker-compose.yml Compose file describing what to deploy
/etc/systemd/system/snikket.service Service unit to start and manage docker compose
/etc/systemd/system/snikket-reload.service Executing unit to trigger reload on docker-compose.service
/etc/systemd/system/snikket-reload.timer Timer unit to plan the reloads

Installation

Put the above mentioned files in the corresponding places and let systemd load them:

# systemctl daemon-reload
# systemctl enable snikket snikket-reload
# systemctl start snikket snikket-reload
[Unit]
Description=Refresh images and update containers
[Service]
Type=oneshot
ExecStart=/bin/systemctl reload snikket.service
[Unit]
Description=Refresh images and update containers
Requires=snikket.service
After=snikket.service
[Timer]
OnCalendar=daily
[Install]
WantedBy=timers.target
[Unit]
Description=Docker Compose container starter
After=docker.service network-online.target
Requires=docker.service network-online.target
[Service]
WorkingDirectory=/etc/snikket
Type=oneshot
RemainAfterExit=yes
ExecStartPre=/usr/bin/docker-compose pull --quiet --parallel
ExecStart=/usr/bin/docker-compose up -d
ExecStop=/usr/bin/docker-compose down
ExecReload=/usr/bin/docker-compose pull --quiet --parallel
ExecReload=/usr/bin/docker-compose up -d
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment