From ce0cbe27afafed337d8908af4fb0b110c2335bfc Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Sat, 8 Apr 2023 09:24:47 +0200 Subject: [PATCH] Add external volume to pod-cloud --- .../backups/restic/setup/files/restic-batch | 6 ++-- .../services/deploy/cloud/tasks/main.yml | 1 + .../systemd/container-cloud-chown.service.j2 | 28 +++++++++++++++++++ .../systemd/container-cloud-cron.service.j2 | 4 ++- .../container-cloud-nextcloud.service.j2 | 4 ++- .../roles/services/include/vars/volumes.yml | 3 ++ 6 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 playbooks/roles/services/deploy/cloud/templates/systemd/container-cloud-chown.service.j2 diff --git a/playbooks/roles/backups/restic/setup/files/restic-batch b/playbooks/roles/backups/restic/setup/files/restic-batch index d294736..5c9a3c3 100644 --- a/playbooks/roles/backups/restic/setup/files/restic-batch +++ b/playbooks/roles/backups/restic/setup/files/restic-batch @@ -258,7 +258,8 @@ class DatasetRepoManager(RepoManager): def __get_volume_datasets(self, root_dataset): zfs_list = subprocess.getoutput( - f"zfs list -H -r {root_dataset} -o name,mountpoint" + f"zfs list -H -r {root_dataset} " + "-o name,mountpoint,eu.wojciechkozlowski:offsite-snapshot" ) zfs_list_lines = zfs_list.split('\n') zfs_list_lines_items = map(lambda l: l.split(), zfs_list_lines) @@ -269,7 +270,8 @@ class DatasetRepoManager(RepoManager): dataset, mountpoint, ) - for dataset, mountpoint in zfs_list_lines_items if os.path.ismount(mountpoint) + for dataset, mountpoint, offsite_snapshot in zfs_list_lines_items + if os.path.ismount(mountpoint) and (offsite_snapshot.lower() != "false") ] def restore(self): diff --git a/playbooks/roles/services/deploy/cloud/tasks/main.yml b/playbooks/roles/services/deploy/cloud/tasks/main.yml index 830ea8f..1abb23c 100644 --- a/playbooks/roles/services/deploy/cloud/tasks/main.yml +++ b/playbooks/roles/services/deploy/cloud/tasks/main.yml @@ -39,6 +39,7 @@ loop: - "pod-cloud.service" - "container-cloud-nginx.service" + - "container-cloud-chown.service" - "container-cloud-nextcloud.service" - "container-cloud-cron.service" register: services_deploy_cloud_systemd_files diff --git a/playbooks/roles/services/deploy/cloud/templates/systemd/container-cloud-chown.service.j2 b/playbooks/roles/services/deploy/cloud/templates/systemd/container-cloud-chown.service.j2 new file mode 100644 index 0000000..f808f26 --- /dev/null +++ b/playbooks/roles/services/deploy/cloud/templates/systemd/container-cloud-chown.service.j2 @@ -0,0 +1,28 @@ +[Unit] +Description=Podman container-cloud-chown.service +Documentation=man:podman-generate-systemd(1) +After=pod-cloud.service +Before=container-cloud-nextcloud.service container-cloud-cron.service +OnFailure=status-mail@%n.service + +[Service] +Environment=PODMAN_SYSTEMD_UNIT=%n +TimeoutStopSec=70 +ExecStartPre=/bin/rm -f %t/container-cloud-chown.pid %t/container-cloud-chown.ctr-id +ExecStart=/usr/bin/podman run \ + --conmon-pidfile %t/container-cloud-chown.pid \ + --cidfile %t/container-cloud-chown.ctr-id \ + --cgroups=no-conmon \ + --pod-id-file %t/pod-cloud.pod-id \ + --replace \ + -v {{ services_data_directory }}/pod-cloud/external/_data:/media/external \ + --user=0 \ + --entrypoint="/bin/bash" \ + --name=pod-cloud-chown \ + docker.io/library/nextcloud:{{ services_deploy_versions.cloud.nextcloud }} \ + -c "chown -R www-data:www-data /media/external" +ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/container-cloud-chown.ctr-id +Type=oneshot + +[Install] +WantedBy=container-cloud-nextcloud.service container-cloud-cron.service diff --git a/playbooks/roles/services/deploy/cloud/templates/systemd/container-cloud-cron.service.j2 b/playbooks/roles/services/deploy/cloud/templates/systemd/container-cloud-cron.service.j2 index ae82a0a..c0672c2 100644 --- a/playbooks/roles/services/deploy/cloud/templates/systemd/container-cloud-cron.service.j2 +++ b/playbooks/roles/services/deploy/cloud/templates/systemd/container-cloud-cron.service.j2 @@ -4,7 +4,8 @@ Documentation=man:podman-generate-systemd(1) Wants=network.target After=network-online.target BindsTo=pod-cloud.service -After=pod-cloud.service +Requires=container-cloud-chown.service +After=pod-cloud.service container-cloud-chown.service OnFailure=status-mail@%n.service [Service] @@ -24,6 +25,7 @@ ExecStart=/usr/bin/podman run \ -v {{ services_root_directory }}/{{ services_resolv_host }}-resolv.conf:/etc/resolv.conf:ro \ -v {{ services_data_directory }}/pod-cloud/nextcloud/_data:/var/www/html \ -v {{ services_data_directory }}/pod-cloud/data/_data:/var/www/html/data \ + -v {{ services_data_directory }}/pod-cloud/external/_data:/media/external \ --name=pod-cloud-cron \ docker.io/library/nextcloud:{{ services_deploy_versions.cloud.nextcloud }} \ /cron.sh diff --git a/playbooks/roles/services/deploy/cloud/templates/systemd/container-cloud-nextcloud.service.j2 b/playbooks/roles/services/deploy/cloud/templates/systemd/container-cloud-nextcloud.service.j2 index d99866e..ceb3ce4 100644 --- a/playbooks/roles/services/deploy/cloud/templates/systemd/container-cloud-nextcloud.service.j2 +++ b/playbooks/roles/services/deploy/cloud/templates/systemd/container-cloud-nextcloud.service.j2 @@ -4,7 +4,8 @@ Documentation=man:podman-generate-systemd(1) Wants=network.target After=network-online.target BindsTo=pod-cloud.service -After=pod-cloud.service +Requires=container-cloud-chown.service +After=pod-cloud.service container-cloud-chown.service OnFailure=status-mail@%n.service [Service] @@ -24,6 +25,7 @@ ExecStart=/usr/bin/podman run \ -v {{ services_root_directory }}/{{ services_resolv_host }}-resolv.conf:/etc/resolv.conf:ro \ -v {{ services_data_directory }}/pod-cloud/nextcloud/_data:/var/www/html \ -v {{ services_data_directory }}/pod-cloud/data/_data:/var/www/html/data \ + -v {{ services_data_directory }}/pod-cloud/external/_data:/media/external \ -v ./.config/pod-cloud/database.name:/run/secrets/database.name:ro \ -v ./.config/pod-cloud/database.user:/run/secrets/database.user:ro \ -v ./.config/pod-cloud/database.password:/run/secrets/database.password:ro \ diff --git a/playbooks/roles/services/include/vars/volumes.yml b/playbooks/roles/services/include/vars/volumes.yml index 7af4589..8fa5bf0 100644 --- a/playbooks/roles/services/include/vars/volumes.yml +++ b/playbooks/roles/services/include/vars/volumes.yml @@ -16,6 +16,9 @@ services_volumes: cloud: nextcloud: data: + external: + extra_zfs_properties: + "eu.wojciechkozlowski:offsite-snapshot=false" git: data: notes: