Solved bug in logic

This commit is contained in:
Kevin Veen-Birkenbach 2023-12-14 00:53:17 +01:00
parent 6cb8c9547b
commit 5443683042

View File

@ -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,21 +29,20 @@ 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):
# Stop and disable the corresponding timer, if it exists print(f"Waiting for 5 seconds for {service} to stop...")
if service_file_exists(service,"timer"): time.sleep(5)
timer_name = service + ".timer"
subprocess.run(['systemctl', 'stop', timer_name]) # Stop and disable the corresponding timer, if it exists
subprocess.run(['systemctl', 'disable', timer_name]) if service_file_exists(service,"timer"):
print(f"{timer_name} stopped and disabled.") timer_name = service + ".timer"
else: subprocess.run(['systemctl', 'stop', timer_name])
print(f"Skipped.") subprocess.run(['systemctl', 'disable', timer_name])
print(f"{timer_name} stopped and disabled.")
if not service_active: else:
print(f"Waiting for 5 seconds for {service} to stop...") print(f"Skipped.")
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):