Add generic docker-compose systemd service

This commit is contained in:
Kris Lamoureux 2022-05-26 23:50:14 -04:00
parent c0be314268
commit dc520a09e9
Signed by: kris
GPG Key ID: 3EDA9C3441EDA925
3 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,3 @@
docker_root: /var/lib/docker-compose
docker_compose: /usr/bin/docker-compose
docker_compose_service: compose

View File

@ -4,6 +4,22 @@
state: present
update_cache: true
- name: Create docker-compose root
file:
path: "{{ docker_root }}"
state: directory
- name: Install docker-compose systemd service
template:
src: docker-compose.service.j2
dest: "/etc/systemd/system/{{ docker_compose_service }}@.service"
register: compose_systemd
- name: Reload systemd manager configuration
systemd:
daemon_reload: true
when: compose_systemd.changed
- name: Add users to docker group
user:
name: "{{ item }}"

View File

@ -0,0 +1,14 @@
[Unit]
Description=%i docker-compose service
PartOf=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=true
WorkingDirectory={{ docker_root }}/%i
ExecStart={{ docker_compose }} up -d --remove-orphans
ExecStop={{ docker_compose }} down
[Install]
WantedBy=multi-user.target