From 51922d8b4471a7d35eca1d0bab627f2e4f585328 Mon Sep 17 00:00:00 2001 From: Someone Date: Fri, 4 Oct 2024 13:42:40 +0200 Subject: [PATCH] [roles/server/docker-compose/dco-service] docker-compose service --- .../dco-service/defaults/main.yml | 14 +++ .../svc-default/config/docker-compose.yml | 13 ++ .../svc-default/config/pre-exec-sourced.sh | 20 +++ .../dco-service/handlers/main.yml | 13 ++ .../docker-compose/dco-service/meta/main.yml | 9 ++ .../docker-compose/dco-service/tasks/main.yml | 117 ++++++++++++++++++ .../templates/default/docker-compose.timer.j2 | 19 +++ 7 files changed, 205 insertions(+) create mode 100644 roles/server/docker-compose/dco-service/defaults/main.yml create mode 100644 roles/server/docker-compose/dco-service/files/default/svc-default/config/docker-compose.yml create mode 100644 roles/server/docker-compose/dco-service/files/default/svc-default/config/pre-exec-sourced.sh create mode 100644 roles/server/docker-compose/dco-service/handlers/main.yml create mode 100644 roles/server/docker-compose/dco-service/meta/main.yml create mode 100644 roles/server/docker-compose/dco-service/tasks/main.yml create mode 100644 roles/server/docker-compose/dco-service/templates/default/docker-compose.timer.j2 diff --git a/roles/server/docker-compose/dco-service/defaults/main.yml b/roles/server/docker-compose/dco-service/defaults/main.yml new file mode 100644 index 0000000..6369a21 --- /dev/null +++ b/roles/server/docker-compose/dco-service/defaults/main.yml @@ -0,0 +1,14 @@ +##################################### +### someone's ansible provisioner ### +##################################### +# Part of: https://git.somenet.org/root/pub/somesible.git +# 2017-2024 by someone +# +# If not overridden in inventory or as a parameter, this is the value that will be used +# +--- +dco_svc_name: "default" + +# if set: dont enable and start service, but create timer service +dco_svc_cron: "" +# *-*-* 08:05:40 diff --git a/roles/server/docker-compose/dco-service/files/default/svc-default/config/docker-compose.yml b/roles/server/docker-compose/dco-service/files/default/svc-default/config/docker-compose.yml new file mode 100644 index 0000000..beb114a --- /dev/null +++ b/roles/server/docker-compose/dco-service/files/default/svc-default/config/docker-compose.yml @@ -0,0 +1,13 @@ +# +################################################ +### Managed by someone's ansible provisioner ### +################################################ +# Part of: https://git.somenet.org/root/pub/somesible.git +# 2017-2024 by someone +# + +version: '2' +services: + default: + image: gliderlabs/alpine + command: "echo default noop." diff --git a/roles/server/docker-compose/dco-service/files/default/svc-default/config/pre-exec-sourced.sh b/roles/server/docker-compose/dco-service/files/default/svc-default/config/pre-exec-sourced.sh new file mode 100644 index 0000000..78dec93 --- /dev/null +++ b/roles/server/docker-compose/dco-service/files/default/svc-default/config/pre-exec-sourced.sh @@ -0,0 +1,20 @@ +#!/bin/bash +################################################ +### Managed by someone's ansible provisioner ### +################################################ +# Part of: https://git.somenet.org/root/pub/somesible.git +# 2017-2024 by someone +# +# Override to change from noop. +# + + +#cat > .env <<-\#HEADER-EOF +# +############################################################################ +### Generated from pre-exec-sourced.sh by docker-compose@default.service ### +############################################################################ +# +#HEADER-EOF + +# cat env.dist >> .env diff --git a/roles/server/docker-compose/dco-service/handlers/main.yml b/roles/server/docker-compose/dco-service/handlers/main.yml new file mode 100644 index 0000000..8061a71 --- /dev/null +++ b/roles/server/docker-compose/dco-service/handlers/main.yml @@ -0,0 +1,13 @@ +##################################### +### someone's ansible provisioner ### +##################################### +# Part of: https://git.somenet.org/root/pub/somesible.git +# 2017-2024 by someone +# +--- +- name: restart docker-compose@{{dco_svc_name}}.service + systemd: + name: docker-compose@{{dco_svc_name}}.service + daemon_reload: yes + state: restarted + ignore_errors: yes diff --git a/roles/server/docker-compose/dco-service/meta/main.yml b/roles/server/docker-compose/dco-service/meta/main.yml new file mode 100644 index 0000000..5f0fba9 --- /dev/null +++ b/roles/server/docker-compose/dco-service/meta/main.yml @@ -0,0 +1,9 @@ +##################################### +### someone's ansible provisioner ### +##################################### +# Part of: https://git.somenet.org/root/pub/somesible.git +# 2017-2024 by someone +# +--- +dependencies: + - { role: server/docker-compose } diff --git a/roles/server/docker-compose/dco-service/tasks/main.yml b/roles/server/docker-compose/dco-service/tasks/main.yml new file mode 100644 index 0000000..07b9fbf --- /dev/null +++ b/roles/server/docker-compose/dco-service/tasks/main.yml @@ -0,0 +1,117 @@ +##################################### +### someone's ansible provisioner ### +##################################### +# Part of: https://git.somenet.org/root/pub/somesible.git +# 2017-2024 by someone +# +--- +- name: create config dir /etc/docker/compose-{{dco_svc_name}} + file: + path: "/etc/docker/compose-{{dco_svc_name}}" + state: directory + mode: 0750 + owner: "root" + group: "root" + + +# fail here, if wrong dco_svc_name given +- name: copy config dirtree for service {{dco_svc_name}} + file: + path: "/etc/docker/compose-{{dco_svc_name}}/{{item.path}}" + state: directory + owner: "root" + group: "root" + with_filetree: + - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/svc-{{dco_svc_name}}/config/" + - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/svc-{{dco_svc_name}}/config/" + - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/svc-{{dco_svc_name}}/config/" + - "default/svc-{{dco_svc_name}}/config/" + when: item.state == 'directory' + notify: restart docker-compose@{{dco_svc_name}}.service + + +- name: copy config filetree for service {{dco_svc_name}} + copy: + src: "{{item.src}}" + dest: "/etc/docker/compose-{{dco_svc_name}}/{{item.path}}" + owner: "root" + group: "root" + with_filetree: + - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/svc-{{dco_svc_name}}/config/" + - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/svc-{{dco_svc_name}}/config/" + - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/svc-{{dco_svc_name}}/config/" + - "default/svc-default/config/" + when: item.state == 'file' + notify: restart docker-compose@{{dco_svc_name}}.service + + +- name: create volume dir for service {{dco_svc_name}} + file: + path: "/srv/docker-compose/svc-{{dco_svc_name}}" + state: directory + mode: 0750 + owner: "root" + group: "root" + + +- name: copy volume dirtree for service {{dco_svc_name}} + file: + path: "/srv/docker-compose/svc-{{dco_svc_name}}/{{item.path}}" + state: directory + owner: "root" + group: "root" + with_filetree: + - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/svc-{{dco_svc_name}}/volumes/" + - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/svc-{{dco_svc_name}}/volumes/" + - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/svc-{{dco_svc_name}}/volumes/" + - "default/svc-default/volumes/" + when: item.state == 'directory' + notify: restart docker-compose@{{dco_svc_name}}.service + + +- name: copy volume filetree for service {{dco_svc_name}} + copy: + src: "{{item.src}}" + dest: "/srv/docker-compose/svc-{{dco_svc_name}}/{{item.path}}" + owner: "root" + group: "root" + with_filetree: + - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/svc-{{dco_svc_name}}/volumes/" + - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/svc-{{dco_svc_name}}/volumes/" + - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/svc-{{dco_svc_name}}/volumes/" + - "default/svc-default/volumes/" + when: item.state == 'file' + notify: restart docker-compose@{{dco_svc_name}}.service + + +- name: enable and start docker-compose@{{dco_svc_name}}.service + systemd: + name: docker-compose@{{dco_svc_name}}.service + daemon_reload: yes + enabled: yes + state: started + when: dco_svc_cron == '' + + +- name: generate docker-compose-{{dco_svc_name}}.timer + template: + src: "{{item}}" + dest: "/etc/systemd/system/docker-compose-{{dco_svc_name}}.timer" + mode: 0644 + owner: "root" + group: "root" + with_first_found: + - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/docker-compose.timer.j2" + - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/docker-compose.timer.j2" + - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/docker-compose.timer.j2" + - "default/docker-compose.timer.j2" + when: dco_svc_cron != '' + + +- name: enable and start docker-compose-{{dco_svc_name}}.timer + systemd: + name: docker-compose-{{dco_svc_name}}.timer + daemon_reload: yes + enabled: yes + state: started + when: dco_svc_cron != '' diff --git a/roles/server/docker-compose/dco-service/templates/default/docker-compose.timer.j2 b/roles/server/docker-compose/dco-service/templates/default/docker-compose.timer.j2 new file mode 100644 index 0000000..11a873e --- /dev/null +++ b/roles/server/docker-compose/dco-service/templates/default/docker-compose.timer.j2 @@ -0,0 +1,19 @@ +# +################################################ +### Managed by someone's ansible provisioner ### +################################################ +# Part of: https://git.somenet.org/root/pub/somesible.git +# 2017-2024 by someone +# + +[Unit] +Description=Periodic execution of docker-compose@{{ dco_svc_name }}.service + +[Timer] +Unit=docker-compose@{{ dco_svc_name }}.service +AccuracySec=30 +OnCalendar={{ dco_svc_cron }} +Persistent=true + +[Install] +WantedBy=timers.target -- 2.43.0