k-space-infra-automation/ansible/kanban/templates/systemd_docker-compose_service.j2

26 lines
725 B
Plaintext
Raw Permalink Normal View History

2019-11-07 22:46:58 +00:00
[Unit]
Description=%i service with docker compose managed by Ansible
Requires=docker.service
After=docker.service
[Service]
Restart=always
WorkingDirectory=/opt/%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