Add running state indicator for systemd timers
This commit is contained in:
@@ -271,6 +271,14 @@ def get_systemd_timer_status(timer_name):
|
||||
text=True
|
||||
)
|
||||
|
||||
# Check corresponding service status
|
||||
service_name = timer_name.replace('.timer', '.service')
|
||||
service_result = subprocess.run(
|
||||
["sudo", "systemctl", "is-active", service_name],
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
|
||||
# Get next run time
|
||||
list_result = subprocess.run(
|
||||
["sudo", "systemctl", "list-timers", timer_name, "--no-legend"],
|
||||
@@ -280,6 +288,7 @@ def get_systemd_timer_status(timer_name):
|
||||
|
||||
is_active = active_result.returncode == 0
|
||||
is_enabled = enabled_result.returncode == 0
|
||||
service_status = service_result.stdout.strip() if service_result else "unknown"
|
||||
|
||||
next_run = "unknown"
|
||||
if list_result.returncode == 0 and list_result.stdout.strip():
|
||||
@@ -287,7 +296,7 @@ def get_systemd_timer_status(timer_name):
|
||||
if len(parts) >= 4:
|
||||
next_run = f"{parts[0]} {parts[1]} {parts[2]}"
|
||||
|
||||
return is_active, is_enabled, next_run
|
||||
return is_active, is_enabled, next_run, service_status
|
||||
|
||||
|
||||
def cmd_list(args):
|
||||
@@ -328,10 +337,14 @@ def cmd_list(args):
|
||||
systemd_timers = ["borg-backup.timer", "borg-local-sync.timer", "dynamic-dns.timer"]
|
||||
|
||||
for timer in systemd_timers:
|
||||
is_active, is_enabled, next_run = get_systemd_timer_status(timer)
|
||||
is_active, is_enabled, next_run, service_status = get_systemd_timer_status(timer)
|
||||
service_name = timer.replace('.timer', '')
|
||||
|
||||
if is_active and is_enabled:
|
||||
if service_status in ["activating", "active"]:
|
||||
# Service is currently running
|
||||
status = f"[🔄 RUNNING - next: {next_run}]"
|
||||
color = "yellow"
|
||||
elif is_active and is_enabled:
|
||||
status = f"[TIMER ACTIVE - next: {next_run}]"
|
||||
color = "green"
|
||||
elif is_enabled:
|
||||
|
Reference in New Issue
Block a user