From 186d57f758c9183ec733a926b83c8d52fc176125 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sun, 26 Mar 2023 17:05:06 +0200 Subject: [PATCH] Refactored /usr/local/bin --- roles/docker-akaunting/README.md | 2 +- roles/docker-mailu/README.md | 1 + roles/docker-nextcloud/README.md | 4 ++-- roles/native-backups-cleanup/tasks/main.yml | 12 ++++++++---- .../backups-cleanup.service.j2} | 2 +- roles/native-backups-cleanup/vars/main.yml | 1 + roles/native-btrfs-health-check/tasks/main.yml | 10 ++++------ .../btrfs-health-check.service.j2} | 2 +- roles/native-btrfs-health-check/vars/main.yml | 1 + roles/native-docker-health-check/tasks/main.yml | 10 ++++------ .../docker-health-check.service.j2} | 2 +- roles/native-docker-health-check/vars/main.yml | 1 + roles/native-docker-volume-backup/tasks/main.yml | 12 ++++++------ ...ackup.service => docker-volume-backup.service.j2} | 2 +- ...me-backup.timer => docker-volume-backup.timer.j2} | 0 roles/native-docker-volume-backup/vars/main.yml | 1 + roles/native-pull-primary-backups/tasks/main.yml | 10 +++++----- ...ackups.service => pull-remote-backups.service.j2} | 2 +- ...l-remote-backups.sh => pull-remote-backups.sh.j2} | 2 +- ...te-backups.timer => pull-remote-backups.timer.j2} | 0 roles/native-pull-primary-backups/vars/main.yml | 1 + roles/native-systemd-email/tasks/main.yml | 8 +++++++- .../templates/systemd-email@.service.j2 | 2 +- roles/native-systemd-email/vars/main.yml | 1 + 24 files changed, 51 insertions(+), 38 deletions(-) rename roles/native-backups-cleanup/{files/backups-cleanup.service => templates/backups-cleanup.service.j2} (57%) create mode 100644 roles/native-backups-cleanup/vars/main.yml rename roles/native-btrfs-health-check/{files/btrfs-health-check.service => templates/btrfs-health-check.service.j2} (52%) create mode 100644 roles/native-btrfs-health-check/vars/main.yml rename roles/native-docker-health-check/{files/docker-health-check.service => templates/docker-health-check.service.j2} (52%) create mode 100644 roles/native-docker-health-check/vars/main.yml rename roles/native-docker-volume-backup/templates/{docker-volume-backup.service => docker-volume-backup.service.j2} (53%) rename roles/native-docker-volume-backup/templates/{docker-volume-backup.timer => docker-volume-backup.timer.j2} (100%) create mode 100644 roles/native-docker-volume-backup/vars/main.yml rename roles/native-pull-primary-backups/templates/{pull-remote-backups.service => pull-remote-backups.service.j2} (53%) rename roles/native-pull-primary-backups/templates/{pull-remote-backups.sh => pull-remote-backups.sh.j2} (61%) rename roles/native-pull-primary-backups/templates/{pull-remote-backups.timer => pull-remote-backups.timer.j2} (100%) create mode 100644 roles/native-pull-primary-backups/vars/main.yml create mode 100644 roles/native-systemd-email/vars/main.yml diff --git a/roles/docker-akaunting/README.md b/roles/docker-akaunting/README.md index c776183d..86630f3a 100644 --- a/roles/docker-akaunting/README.md +++ b/roles/docker-akaunting/README.md @@ -81,7 +81,7 @@ docker-compose build && docker-compose -p akaunting up -d --force-recreate # recover all volumes -cd /usr/local/bin/docker-volume-backup && +cd /home/administrator/scripts/docker-volume-backup && bash docker-volume-recover.sh akaunting_akaunting-modules ${machine_id:0:64} "$backup_version" && bash docker-volume-recover.sh akaunting_akaunting-data ${machine_id:0:64} "$backup_version" && bash docker-volume-recover.sh akaunting_akaunting-db ${machine_id:0:64} "$backup_version" akaunting-db "$akaunting_db_password" akaunting diff --git a/roles/docker-mailu/README.md b/roles/docker-mailu/README.md index c9191829..b95a1b3f 100644 --- a/roles/docker-mailu/README.md +++ b/roles/docker-mailu/README.md @@ -81,3 +81,4 @@ For update instructions follow: - https://github.com/nuxsmin/sysPass/issues/1299 - https://github.com/Mailu/Mailu/issues/1171 - https://support.plesk.com/hc/en-us/articles/115001264814-Unable-to-log-into-RoundCube-Connection-to-storage-server-failed +- https://github.com/Mailu/Mailu diff --git a/roles/docker-nextcloud/README.md b/roles/docker-nextcloud/README.md index ffbe95c0..b01f16fa 100644 --- a/roles/docker-nextcloud/README.md +++ b/roles/docker-nextcloud/README.md @@ -13,7 +13,7 @@ NEXTCLOUD_APPLICATION_DOCKER_CONTAINER=nextcloud-application-1 To update the nextcloud container execute the following commands on the server: ```bash docker exec -it -u www-data $NEXTCLOUD_APPLICATION_DOCKER_CONTAINER /var/www/html/occ maintenance:mode --on - sudo python /usr/local/bin/docker-volume-backup/docker-volume-backup.py + sudo python /home/administrator/scripts/docker-volume-backup/docker-volume-backup.py export COMPOSE_HTTP_TIMEOUT=600 export DOCKER_CLIENT_TIMEOUT=600 cd /home/administrator/docker-compose/nextcloud && docker-compose down @@ -58,7 +58,7 @@ and disable the not functioning apps. cd /home/administrator/docker-compose/nextcloud && docker-compose down && docker exec -i nextcloud_database_1 mysql -u nextcloud -pPASSWORT nextcloud < "/Backups/$(sha256sum /etc/machine-id | head -c 64)/docker-volume-backup/latest/nextcloud_database/sql/backup.sql" && -cd /usr/local/bin/docker-volume-backup && +cd /home/administrator/scripts/docker-volume-backup && bash ./docker-volume-recover.sh "nextcloud_data" "$(sha256sum /etc/machine-id | head -c 64)" ``` diff --git a/roles/native-backups-cleanup/tasks/main.yml b/roles/native-backups-cleanup/tasks/main.yml index e135a563..7239b899 100644 --- a/roles/native-backups-cleanup/tasks/main.yml +++ b/roles/native-backups-cleanup/tasks/main.yml @@ -2,13 +2,17 @@ pip: name: psutil +- name: "create {{docker_backups_cleanup}}" + file: + path: "{{docker_backups_cleanup}}" + state: directory + mode: 0755 + - name: create backups-cleanup.py - template: src=backups-cleanup.py.j2 dest=/usr/local/bin/backups-cleanup.py + template: src=backups-cleanup.py.j2 dest={{docker_backups_cleanup}}backups-cleanup.py - name: create backups-cleanup.service - copy: - src: backups-cleanup.service - dest: "/etc/systemd/system/backups-cleanup.service" + template: src=backups-cleanup.service.j2 dest=/etc/systemd/system/backups-cleanup.service notify: restart backups-cleanup.service - name: create backups-cleanup.timer diff --git a/roles/native-backups-cleanup/files/backups-cleanup.service b/roles/native-backups-cleanup/templates/backups-cleanup.service.j2 similarity index 57% rename from roles/native-backups-cleanup/files/backups-cleanup.service rename to roles/native-backups-cleanup/templates/backups-cleanup.service.j2 index 286a8fee..a1734e0b 100644 --- a/roles/native-backups-cleanup/files/backups-cleanup.service +++ b/roles/native-backups-cleanup/templates/backups-cleanup.service.j2 @@ -4,4 +4,4 @@ OnFailure=systemd-email@%n.service [Service] Type=oneshot -ExecStart=/usr/bin/python /usr/local/bin/backups-cleanup.py +ExecStart=/usr/bin/python {{docker_backups_cleanup}}/backups-cleanup.py diff --git a/roles/native-backups-cleanup/vars/main.yml b/roles/native-backups-cleanup/vars/main.yml new file mode 100644 index 00000000..53d8460a --- /dev/null +++ b/roles/native-backups-cleanup/vars/main.yml @@ -0,0 +1 @@ +docker_backups_cleanup: "/home/administrator/scripts/backups-cleanup/" \ No newline at end of file diff --git a/roles/native-btrfs-health-check/tasks/main.yml b/roles/native-btrfs-health-check/tasks/main.yml index 0e88f5ad..acd97806 100644 --- a/roles/native-btrfs-health-check/tasks/main.yml +++ b/roles/native-btrfs-health-check/tasks/main.yml @@ -1,18 +1,16 @@ -- name: "create /home/administrator/scripts/btrfs-health-check/" +- name: "create {{docker_btrfs_health_check_folder}}" file: - path: "/home/administrator/scripts/btrfs-health-check" + path: "{{docker_btrfs_health_check_folder}}" state: directory mode: 0755 - name: create btrfs-health-check.sh copy: src: btrfs-health-check.sh - dest: "/home/administrator/scripts/btrfs-health-check/btrfs-health-check.sh" + dest: "{{docker_btrfs_health_check_folder}}btrfs-health-check.sh" - name: create btrfs-health-check.service - copy: - src: btrfs-health-check.service - dest: "/etc/systemd/system/btrfs-health-check.service" + template: btrfs-health-check.service.j2 dest=/etc/systemd/system/btrfs-health-check.service notify: restart btrfs-health-check.service - name: create btrfs-health-check.timer diff --git a/roles/native-btrfs-health-check/files/btrfs-health-check.service b/roles/native-btrfs-health-check/templates/btrfs-health-check.service.j2 similarity index 52% rename from roles/native-btrfs-health-check/files/btrfs-health-check.service rename to roles/native-btrfs-health-check/templates/btrfs-health-check.service.j2 index ba2131a0..89a73ca3 100644 --- a/roles/native-btrfs-health-check/files/btrfs-health-check.service +++ b/roles/native-btrfs-health-check/templates/btrfs-health-check.service.j2 @@ -4,4 +4,4 @@ OnFailure=systemd-email@%n.service [Service] Type=oneshot -ExecStart=/bin/bash /home/administrator/scripts/btrfs-health-check/btrfs-health-check.sh +ExecStart=/bin/bash {{docker_btrfs_health_check_folder}}btrfs-health-check.sh diff --git a/roles/native-btrfs-health-check/vars/main.yml b/roles/native-btrfs-health-check/vars/main.yml new file mode 100644 index 00000000..9178636c --- /dev/null +++ b/roles/native-btrfs-health-check/vars/main.yml @@ -0,0 +1 @@ +docker_btrfs_health_check_folder: "/home/administrator/scripts/btrfs-health-check/" \ No newline at end of file diff --git a/roles/native-docker-health-check/tasks/main.yml b/roles/native-docker-health-check/tasks/main.yml index e2c147f8..d11afdc2 100644 --- a/roles/native-docker-health-check/tasks/main.yml +++ b/roles/native-docker-health-check/tasks/main.yml @@ -1,18 +1,16 @@ -- name: "create /home/administrator/scripts/docker-health-check/" +- name: "create {{docker_health_check_folder}}" file: - path: "/home/administrator/scripts/docker-health-check" + path: "{{docker_health_check_folder}}" state: directory mode: 0755 - name: create docker-health-check.sh copy: src: docker-health-check.sh - dest: "/home/administrator/scripts/docker-health-check/docker-health-check.sh" + dest: "{{docker_health_check_folder}}docker-health-check.sh" - name: create docker-health-check.service - copy: - src: docker-health-check.service - dest: "/etc/systemd/system/docker-health-check.service" + template: src=docker-health-check.service.j2 dest=/etc/systemd/system/docker-health-check.service notify: restart docker-health-check.service - name: create docker-health-check.timer diff --git a/roles/native-docker-health-check/files/docker-health-check.service b/roles/native-docker-health-check/templates/docker-health-check.service.j2 similarity index 52% rename from roles/native-docker-health-check/files/docker-health-check.service rename to roles/native-docker-health-check/templates/docker-health-check.service.j2 index 31bd0ffa..0e921b32 100644 --- a/roles/native-docker-health-check/files/docker-health-check.service +++ b/roles/native-docker-health-check/templates/docker-health-check.service.j2 @@ -4,4 +4,4 @@ OnFailure=systemd-email@%n.service [Service] Type=oneshot -ExecStart=/bin/bash /home/administrator/scripts/docker-health-check/docker-health-check.sh +ExecStart=/bin/bash {{docker_health_check_folder}}docker-health-check.sh diff --git a/roles/native-docker-health-check/vars/main.yml b/roles/native-docker-health-check/vars/main.yml new file mode 100644 index 00000000..935fb810 --- /dev/null +++ b/roles/native-docker-health-check/vars/main.yml @@ -0,0 +1 @@ +docker_health_check_folder: "/home/administrator/scripts/docker-health-check/" \ No newline at end of file diff --git a/roles/native-docker-volume-backup/tasks/main.yml b/roles/native-docker-volume-backup/tasks/main.yml index a83f3549..8056b02f 100644 --- a/roles/native-docker-volume-backup/tasks/main.yml +++ b/roles/native-docker-volume-backup/tasks/main.yml @@ -5,20 +5,20 @@ - name: pull docker-volume-backup.git git: repo: "https://github.com/kevinveenbirkenbach/docker-volume-backup.git" - dest: "/usr/local/bin/docker-volume-backup" + dest: "{{docker_volume_backup_folder}}" update: yes - name: configure docker-volume-backup.service.tpl - template: src=docker-volume-backup.service dest=/etc/systemd/system/docker-volume-backup.service + template: src=docker-volume-backup.service.j2 dest=/etc/systemd/system/docker-volume-backup.service notify: restart docker-volume-backup service - name: configure docker-volume-backup.timer.tpl - template: src=docker-volume-backup.timer dest=/etc/systemd/system/docker-volume-backup.timer + template: src=docker-volume-backup.timer.j2 dest=/etc/systemd/system/docker-volume-backup.timer notify: restart docker-volume-backup timer -- name: create /usr/local/bin/docker-volume-backup/databases.csv +- name: create {{docker_volume_backup_folder}}/databases.csv copy: - src: "{{ inventory_dir }}/files/{{ inventory_hostname }}/usr/local/bin/docker-volume-backup/databases.csv" - dest: /usr/local/bin/docker-volume-backup/databases.csv + src: "{{ inventory_dir }}/files/{{ inventory_hostname }}{{docker_volume_backup_folder}}/databases.csv" + dest: {{docker_volume_backup_folder}}/databases.csv owner: root group: root diff --git a/roles/native-docker-volume-backup/templates/docker-volume-backup.service b/roles/native-docker-volume-backup/templates/docker-volume-backup.service.j2 similarity index 53% rename from roles/native-docker-volume-backup/templates/docker-volume-backup.service rename to roles/native-docker-volume-backup/templates/docker-volume-backup.service.j2 index 4441b8a8..8febb335 100644 --- a/roles/native-docker-volume-backup/templates/docker-volume-backup.service +++ b/roles/native-docker-volume-backup/templates/docker-volume-backup.service.j2 @@ -4,4 +4,4 @@ OnFailure=systemd-email@%n.service [Service] Type=oneshot -ExecStart=/usr/bin/python /usr/local/bin/docker-volume-backup/docker-volume-backup.py +ExecStart=/usr/bin/python {{docker_volume_backup_folder}}/docker-volume-backup.py \ No newline at end of file diff --git a/roles/native-docker-volume-backup/templates/docker-volume-backup.timer b/roles/native-docker-volume-backup/templates/docker-volume-backup.timer.j2 similarity index 100% rename from roles/native-docker-volume-backup/templates/docker-volume-backup.timer rename to roles/native-docker-volume-backup/templates/docker-volume-backup.timer.j2 diff --git a/roles/native-docker-volume-backup/vars/main.yml b/roles/native-docker-volume-backup/vars/main.yml new file mode 100644 index 00000000..d73c2dea --- /dev/null +++ b/roles/native-docker-volume-backup/vars/main.yml @@ -0,0 +1 @@ +docker_volume_backup_folder: "/home/administrator/scripts/docker-volume-backup/" \ No newline at end of file diff --git a/roles/native-pull-primary-backups/tasks/main.yml b/roles/native-pull-primary-backups/tasks/main.yml index 28d73c29..cba08327 100644 --- a/roles/native-pull-primary-backups/tasks/main.yml +++ b/roles/native-pull-primary-backups/tasks/main.yml @@ -1,15 +1,15 @@ - name: create pull-remote-backup.sh copy: src: pull-remote-backup.sh - dest: "/usr/local/bin/pull-remote-backup.sh" + dest: "bash {{docker_pull_primary_backups_folder}}pull-remote-backup.sh" - name: create pull-remote-backups.service - template: src=pull-remote-backups.service dest=/etc/systemd/system/pull-remote-backups.service - notify: restart pull-remote-backups service + template: src=pull-remote-backups.service.j2 dest=/etc/systemd/system/pull-remote-backups.service + notify: restart pull-remote-backups serviceß - name: create pull-remote-backups.timer - template: src=pull-remote-backups.timer dest=/etc/systemd/system/pull-remote-backups.timer + template: src=pull-remote-backups.timer.j2 dest=/etc/systemd/system/pull-remote-backups.timer notify: restart pull-remote-backups timer - name: create pull-remote-backups.sh - template: src=pull-remote-backups.sh dest=/usr/local/bin/pull-remote-backups.sh + template: src=pull-remote-backups.sh.j2 dest=bash {{docker_pull_primary_backups_folder}}pull-remote-backups.sh diff --git a/roles/native-pull-primary-backups/templates/pull-remote-backups.service b/roles/native-pull-primary-backups/templates/pull-remote-backups.service.j2 similarity index 53% rename from roles/native-pull-primary-backups/templates/pull-remote-backups.service rename to roles/native-pull-primary-backups/templates/pull-remote-backups.service.j2 index 7189b160..8627f9f0 100644 --- a/roles/native-pull-primary-backups/templates/pull-remote-backups.service +++ b/roles/native-pull-primary-backups/templates/pull-remote-backups.service.j2 @@ -4,4 +4,4 @@ OnFailure=systemd-email@%n.service [Service] Type=oneshot -ExecStart=/usr/bin/bash /usr/local/bin/pull-remote-backups.sh +ExecStart=/usr/bin/bash {{docker_pull_primary_backups_folder}}pull-remote-backups.sh diff --git a/roles/native-pull-primary-backups/templates/pull-remote-backups.sh b/roles/native-pull-primary-backups/templates/pull-remote-backups.sh.j2 similarity index 61% rename from roles/native-pull-primary-backups/templates/pull-remote-backups.sh rename to roles/native-pull-primary-backups/templates/pull-remote-backups.sh.j2 index e10e2544..eddb8427 100644 --- a/roles/native-pull-primary-backups/templates/pull-remote-backups.sh +++ b/roles/native-pull-primary-backups/templates/pull-remote-backups.sh.j2 @@ -3,6 +3,6 @@ hosts="{{pull_remote_backups_hosts}}"; errors=0 for host in $hosts; do - bash /usr/local/bin/pull-remote-backup.sh $host || ((errors+=1)); + bash {{docker_pull_primary_backups_folder}}/pull-remote-backup.sh $host || ((errors+=1)); done; exit $errors; diff --git a/roles/native-pull-primary-backups/templates/pull-remote-backups.timer b/roles/native-pull-primary-backups/templates/pull-remote-backups.timer.j2 similarity index 100% rename from roles/native-pull-primary-backups/templates/pull-remote-backups.timer rename to roles/native-pull-primary-backups/templates/pull-remote-backups.timer.j2 diff --git a/roles/native-pull-primary-backups/vars/main.yml b/roles/native-pull-primary-backups/vars/main.yml new file mode 100644 index 00000000..d72095d6 --- /dev/null +++ b/roles/native-pull-primary-backups/vars/main.yml @@ -0,0 +1 @@ +docker_pull_primary_backups_folder: "/usr/local/bin/pull-primary-backups/" \ No newline at end of file diff --git a/roles/native-systemd-email/tasks/main.yml b/roles/native-systemd-email/tasks/main.yml index 35207f88..56d0045b 100644 --- a/roles/native-systemd-email/tasks/main.yml +++ b/roles/native-systemd-email/tasks/main.yml @@ -4,8 +4,14 @@ - name: configure msmtprc.conf.j2 template: src=msmtprc.conf.j2 dest=/root/.msmtprc +- name: "create {{systemd_email_folder}}" + file: + path: "{{systemd_email_folder}}" + state: directory + mode: 0755 + - name: configure systemd-email.sh - template: src=systemd-email.sh.j2 dest=/usr/local/bin/systemd-email.sh + template: src=systemd-email.sh.j2 dest={{systemd_email_folder}}bin/systemd-email.sh - name: configure systemd-email.service template: src=systemd-email@.service.j2 dest=/etc/systemd/system/systemd-email@.service diff --git a/roles/native-systemd-email/templates/systemd-email@.service.j2 b/roles/native-systemd-email/templates/systemd-email@.service.j2 index 2a58bd2b..86f537e9 100644 --- a/roles/native-systemd-email/templates/systemd-email@.service.j2 +++ b/roles/native-systemd-email/templates/systemd-email@.service.j2 @@ -3,6 +3,6 @@ Description=status email for %i to user [Service] Type=oneshot -ExecStart=/bin/bash /usr/local/bin/systemd-email.sh %i +ExecStart=/bin/bash {{systemd_email_folder}}systemd-email.sh %i User=root Group=systemd-journal diff --git a/roles/native-systemd-email/vars/main.yml b/roles/native-systemd-email/vars/main.yml new file mode 100644 index 00000000..1245b11f --- /dev/null +++ b/roles/native-systemd-email/vars/main.yml @@ -0,0 +1 @@ +systemd_email_folder: "/home/administrator/scripts/systemd_email/" \ No newline at end of file