Check if nothing got defreezed during the freezing process

This commit is contained in:
Kevin Veen-Birkenbach 2023-12-14 17:12:42 +01:00
parent 0ba36f3671
commit 5605e0bcc3
2 changed files with 46 additions and 22 deletions

View File

@ -70,6 +70,10 @@ system_maintenance_cleanup_services:
- "cleanup-disc-space"
- "cleanup-failed-docker-backups"
### Freeze services (wait until they are finished to be sure that nobody else is doing stuff in the fridge)
- "system-maintenance-service-freeze"
- "system-maintenance-service-defrost"
### Services that Manipulate the System
system_maintenance_manipulation_services:
- "heal-docker"

View File

@ -28,12 +28,29 @@ def check_service_active(service_name):
"""Check if a service is active or activating."""
result = subprocess.run(['systemctl', 'is-active', service_name], stdout=subprocess.PIPE)
service_status = result.stdout.decode('utf-8').strip()
return service_status in ['active', 'activating']
return_value=service_status in ['active', 'activating']
if return_value:
print(f"Service {service} is active.");
else:
print(f"Service {service} is not active.");
return return_value
def check_any_service_active(services):
"""Check if any service in the list is active or activating."""
for service in services:
if check_service_active(service_name):
return True
return False
def freeze(services_to_wait_for, ignored_services, timeout_sec):
break_time_sec=5
attempt=0
max_attempts=timeout_sec/break_time_sec
any_service_active=True
print("Checking if any services is active.")
# This guaranties that no service will be started in the between time
while any_service_active:
# Filter services that exist and are not in the ignored list
for service in services_to_wait_for:
print(f"\nFreezing: {service}")
@ -55,7 +72,10 @@ def freeze(services_to_wait_for, ignored_services, timeout_sec):
subprocess.run(['systemctl', 'disable', timer_name])
print(f"{timer_name} stopped and disabled.")
else:
print(f"Skipped.")
print(f"No timer to stop.")
print("Checking if any of the previous deactivated services is active.")
any_service_active=check_any_service_active(services_to_wait_for)
print("\nAll required services have stopped.")
def defrost(services_to_wait_for, ignored_services):