civodul pushed a commit to branch devel
in repository shepherd.

commit 8288d3e785b3e97833aba434b58dc963b2cfd662
Author: Ludovic Courtès <l...@gnu.org>
AuthorDate: Sat Sep 7 17:31:19 2024 +0200

    herd: ‘herd status SERVICE’ shows the service’s list of custom actions.
    
    * modules/shepherd/scripts/herd.scm (<live-service>)[actions]: New field.
    (sexp->live-service): Initialize it.
    (display-service-status): Display the list of actions when non-empty.
    * tests/basic.sh: Test it.
---
 modules/shepherd/scripts/herd.scm | 14 +++++++++++---
 tests/basic.sh                    |  5 +++++
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/modules/shepherd/scripts/herd.scm 
b/modules/shepherd/scripts/herd.scm
index 80e18c3..04de40a 100644
--- a/modules/shepherd/scripts/herd.scm
+++ b/modules/shepherd/scripts/herd.scm
@@ -43,7 +43,7 @@
 
 ;; Information about live services.
 (define-record-type <live-service>
-  (live-service provision requirement one-shot? transient? respawn?
+  (live-service provision requirement one-shot? transient? respawn? actions
                 enabled? status running
                 status-changes last-respawns startup-failures
                 exit-statuses
@@ -55,6 +55,7 @@
   (one-shot?        live-service-one-shot?)       ;Boolean
   (transient?       live-service-transient?)      ;Boolean
   (respawn?         live-service-respawn?)        ;Boolean
+  (actions          live-service-actions)         ;list of symbols
 
   (enabled?         live-service-enabled?)         ;Boolean
   (status           live-service-status)           ;symbol
@@ -115,13 +116,14 @@ of pairs."
 into a @code{live-service} record."
   (match sexp
     (('service ('version 0 _ ...) properties ...)
-     (alist-let* properties (provides requires status running respawn? enabled?
+     (alist-let* properties (provides requires status running respawn?
+                             actions enabled?
                              status-changes last-respawns startup-failures
                              exit-statuses
                              recent-messages log-files
                              one-shot? transient? pending-replacement?)
        (live-service provides requires one-shot?
-                     transient? respawn?
+                     transient? respawn? (or actions '())
 
                      enabled?
                      (or status (if running 'running 'stopped))
@@ -509,6 +511,12 @@ calendar event."
   (unless (null? (live-service-requirement service))
     (format #t (l10n "  Requires:~{ ~a~}~%")
             (live-service-requirement service)))
+  (unless (null? (live-service-actions service))
+    (format #t (l10n "  Custom action:~{ ~a~}~%"
+                     "  Custom actions:~{ ~a~}~%"
+                     (length (live-service-actions service)))
+            (live-service-actions service)))
+
   (when (live-service-pending-replacement? service)
     (format #t (highlight/warn (l10n "  Replacement pending (restart \
 to upgrade).~%"))))
diff --git a/tests/basic.sh b/tests/basic.sh
index 23a1444..71e09cd 100644
--- a/tests/basic.sh
+++ b/tests/basic.sh
@@ -93,6 +93,11 @@ $herd status root | grep "PID: $(cat "$pid")"
 # The "Recent messages" bit should contain that phrase.
 $herd status root | grep "Service root started"
 
+# The "Custom actions" bit should list these and more.
+$herd status root | grep "actions: .*eval"
+$herd status root | grep "actions: .*load"
+$herd status root | grep "actions: .*halt"
+
 $herd graph | grep '"test-2" -> "test"'
 
 $herd start test

Reply via email to