feat: adds borg, timers and systemd service support
This commit is contained in:
@@ -255,8 +255,44 @@ def check_service_running(service_name):
|
||||
return len(containers)
|
||||
|
||||
|
||||
def get_systemd_timer_status(timer_name):
|
||||
"""Check if a systemd timer is active and enabled, and get next run time"""
|
||||
# Check if timer is active (running/waiting)
|
||||
active_result = subprocess.run(
|
||||
["sudo", "systemctl", "is-active", timer_name],
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
|
||||
# Check if timer is enabled (will start on boot)
|
||||
enabled_result = subprocess.run(
|
||||
["sudo", "systemctl", "is-enabled", timer_name],
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
|
||||
# Get next run time
|
||||
list_result = subprocess.run(
|
||||
["sudo", "systemctl", "list-timers", timer_name, "--no-legend"],
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
|
||||
is_active = active_result.returncode == 0
|
||||
is_enabled = enabled_result.returncode == 0
|
||||
|
||||
next_run = "unknown"
|
||||
if list_result.returncode == 0 and list_result.stdout.strip():
|
||||
parts = list_result.stdout.strip().split()
|
||||
if len(parts) >= 4:
|
||||
next_run = f"{parts[0]} {parts[1]} {parts[2]}"
|
||||
|
||||
return is_active, is_enabled, next_run
|
||||
|
||||
|
||||
def cmd_list(args):
|
||||
"""List available Docker services"""
|
||||
"""List available Docker services and systemd services"""
|
||||
# Docker services section
|
||||
if not os.path.exists(SERVICES_DIR):
|
||||
printfe("red", f"Error: Services directory not found at {SERVICES_DIR}")
|
||||
return 1
|
||||
@@ -270,21 +306,42 @@ def cmd_list(args):
|
||||
|
||||
if not services:
|
||||
printfe("yellow", "No Docker services found")
|
||||
return 0
|
||||
else:
|
||||
println("Available Docker services:", "blue")
|
||||
for service in sorted(services):
|
||||
container_count = check_service_running(service)
|
||||
is_running = container_count > 0
|
||||
|
||||
println("Available Docker services:", "blue")
|
||||
for service in sorted(services):
|
||||
container_count = check_service_running(service)
|
||||
is_running = container_count > 0
|
||||
if is_running:
|
||||
status = f"[RUNNING - {container_count} container{'s' if container_count > 1 else ''}]"
|
||||
color = "green"
|
||||
else:
|
||||
status = "[STOPPED]"
|
||||
color = "red"
|
||||
|
||||
if is_running:
|
||||
status = f"[RUNNING - {container_count} container{'s' if container_count > 1 else ''}]"
|
||||
printfe(color, f" - {service:<20} {status}")
|
||||
|
||||
# Systemd services section
|
||||
print()
|
||||
println("System services:", "blue")
|
||||
|
||||
systemd_timers = ["borg-backup.timer", "dynamic-dns.timer"]
|
||||
|
||||
for timer in systemd_timers:
|
||||
is_active, is_enabled, next_run = get_systemd_timer_status(timer)
|
||||
service_name = timer.replace('.timer', '')
|
||||
|
||||
if is_active and is_enabled:
|
||||
status = f"[TIMER ACTIVE - next: {next_run}]"
|
||||
color = "green"
|
||||
elif is_enabled:
|
||||
status = "[TIMER ENABLED - INACTIVE]"
|
||||
color = "yellow"
|
||||
else:
|
||||
status = "[STOPPED]"
|
||||
status = "[TIMER DISABLED]"
|
||||
color = "red"
|
||||
|
||||
printfe(color, f" - {service:<20} {status}")
|
||||
printfe(color, f" - {service_name:<20} {status}")
|
||||
|
||||
return 0
|
||||
|
||||
|
Reference in New Issue
Block a user