diff --git a/roles/containers/defaults/main.yml b/roles/containers/defaults/main.yml index cd69172..b3ace9d 100644 --- a/roles/containers/defaults/main.yml +++ b/roles/containers/defaults/main.yml @@ -3,4 +3,4 @@ # these are defaults # change these in group/host vars -docker_compose_dir: "/home/{{ ansible_user }}/services" +docker_compose_dir: "/opts/services" diff --git a/roles/containers/tasks/main.yml b/roles/containers/tasks/main.yml index 86c6f7b..92ae258 100644 --- a/roles/containers/tasks/main.yml +++ b/roles/containers/tasks/main.yml @@ -15,9 +15,16 @@ - name: Generate docker-compose.yml template: - src: "docker-compose.yml" + src: "docker-compose.yml.j2" dest: "{{ docker_compose_dir }}/docker-compose.yml" -- name: Docker compose up - community.docker.docker_compose: - project_src: "{{ docker_compose_dir }}" +- name: Create systemd unit file + template: + src: "docker-compose.service.j2" + dest: "/etc/systemd/system/docker-compose.service" + +- name: Compose up + systemd: + name: docker-compose + state: started + enabled: true diff --git a/roles/containers/templates/docker-compose.service.j2 b/roles/containers/templates/docker-compose.service.j2 new file mode 100644 index 0000000..659edfb --- /dev/null +++ b/roles/containers/templates/docker-compose.service.j2 @@ -0,0 +1,15 @@ +[Unit] +Description=Services manager with docker-compose +Requires=docker.service +After=docker.service + +[Service] +WorkingDirectory={{ docker_compose_dir }} +ExecStartPre=-/usr/bin/docker compose pull +ExecStart=/usr/bin/docker compose up --remove-orphans +ExecStop=/usr/bin/docker compose down +ExecReload=/usr/bin/docker compose pull +ExecReload=/usr/bin/docker compose up --remove-orphans + +[Install] +WantedBy=multi-user.target diff --git a/roles/containers/templates/docker-compose.yml.j2 b/roles/containers/templates/docker-compose.yml.j2 index 3857280..126ab8a 100644 --- a/roles/containers/templates/docker-compose.yml.j2 +++ b/roles/containers/templates/docker-compose.yml.j2 @@ -19,7 +19,6 @@ services: - gitea volumes: - {{ dataroot }}/gitea:/data - - {{ }} - /etc/timezone:/etc/timezone:ro - /etc/localtime:/etc/localtime:ro ports: