From 32fe016c4077fd942ec9c823eea628c177c89691 Mon Sep 17 00:00:00 2001 From: IUCCA <33322841+IUCCA@users.noreply.github.com> Date: Wed, 8 May 2024 15:34:41 +0200 Subject: [PATCH] added optional systemd service + timer for nextcloud app updates (#17) * added optional systemd service + timer for nextcloud app updates * added optional systemd service + timer for nextcloud app updates * added uninstall tasks --- defaults/main.yml | 7 +++++++ tasks/install.yml | 22 ++++++++++++++++++++++ tasks/uninstall.yml | 4 ++++ templates/systemd/app-update.service.j2 | 6 ++++++ templates/systemd/app-update.timer.j2 | 9 +++++++++ 5 files changed, 48 insertions(+) create mode 100644 templates/systemd/app-update.service.j2 create mode 100644 templates/systemd/app-update.timer.j2 diff --git a/defaults/main.yml b/defaults/main.yml index 1d13f63..4285bf6 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -445,6 +445,13 @@ nextcloud_config_additional_parameters: [] # Learn more here: https://man.archlinux.org/man/systemd.time.7 nextcloud_cron_schedule: '*:0/15:0' +#enable auto updates for nextcloud apps +nextcloud_auto_app_update_enabled: false +# nextcloud_auto_app_update_schedule contains a systemd OnCalendar definition which controls how often `app-update.timer` runs +# The default value means 'every day at 00:00'. +# Learn more here: https://man.archlinux.org/man/systemd.time.7 +nextcloud_auto_app_update_schedule: '*-*-* 00:00:00' + # Specifies the value of the `X-XSS-Protection` header # Stops pages from loading when they detect reflected cross-site scripting (XSS) attacks. # diff --git a/tasks/install.yml b/tasks/install.yml index b98e001..5bb367a 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -92,3 +92,25 @@ - server.service - cron.service - cron.timer + +- when: "nextcloud_auto_app_update_enabled | bool" + block: + - name: Ensure Nextcloud app update systemd services installed + ansible.builtin.template: + src: "{{ role_path }}/templates/systemd/{{ item }}.j2" + dest: "{{ devture_systemd_docker_base_systemd_path }}/{{ nextcloud_identifier }}-{{ item }}" + mode: 0640 + with_items: + - app-update.service + - app-update.timer + +- when: "not nextcloud_auto_app_update_enabled | bool" + block: + - name: Ensure Nextcloud systemd app update services do not exists + ansible.builtin.file: + path: "{{ devture_systemd_docker_base_systemd_path }}/{{ nextcloud_identifier }}-{{ item }}" + state: absent + with_items: + - app-update.service + - app-update.timer + diff --git a/tasks/uninstall.yml b/tasks/uninstall.yml index b1e3fff..d897bc3 100644 --- a/tasks/uninstall.yml +++ b/tasks/uninstall.yml @@ -17,6 +17,8 @@ - server.service - cron.service - cron.timer + - app-update.service + - app-update.timer - name: Ensure Nextcloud systemd services do not exists ansible.builtin.file: @@ -26,6 +28,8 @@ - server.service - cron.service - cron.timer + - app-update.service + - app-update.timer - name: Ensure Nextcloud path doesn't exist ansible.builtin.file: diff --git a/templates/systemd/app-update.service.j2 b/templates/systemd/app-update.service.j2 new file mode 100644 index 0000000..16f489f --- /dev/null +++ b/templates/systemd/app-update.service.j2 @@ -0,0 +1,6 @@ +[Unit] +Description=Runs app updates For Nextcloud ({{ nextcloud_identifier }}) + +[Service] +Type=oneshot +ExecStart={{ devture_systemd_docker_base_host_command_docker }} exec {{ nextcloud_identifier }}-server php /var/www/html/occ app:update --all --no-interaction diff --git a/templates/systemd/app-update.timer.j2 b/templates/systemd/app-update.timer.j2 new file mode 100644 index 0000000..e346ea3 --- /dev/null +++ b/templates/systemd/app-update.timer.j2 @@ -0,0 +1,9 @@ +[Unit] +Description=Periodically update the apps for Nextcloud ({{ nextcloud_identifier }}) + +[Timer] +Unit={{ nextcloud_identifier }}-app-update.service +OnCalendar={{ nextcloud_auto_app_update_schedule }} + +[Install] +WantedBy=timers.target \ No newline at end of file