diff --git a/tasks/configure_sftp_server.yml b/tasks/configure_sftp_server.yml index 2a108a5e721771ec34622e5c8b3f477a2e708a9a..7e85b7c537ef4c09b00890dd84b3e6a7710b5756 100644 --- a/tasks/configure_sftp_server.yml +++ b/tasks/configure_sftp_server.yml @@ -136,3 +136,32 @@ when: not external_ftp notify: - restart sshd + +- name: find out if chmod script for correcting permissions of SIPs uploaded via SFTP is installed + ansible.builtin.stat: + path: "/usr/local/bin/chmod.sh" + register: chmod_installed + +- name: deploy systemd units for correcting permissions of SIPs uploaded via SFTP + ansible.builtin.template: + src: "usr/local/lib/systemd/system/chmod_chown_sftp_uploads.{{ item }}.j2" + dest: "/usr/local/lib/systemd/system/chmod_chown_sftp_uploads.{{ item }}" + mode: "0644" + loop: + - "timer" + - "service" + when: chmod_installed.stat.exists + +- name: activate chmod systemd units + ansible.builtin.systemd: + daemon_reload: true + name: "chmod_chown_sftp_uploads.{{ item.name }}" + enabled: "{{ item.enabled | default(true) }}" + state: "{{ item.state | default(omit) }}" + loop: + - name: "service" + enabled: true + - name: "timer" + enabled: true + state: started + when: chmod_installed.stat.exists diff --git a/templates/usr/local/lib/systemd/system/chmod_chown_sftp_uploads.service.j2 b/templates/usr/local/lib/systemd/system/chmod_chown_sftp_uploads.service.j2 new file mode 100644 index 0000000000000000000000000000000000000000..03d4ef3b6b380d57d74a340b6e74945934c07935 --- /dev/null +++ b/templates/usr/local/lib/systemd/system/chmod_chown_sftp_uploads.service.j2 @@ -0,0 +1,11 @@ +[Unit] +Description=service: set correct permissions for SIPs that were uploaded via SFTP + +[Service] +Type=oneshot +Restart=no +User=root +ExecStart=/usr/local/bin/chown.sh + +[Install] +WantedBy=default.target diff --git a/templates/usr/local/lib/systemd/system/chmod_chown_sftp_uploads.timer.j2 b/templates/usr/local/lib/systemd/system/chmod_chown_sftp_uploads.timer.j2 new file mode 100644 index 0000000000000000000000000000000000000000..4c7ac42839fff30bdebeb944f9fa13c844bd53a3 --- /dev/null +++ b/templates/usr/local/lib/systemd/system/chmod_chown_sftp_uploads.timer.j2 @@ -0,0 +1,14 @@ +[Unit] +Description=timer: set correct permissions for SIPs that were uploaded via SFTP + +[Timer] +OnUnitActiveSec=300 +#When activated, it triggers the service immediately if it missed the last start time, for example due to the system being powered off +Persistent=true +#Unit to activate when the timer elapses. (default is set to the same name as the timer unit, except for the suffix) +Unit=chmod_chown_sftp_uploads.service + +[Install] +#is requires to activate the timer permanently +#on first init a symbolic link of /etc/systemd/system/basic.target.wants will be created +WantedBy=default.target