Solved bugs and optimized storage-optimiter

This commit is contained in:
Kevin Veen-Birkenbach 2024-01-10 14:00:43 +01:00
parent d6c1757c5f
commit 59af670009
9 changed files with 35 additions and 30 deletions

View File

@ -11,7 +11,7 @@
hosts: all
become: true
roles:
- role: storage-optimizer
- role: system-storage-optimizer
when: path_mass_storage or path_rapid_storage
- name: setup standard wireguard

View File

@ -92,7 +92,7 @@ system_maintenance_cleanup_services:
system_maintenance_manipulation_services:
- "heal-docker"
- "update-docker"
- "storage-optimizer"
- "system-storage-optimizer"
## Total System Maintenance Services
system_maintenance_services: "{{ system_maintenance_backup_services + system_maintenance_cleanup_services + system_maintenance_manipulation_services }}"

View File

@ -1,4 +0,0 @@
- name: "start storage-optimizer service"
systemd:
name: backup-docker-to-local-everything.cymais.service
state: started

View File

@ -1,18 +0,0 @@
- 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: start storage-optimizer service
- name: create storage-optimizer.py
template:
src: storage-optimizer.py.j2
dest: "{{storage_optimizer_script}}"
mode: 0755
notify: start storage-optimizer service

View File

@ -1,2 +0,0 @@
storage_optimizer_directory: "{{path_administrator_scripts}}storage-optimizer/"
storage_optimizer_script: "{{storage_optimizer_directory}}storage-optimizer.py"

View File

@ -36,11 +36,15 @@ def pause_and_move(storage_path, volume, volume_path, containers):
stop_containers(containers)
# Create a new directory on the Storage
storage_volume_path = os.path.join(storage_path, 'data', 'docker', 'volumes', volume)
os.makedirs(storage_volume_path, exist_ok=False)
os.makedirs(storage_volume_path,exist_ok=False)
# Move the data
for item in os.listdir(volume_path):
shutil.move(os.path.join(volume_path, item), storage_volume_path)
# Ensure the volume_path is empty and remove it
if not os.listdir(volume_path):
os.rmdir(volume_path)
# Create a symbolic link
os.symlink(storage_volume_path, volume_path)
@ -73,9 +77,11 @@ if __name__ == "__main__":
volumes = run_command("docker volume ls -q").splitlines()
for volume in volumes:
containers = run_command(f"docker ps -q --filter volume={volume}").splitlines()
volume_path = get_volume_path(volume)
if is_symbolic_link(volume_path):
containers = run_command(f"docker ps -q --filter volume={volume}").splitlines()
if not containers:
print(f"Skipped Volume {volume}. It does not belong to a running container.")
elif is_symbolic_link(volume_path):
print(f"Skipped Volume {volume}. The storage path {volume_path} is a symbolic link.")
elif has_container_with_database(containers):
print(f"Safing volume {volume} on SSD.")

View File

@ -0,0 +1,21 @@
- name: "create {{storage_optimizer_directory}}"
file:
path: "{{storage_optimizer_directory}}"
state: directory
mode: 0755
- name: create system-storage-optimizer.cymais.service
template:
src: system-storage-optimizer.service.j2
dest: /etc/systemd/system/system-storage-optimizer.cymais.service
- name: create system-storage-optimizer.py
copy:
src: system-storage-optimizer.py
dest: "{{storage_optimizer_script}}"
mode: 0755
- name: "optimize storage performance"
systemd:
name: system-storage-optimizer.cymais.service
state: started

View File

@ -4,5 +4,5 @@ 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(' ') }}'
ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore system-storage-optimizer'
ExecStart=/bin/sh -c '/usr/bin/python {{storage_optimizer_script}} --rapid-storage-path {{path_rapid_storage}} --mass-storage-path {{path_mass_storage}}'

View File

@ -0,0 +1,2 @@
storage_optimizer_directory: "{{path_administrator_scripts}}system-storage-optimizer/"
storage_optimizer_script: "{{storage_optimizer_directory}}system-storage-optimizer.py"