mirror of
				https://github.com/kevinveenbirkenbach/computer-playbook.git
				synced 2025-11-04 12:18:17 +00:00 
			
		
		
		
	Compare commits
	
		
			2 Commits
		
	
	
		
			8481b3ddfe
			...
			ebd8154d83
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| ebd8154d83 | |||
| 1bb6a99740 | 
@@ -5,5 +5,5 @@ OnFailure=systemd-notifier.cymais@%n.service cleanup-failed-docker-backups.cymai
 | 
				
			|||||||
[Service]
 | 
					[Service]
 | 
				
			||||||
Type=oneshot
 | 
					Type=oneshot
 | 
				
			||||||
ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ')  }} --ignore {{ system_maintenance_backup_services | reject('equalto', 'backup-docker-to-local') | join(' ') }} --timeout "{{sytem_maintenance_lock_timeout_backup_services}}"'
 | 
					ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ')  }} --ignore {{ system_maintenance_backup_services | reject('equalto', 'backup-docker-to-local') | join(' ') }} --timeout "{{sytem_maintenance_lock_timeout_backup_services}}"'
 | 
				
			||||||
ExecStart=/bin/sh -c '/usr/bin/python {{backup_docker_to_local_folder}}backup-docker-to-local.py --everything'
 | 
					ExecStart=/bin/sh -c '/usr/bin/python {{backup_docker_to_local_folder}}backup-docker-to-local.py --compose-dir {{path_docker_compose_instances}} --everything'
 | 
				
			||||||
ExecStartPost=/bin/sh -c '/bin/systemctl start heal-docker.cymais.service &'
 | 
					ExecStartPost=/bin/sh -c '/bin/systemctl start heal-docker.cymais.service &'
 | 
				
			||||||
@@ -5,5 +5,5 @@ OnFailure=systemd-notifier.cymais@%n.service cleanup-failed-docker-backups.cymai
 | 
				
			|||||||
[Service]
 | 
					[Service]
 | 
				
			||||||
Type=oneshot
 | 
					Type=oneshot
 | 
				
			||||||
ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ')  }} --ignore {{ system_maintenance_backup_services | reject('equalto', 'backup-docker-to-local-everything') | join(' ') }} --timeout "{{sytem_maintenance_lock_timeout_backup_services}}"'
 | 
					ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ')  }} --ignore {{ system_maintenance_backup_services | reject('equalto', 'backup-docker-to-local-everything') | join(' ') }} --timeout "{{sytem_maintenance_lock_timeout_backup_services}}"'
 | 
				
			||||||
ExecStart=/bin/sh -c '/usr/bin/python {{backup_docker_to_local_folder}}backup-docker-to-local.py'
 | 
					ExecStart=/bin/sh -c '/usr/bin/python {{backup_docker_to_local_folder}}backup-docker-to-local.py --compose-dir {{path_docker_compose_instances}}'
 | 
				
			||||||
ExecStartPost=/bin/sh -c '/bin/systemctl start heal-docker.cymais.service &'
 | 
					ExecStartPost=/bin/sh -c '/bin/systemctl start heal-docker.cymais.service &'
 | 
				
			||||||
@@ -13,6 +13,19 @@ def restart_docker_services(dir_path):
 | 
				
			|||||||
    except subprocess.CalledProcessError as e:
 | 
					    except subprocess.CalledProcessError as e:
 | 
				
			||||||
        print(f"Error restarting services in {dir_path}: {e}")
 | 
					        print(f"Error restarting services in {dir_path}: {e}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def hard_restart_docker_services(dir_path):
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    Perform a hard restart of docker-compose services in the given directory
 | 
				
			||||||
 | 
					    using docker-compose down and docker-compose up -d.
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    try:
 | 
				
			||||||
 | 
					        print(f"Performing hard restart for docker-compose services in: {dir_path}")
 | 
				
			||||||
 | 
					        subprocess.run(["docker-compose", "down"], cwd=dir_path, check=True)
 | 
				
			||||||
 | 
					        subprocess.run(["docker-compose", "up", "-d"], cwd=dir_path, check=True)
 | 
				
			||||||
 | 
					        print(f"Hard restart completed successfully in: {dir_path}")
 | 
				
			||||||
 | 
					    except subprocess.CalledProcessError as e:
 | 
				
			||||||
 | 
					        print(f"Error during hard restart in {dir_path}: {e}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == "__main__":
 | 
					if __name__ == "__main__":
 | 
				
			||||||
    if len(sys.argv) < 2:
 | 
					    if len(sys.argv) < 2:
 | 
				
			||||||
        print("Please provide the path to the parent directory as a parameter.")
 | 
					        print("Please provide the path to the parent directory as a parameter.")
 | 
				
			||||||
@@ -23,12 +36,18 @@ if __name__ == "__main__":
 | 
				
			|||||||
    for dir_entry in os.scandir(parent_directory):
 | 
					    for dir_entry in os.scandir(parent_directory):
 | 
				
			||||||
        if dir_entry.is_dir():
 | 
					        if dir_entry.is_dir():
 | 
				
			||||||
            dir_path = dir_entry.path
 | 
					            dir_path = dir_entry.path
 | 
				
			||||||
 | 
					            dir_name = os.path.basename(dir_path)
 | 
				
			||||||
            print(f"Checking directory: {dir_path}")
 | 
					            print(f"Checking directory: {dir_path}")
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            docker_compose_file = os.path.join(dir_path, "docker-compose.yml")
 | 
					            docker_compose_file = os.path.join(dir_path, "docker-compose.yml")
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            if os.path.isfile(docker_compose_file):
 | 
					            if os.path.isfile(docker_compose_file):
 | 
				
			||||||
                print(f"Found docker-compose.yml in {dir_path}. Restarting services...")
 | 
					                print(f"Found docker-compose.yml in {dir_path}.")
 | 
				
			||||||
 | 
					                if dir_name == "mailu":
 | 
				
			||||||
 | 
					                    print(f"Directory {dir_name} detected. Performing hard restart...")
 | 
				
			||||||
 | 
					                    hard_restart_docker_services(dir_path)
 | 
				
			||||||
 | 
					                else:
 | 
				
			||||||
 | 
					                    print(f"Restarting services in {dir_path}...")
 | 
				
			||||||
                    restart_docker_services(dir_path)
 | 
					                    restart_docker_services(dir_path)
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                print(f"No docker-compose.yml found in {dir_path}. Skipping.")
 | 
					                print(f"No docker-compose.yml found in {dir_path}. Skipping.")
 | 
				
			||||||
		Reference in New Issue
	
	Block a user