From 905b8b5e7128a5b35c8f0ebe1e84272cf6c054c8 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Wed, 10 Jan 2024 12:13:38 +0100 Subject: [PATCH] Finished storage-optimizer draft --- group_vars/all | 1 + inventory.example.yml | 5 ++++- roles/backup-remote-to-local/handlers/main.yml | 7 ------- roles/storage-optimizer/handlers/main.yml | 4 ++++ roles/storage-optimizer/tasks/main.yml | 18 ++++++++++++++++++ .../templates/storage-optimizer.service.j2 | 8 ++++++++ roles/storage-optimizer/vars/main.yml | 2 ++ 7 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 roles/storage-optimizer/handlers/main.yml create mode 100644 roles/storage-optimizer/tasks/main.yml create mode 100644 roles/storage-optimizer/templates/storage-optimizer.service.j2 create mode 100644 roles/storage-optimizer/vars/main.yml diff --git a/group_vars/all b/group_vars/all index d3294459..a25b465f 100644 --- a/group_vars/all +++ b/group_vars/all @@ -92,6 +92,7 @@ system_maintenance_cleanup_services: system_maintenance_manipulation_services: - "heal-docker" - "update-docker" + - "storage-optimizer" ## Total System Maintenance Services system_maintenance_services: "{{ system_maintenance_backup_services + system_maintenance_cleanup_services + system_maintenance_manipulation_services }}" diff --git a/inventory.example.yml b/inventory.example.yml index a9c2969d..35766f4c 100644 --- a/inventory.example.yml +++ b/inventory.example.yml @@ -45,4 +45,7 @@ pixelfed_database_password: "I_NEED_TO_CHANGE_THIS_UNSECURE_PASSWORD" pixelfed_app_key: "I_NEED_TO_CHANGE_THIS_UNSECURE_PASSWORD" wordpress_database_password: "I_NEED_TO_CHANGE_THIS_UNSECURE_PASSWORD" yourls_database_password: "I_NEED_TO_CHANGE_THIS_UNSECURE_PASSWORD" -yourls_user_password: "I_NEED_TO_CHANGE_THIS_UNSECURE_PASSWORD" \ No newline at end of file +yourls_user_password: "I_NEED_TO_CHANGE_THIS_UNSECURE_PASSWORD" + +path_mass_storage: "/mnt/hdd/" +path_rapid_storage: "/mnt/ssd/" \ No newline at end of file diff --git a/roles/backup-remote-to-local/handlers/main.yml b/roles/backup-remote-to-local/handlers/main.yml index 9e076b83..f0c7b4b4 100644 --- a/roles/backup-remote-to-local/handlers/main.yml +++ b/roles/backup-remote-to-local/handlers/main.yml @@ -2,10 +2,3 @@ systemd: name: backup-remote-to-local.cymais.service daemon_reload: yes - -- name: "restart backup-remote-to-local timer" - systemd: - name: backup-remote-to-local.cymais.timer - state: started - enabled: yes - daemon_reload: yes diff --git a/roles/storage-optimizer/handlers/main.yml b/roles/storage-optimizer/handlers/main.yml new file mode 100644 index 00000000..c63bb350 --- /dev/null +++ b/roles/storage-optimizer/handlers/main.yml @@ -0,0 +1,4 @@ +- name: "reload storage-optimizer service" + systemd: + name: storage-optimizer.cymais.service + daemon_reload: yes \ No newline at end of file diff --git a/roles/storage-optimizer/tasks/main.yml b/roles/storage-optimizer/tasks/main.yml new file mode 100644 index 00000000..c30e982f --- /dev/null +++ b/roles/storage-optimizer/tasks/main.yml @@ -0,0 +1,18 @@ +- name: "create {{storage_optimizer_directory}}" + file: + path: "{{storage_optimizer_directory}}" + state: directory + mode: 0755 + +- name: create storage-optimizer.cymais.service + template: + src: storage-optimizer.service.j2 + dest: /etc/systemd/system/storage-optimizer.cymais.service + notify: reload storage-optimizer service + +- name: create storage-optimizer.py + template: + src: storage-optimizer.py.j2 + dest: "{{storage_optimizer_script}}" + mode: 0755 + notify: reload storage-optimizer service \ No newline at end of file diff --git a/roles/storage-optimizer/templates/storage-optimizer.service.j2 b/roles/storage-optimizer/templates/storage-optimizer.service.j2 new file mode 100644 index 00000000..a8dff299 --- /dev/null +++ b/roles/storage-optimizer/templates/storage-optimizer.service.j2 @@ -0,0 +1,8 @@ +[Unit] +Description=Optimize storage paths +OnFailure=systemd-notifier.cymais@%n.service + +[Service] +Type=oneshot +ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore {{system_maintenance_backup_services| join(' ') }}' +ExecStart=/bin/sh -c '/usr/bin/python {{storage_optimizer_script}} --rapid-storage-path {{rapid_mass_storage}} --mass-storage-path {{path_mass_storage}}' \ No newline at end of file diff --git a/roles/storage-optimizer/vars/main.yml b/roles/storage-optimizer/vars/main.yml new file mode 100644 index 00000000..0e7afd7b --- /dev/null +++ b/roles/storage-optimizer/vars/main.yml @@ -0,0 +1,2 @@ +storage_optimizer_directory: "{{path_administrator_scripts}}storage-optimizer/" +storage_optimizer_script: "{{storage_optimizer_directory}}storage-optimizer.py" \ No newline at end of file