Skip to content

Instantly share code, notes, and snippets.

@megrxu
Last active July 21, 2020 12:24
Show Gist options
  • Save megrxu/2db361d63ee25efb70bdf98025eda718 to your computer and use it in GitHub Desktop.
Save megrxu/2db361d63ee25efb70bdf98025eda718 to your computer and use it in GitHub Desktop.
Systemd Services
[Unit]
Description=%i service with docker compose
Requires=docker.service
After=docker.service
[Service]
Restart=always
WorkingDirectory=/etc/docker/compose/%i
# Remove old containers, images and volumes
ExecStartPre=/usr/bin/docker-compose down -v
ExecStartPre=/usr/bin/docker-compose rm -fv
ExecStartPre=-/bin/bash -c 'docker volume ls -qf "name=%i_" | xargs docker volume rm'
ExecStartPre=-/bin/bash -c 'docker network ls -qf "name=%i_" | xargs docker network rm'
ExecStartPre=-/bin/bash -c 'docker ps -aqf "name=%i_*" | xargs docker rm'
# Compose up
ExecStart=/usr/bin/docker-compose up
# Compose down, remove containers and volumes
ExecStop=/usr/bin/docker-compose down -v
[Install]
WantedBy=multi-user.target
[Unit]
Description=Fava
After=network.target
[Service]
User=fava
Type=simple
RemainAfterExit=true
WorkingDirectory=/usr/share/webapps/bean
ExecStart=/usr/bin/pipenv run fava book.bean -p 5000
StandardOutput=journal
[Install]
WantedBy=multi-user.target
[Unit]
Description=ZJUNet auto connect
After=network-online.target
[Service]
User=root
Type=oneshot
RemainAfterExit=true
ExecStart=/usr/local/bin/zjunet vpn -c
ExecStop=/usr/local/bin/zjunet vpn -d
StandardOutput=journal
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment