Add running state indicator for systemd timers
This commit is contained in:
@@ -24,7 +24,13 @@ def show_timer_status(timer_name, system_level=True):
|
||||
# Get timer status
|
||||
status_cmd = f"{cmd_prefix} is-active {timer_name}"
|
||||
status_result = run_command(status_cmd)
|
||||
status = "active" if status_result and status_result.returncode == 0 else "inactive"
|
||||
timer_status = "active" if status_result and status_result.returncode == 0 else "inactive"
|
||||
|
||||
# Get corresponding service status
|
||||
service_name = timer_name.replace('.timer', '.service')
|
||||
service_cmd = f"{cmd_prefix} is-active {service_name}"
|
||||
service_result = run_command(service_cmd)
|
||||
service_status = service_result.stdout.strip() if service_result else "unknown"
|
||||
|
||||
# Get next run time
|
||||
list_cmd = f"{cmd_prefix} list-timers {timer_name} --no-legend"
|
||||
@@ -36,14 +42,26 @@ def show_timer_status(timer_name, system_level=True):
|
||||
if len(parts) >= 4:
|
||||
next_run = f"{parts[0]} {parts[1]} {parts[2]} ({parts[3]})"
|
||||
|
||||
# Get service name
|
||||
service_name = timer_name.replace('.timer', '.service')
|
||||
|
||||
# Format output
|
||||
status_color = "green" if status == "active" else "red"
|
||||
# Format output based on service status
|
||||
service_short = service_name.replace('.service', '')
|
||||
|
||||
printfe(status_color, f"● {service_short:<12} {status:<8} next: {next_run}")
|
||||
if service_status in ["activating", "active"]:
|
||||
# Service is currently running
|
||||
status_color = "yellow"
|
||||
status_text = f"RUNNING next: {next_run}"
|
||||
symbol = "🔄"
|
||||
elif timer_status == "active":
|
||||
# Timer is active but service is not running
|
||||
status_color = "green"
|
||||
status_text = f"active next: {next_run}"
|
||||
symbol = "●"
|
||||
else:
|
||||
# Timer is inactive
|
||||
status_color = "red"
|
||||
status_text = f"inactive next: {next_run}"
|
||||
symbol = "●"
|
||||
|
||||
printfe(status_color, f"{symbol} {service_short:<12} {status_text}")
|
||||
|
||||
def show_examples():
|
||||
"""Show example commands for checking services and logs"""
|
||||
@@ -52,17 +70,21 @@ def show_examples():
|
||||
|
||||
printfe("yellow", "Check service status:")
|
||||
print(" sudo systemctl status borg-backup.service")
|
||||
print(" sudo systemctl status borg-local-sync.service")
|
||||
print(" sudo systemctl status dynamic-dns.service")
|
||||
print()
|
||||
|
||||
printfe("yellow", "View logs:")
|
||||
print(" sudo journalctl -u borg-backup.service -f")
|
||||
print(" sudo journalctl -u borg-local-sync.service -f")
|
||||
print(" sudo journalctl -u dynamic-dns.service -f")
|
||||
print(" tail -f /var/log/borg-backup.log")
|
||||
print(" tail -f /var/log/borg-local-sync.log")
|
||||
print()
|
||||
|
||||
printfe("yellow", "Manual trigger:")
|
||||
print(" sudo systemctl start borg-backup.service")
|
||||
print(" sudo systemctl start borg-local-sync.service")
|
||||
print(" sudo systemctl start dynamic-dns.service")
|
||||
print()
|
||||
|
||||
|
Reference in New Issue
Block a user