Replace incron with inotify script
This commit is contained in:
parent
b183ddb51c
commit
ade6e4ce3e
|
@ -1,5 +1,6 @@
|
||||||
---
|
---
|
||||||
sftp_root: "/var/sftp" # no trailing /
|
sftp_root: "/var/sftp" # no trailing /
|
||||||
|
software_package_root: "/opt"
|
||||||
|
|
||||||
# temporary fix for https://github.com/ansible/ansible/issues/8603
|
# temporary fix for https://github.com/ansible/ansible/issues/8603
|
||||||
_lizmap_version: 3.7.6
|
_lizmap_version: 3.7.6
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
---
|
---
|
||||||
- name: Setup QGIS-Server and Lizmap
|
- name: Setup QGIS-Server and Lizmap
|
||||||
hosts: testing
|
hosts: testing
|
||||||
vars_files:
|
|
||||||
- variables/public.yaml
|
|
||||||
handlers:
|
handlers:
|
||||||
- name: Ensure nginx is restarted
|
- name: Ensure nginx is restarted
|
||||||
become: true
|
become: true
|
||||||
|
@ -22,12 +20,13 @@
|
||||||
name: "php{{ php['version'] }}-fpm"
|
name: "php{{ php['version'] }}-fpm"
|
||||||
state: restarted
|
state: restarted
|
||||||
|
|
||||||
- name: Ensure incron is restarted and enabled
|
- name: Ensure sftp-permissions is restarted and enabled
|
||||||
become: true
|
become: true
|
||||||
ansible.builtin.systemd:
|
ansible.builtin.systemd:
|
||||||
name: incron
|
name: sftp-permissions
|
||||||
state: restarted
|
state: restarted
|
||||||
enabled: true
|
enabled: true
|
||||||
|
daemon_reload: true
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Ensure valid apt cache and required tools are present
|
- name: Ensure valid apt cache and required tools are present
|
||||||
|
@ -43,7 +42,7 @@
|
||||||
- software-properties-common
|
- software-properties-common
|
||||||
- postgresql
|
- postgresql
|
||||||
- acl # bug: https://github.com/ansible/ansible/issues/74830
|
- acl # bug: https://github.com/ansible/ansible/issues/74830
|
||||||
- incron
|
- inotify-tools
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: Ensure qgis-server is valid
|
- name: Ensure qgis-server is valid
|
||||||
|
@ -442,29 +441,35 @@
|
||||||
group: sftp
|
group: sftp
|
||||||
mode: u=rwX,g=rwXs,o=
|
mode: u=rwX,g=rwXs,o=
|
||||||
|
|
||||||
- name: Ensure incron is latest
|
- name: Ensure sftp-permissions is latest
|
||||||
notify:
|
notify:
|
||||||
- Ensure incron is restarted and enabled
|
- Ensure sftp-permissions is restarted and enabled
|
||||||
become: true
|
become: true
|
||||||
block:
|
block:
|
||||||
- name: Ensure incron for root is enabled
|
- name: Ensure sftp-permissions dir exists
|
||||||
ansible.builtin.blockinfile:
|
ansible.builtin.file:
|
||||||
path: /etc/incron.allow
|
dest: "{{ software_package_root }}/sftp-permissions"
|
||||||
block: "root"
|
state: directory
|
||||||
create: true
|
|
||||||
owner: root
|
owner: root
|
||||||
group: incron
|
group: root
|
||||||
mode: u=rw,g=r,o=
|
mode: u=rwX,g=rX,o=rX
|
||||||
|
|
||||||
|
- name: Ensure sftp-permissions script is latest
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: ./templates/sftp-inotify.sh.j2
|
||||||
|
dest: "{{ software_package_root }}/sftp-permissions/sftp-inotify.sh"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: u=rwx,g=r,o=
|
||||||
backup: true
|
backup: true
|
||||||
|
|
||||||
- name: Ensure incron task for root is latest
|
- name: Ensure sftp-permissions service is latest
|
||||||
ansible.builtin.blockinfile:
|
ansible.builtin.template:
|
||||||
path: /var/spool/incron/root
|
src: ./templates/sftp-permissions.service.j2
|
||||||
block: "{{ lizmap['root_repositories'] }} IN_ATTRIB,IN_CREATE,IN_MOVED_TO chmod g+rw $@/$#"
|
dest: /etc/systemd/system/sftp-permissions.service
|
||||||
create: true
|
|
||||||
owner: root
|
owner: root
|
||||||
group: incron
|
group: root
|
||||||
mode: u=rw,g=,o=
|
mode: u=rw,g=r,o=r
|
||||||
|
|
||||||
- name: Ensure sshd config is latest
|
- name: Ensure sshd config is latest
|
||||||
notify:
|
notify:
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
inotifywait -m -r -e attrib -e create -e moved_to --format '%w%f' {{ sftp_root }} | while read file
|
||||||
|
do
|
||||||
|
current_permissions=$(stat -c %A "$file")
|
||||||
|
if ! [[ "$current_permissions" =~ ^[^\ ](rw[^\ ]){2}[^\ ]{3}$ ]]; then # long: ^[^\ ]rw[^\ ]rw[^\ ][^\ ][^\ ][^\ ]$ matches "?rw?rw????"
|
||||||
|
echo "Attribute change detected on $file"
|
||||||
|
chmod u+rw,g+rw "$file"
|
||||||
|
else
|
||||||
|
echo "Skipped change for $file"
|
||||||
|
fi
|
||||||
|
done
|
|
@ -0,0 +1,9 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Inotify Monitoring Service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart={{ software_package_root }}/sftp-permissions/sftp-inotify.sh
|
||||||
|
;;Restart=always
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
Loading…
Reference in New Issue