mirror of
				https://github.com/kevinveenbirkenbach/computer-playbook.git
				synced 2025-11-03 19:58:14 +00:00 
			
		
		
		
	Solved bug in logic
This commit is contained in:
		@@ -22,11 +22,6 @@ def check_service_active(service_name):
 | 
				
			|||||||
    service_status = result.stdout.decode('utf-8').strip()
 | 
					    service_status = result.stdout.decode('utf-8').strip()
 | 
				
			||||||
    return service_status in ['active', 'activating', 'deactivating', 'reloading']
 | 
					    return service_status in ['active', 'activating', 'deactivating', 'reloading']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#def service_exists(service_name):
 | 
					 | 
				
			||||||
#    """Check if a service exists."""
 | 
					 | 
				
			||||||
#    result = subprocess.run(['systemctl', 'status', service_name], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 | 
					 | 
				
			||||||
#    return result.returncode == 0
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def freeze(services_to_wait_for, ignored_services):
 | 
					def freeze(services_to_wait_for, ignored_services):
 | 
				
			||||||
    # Filter services that exist and are not in the ignored list
 | 
					    # Filter services that exist and are not in the ignored list
 | 
				
			||||||
    for service in services_to_wait_for:
 | 
					    for service in services_to_wait_for:
 | 
				
			||||||
@@ -34,8 +29,11 @@ def freeze(services_to_wait_for, ignored_services):
 | 
				
			|||||||
        if service in ignored_services:
 | 
					        if service in ignored_services:
 | 
				
			||||||
            print(f"{service} will be ignored.")
 | 
					            print(f"{service} will be ignored.")
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            service_active = check_service_active(service)
 | 
					            
 | 
				
			||||||
            while not service_active:
 | 
					            while check_service_active(service):
 | 
				
			||||||
 | 
					                print(f"Waiting for 5 seconds for {service} to stop...")
 | 
				
			||||||
 | 
					                time.sleep(5)
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
            # Stop and disable the corresponding timer, if it exists
 | 
					            # Stop and disable the corresponding timer, if it exists
 | 
				
			||||||
            if service_file_exists(service,"timer"):
 | 
					            if service_file_exists(service,"timer"):
 | 
				
			||||||
                timer_name = service + ".timer"
 | 
					                timer_name = service + ".timer"
 | 
				
			||||||
@@ -45,10 +43,6 @@ def freeze(services_to_wait_for, ignored_services):
 | 
				
			|||||||
            else:
 | 
					            else:
 | 
				
			||||||
                print(f"Skipped.")
 | 
					                print(f"Skipped.")
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
                if not service_active:
 | 
					 | 
				
			||||||
                    print(f"Waiting for 5 seconds for {service} to stop...")
 | 
					 | 
				
			||||||
                    time.sleep(5)
 | 
					 | 
				
			||||||
                    service_active = check_service_active(service)
 | 
					 | 
				
			||||||
    print("\nAll required services have stopped.")
 | 
					    print("\nAll required services have stopped.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def defrost(services_to_wait_for, ignored_services):
 | 
					def defrost(services_to_wait_for, ignored_services):
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user