Add generic docker-compose systemd service
This commit is contained in:
parent
c0be314268
commit
dc520a09e9
3
roles/docker/defaults/main.yml
Normal file
3
roles/docker/defaults/main.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
docker_root: /var/lib/docker-compose
|
||||||
|
docker_compose: /usr/bin/docker-compose
|
||||||
|
docker_compose_service: compose
|
@ -4,6 +4,22 @@
|
|||||||
state: present
|
state: present
|
||||||
update_cache: true
|
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
|
- name: Add users to docker group
|
||||||
user:
|
user:
|
||||||
name: "{{ item }}"
|
name: "{{ item }}"
|
||||||
|
14
roles/docker/templates/docker-compose.service.j2
Normal file
14
roles/docker/templates/docker-compose.service.j2
Normal 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
|
Loading…
Reference in New Issue
Block a user