mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2024-11-25 06:01:04 +01:00
Solved bugs and optimized storage-optimiter
This commit is contained in:
parent
d6c1757c5f
commit
59af670009
@ -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
|
||||
|
@ -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 }}"
|
||||
|
@ -1,4 +0,0 @@
|
||||
- name: "start storage-optimizer service"
|
||||
systemd:
|
||||
name: backup-docker-to-local-everything.cymais.service
|
||||
state: started
|
@ -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
|
@ -1,2 +0,0 @@
|
||||
storage_optimizer_directory: "{{path_administrator_scripts}}storage-optimizer/"
|
||||
storage_optimizer_script: "{{storage_optimizer_directory}}storage-optimizer.py"
|
@ -36,12 +36,16 @@ 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.")
|
21
roles/system-storage-optimizer/tasks/main.yml
Normal file
21
roles/system-storage-optimizer/tasks/main.yml
Normal 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
|
@ -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}}'
|
2
roles/system-storage-optimizer/vars/main.yml
Normal file
2
roles/system-storage-optimizer/vars/main.yml
Normal file
@ -0,0 +1,2 @@
|
||||
storage_optimizer_directory: "{{path_administrator_scripts}}system-storage-optimizer/"
|
||||
storage_optimizer_script: "{{storage_optimizer_directory}}system-storage-optimizer.py"
|
Loading…
Reference in New Issue
Block a user