mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2024-11-22 12:41:05 +01:00
Check if nothing got defreezed during the freezing process
This commit is contained in:
parent
f279c7000b
commit
f73ea74cd5
@ -70,6 +70,10 @@ system_maintenance_cleanup_services:
|
|||||||
- "cleanup-disc-space"
|
- "cleanup-disc-space"
|
||||||
- "cleanup-failed-docker-backups"
|
- "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
|
### Services that Manipulate the System
|
||||||
system_maintenance_manipulation_services:
|
system_maintenance_manipulation_services:
|
||||||
- "heal-docker"
|
- "heal-docker"
|
||||||
|
@ -28,12 +28,29 @@ def check_service_active(service_name):
|
|||||||
"""Check if a service is active or activating."""
|
"""Check if a service is active or activating."""
|
||||||
result = subprocess.run(['systemctl', 'is-active', service_name], stdout=subprocess.PIPE)
|
result = subprocess.run(['systemctl', 'is-active', service_name], stdout=subprocess.PIPE)
|
||||||
service_status = result.stdout.decode('utf-8').strip()
|
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):
|
def freeze(services_to_wait_for, ignored_services, timeout_sec):
|
||||||
break_time_sec=5
|
break_time_sec=5
|
||||||
attempt=0
|
attempt=0
|
||||||
max_attempts=timeout_sec/break_time_sec
|
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
|
# 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:
|
||||||
print(f"\nFreezing: {service}")
|
print(f"\nFreezing: {service}")
|
||||||
@ -55,7 +72,10 @@ def freeze(services_to_wait_for, ignored_services, timeout_sec):
|
|||||||
subprocess.run(['systemctl', 'disable', timer_name])
|
subprocess.run(['systemctl', 'disable', timer_name])
|
||||||
print(f"{timer_name} stopped and disabled.")
|
print(f"{timer_name} stopped and disabled.")
|
||||||
else:
|
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.")
|
print("\nAll required services have stopped.")
|
||||||
|
|
||||||
def defrost(services_to_wait_for, ignored_services):
|
def defrost(services_to_wait_for, ignored_services):
|
||||||
|
Loading…
Reference in New Issue
Block a user