guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[shepherd] 05/06: service: Communicate recently-logged messages to clien


From: Ludovic Courtès
Subject: [shepherd] 05/06: service: Communicate recently-logged messages to clients.
Date: Sun, 17 Dec 2023 17:06:22 -0500 (EST)

civodul pushed a commit to branch devel
in repository shepherd.

commit 62aaa48a9da8891d9a15859665895f72903cf1c8
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Mon Dec 4 23:32:22 2023 +0100

    service: Communicate recently-logged messages to clients.
    
    * modules/shepherd/service.scm (service-recent-messages): New procedure.
    (service->sexp): Use it and emit ‘recent-messages’ field.
    * tests/status-sexp.sh: Adjust accordingly.
    * doc/shepherd.texi (Interacting with Services): Document
    ‘service-recent-messages’.
---
 doc/shepherd.texi            |  7 +++++++
 modules/shepherd/service.scm |  8 +++++++-
 tests/status-sexp.sh         | 12 ++++++++----
 3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/doc/shepherd.texi b/doc/shepherd.texi
index aca3a57..51302e7 100644
--- a/doc/shepherd.texi
+++ b/doc/shepherd.texi
@@ -1021,6 +1021,13 @@ The replacement is the service that will replace 
@var{service} when it
 is eventually stopped.
 @end deffn
 
+@deffn {Procedure} service-recent-messages @var{service}
+Return a list of messages recently logged by @var{service}---typically
+lines written by a daemon on standard output.  Each element of the list
+is a timestamp/string pair where the timestamp is the number of seconds
+since January 1st, 1970 (an integer).
+@end deffn
+
 @xref{Service Internals}, if you're curious about the nitty-gritty
 details!
 
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 2cc5405..9aaa08c 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -70,6 +70,7 @@
             service-startup-failures
             service-status-changes
             service-replacement
+            service-recent-messages
             service-action-list
             lookup-service-action
             service-defines-action?
@@ -782,6 +783,10 @@ channel and wait for its reply."
   ;; Return the replacement of @var{service}, #f if there is none.
   (service-control-message 'replacement))
 
+(define service-recent-messages
+  ;; Return the list of recent messages logged for @var{service}.
+  (service-control-message 'recent-messages))
+
 (define (enable-service service)
   "Enable @var{service}."
   (put-message (service-control service) 'enable))
@@ -1106,7 +1111,8 @@ clients."
             (one-shot? ,(one-shot-service? service))
             (transient? ,(transient-service? service))
             (respawn-limit ,(service-respawn-limit service))
-            (respawn-delay ,(service-respawn-delay service))))
+            (respawn-delay ,(service-respawn-delay service))
+            (recent-messages ,(service-recent-messages service))))
 
 
 ;;;
diff --git a/tests/status-sexp.sh b/tests/status-sexp.sh
index 7c6ad1c..22f8136 100644
--- a/tests/status-sexp.sh
+++ b/tests/status-sexp.sh
@@ -81,7 +81,8 @@ root_service_sexp="
       (one-shot? #f)
       (transient? #f)
       (respawn-limit (5 . 7))
-      (respawn-delay 0.1))"
+      (respawn-delay 0.1)
+      (recent-messages ()))"
 
 # Define a helper procedure that resets timestamps in the 'status-changes'
 # property to make it easier to compare them.
@@ -121,7 +122,8 @@ $define_reset_timestamps
                (startup-failures ())
                (status running)
                (one-shot? #f) (transient? #f)
-               (respawn-limit (5 . 7)) (respawn-delay 1))
+               (respawn-limit (5 . 7)) (respawn-delay 1)
+              (recent-messages ()))
              (service (version 0)
                (provides (bar)) (requires (foo))
                (respawn? #f) (docstring \"Bar!\")
@@ -131,7 +133,8 @@ $define_reset_timestamps
                (startup-failures ())
                (status stopped)
                (one-shot? #f) (transient? #f)
-               (respawn-limit (5 . 7)) (respawn-delay 1)))))))
+               (respawn-limit (5 . 7)) (respawn-delay 1)
+               (recent-messages ())))))))
 "
 
 # The 'start' command should return the service sexp on success.
@@ -159,7 +162,8 @@ $define_reset_timestamps
                (startup-failures ())
                (status running)
                (one-shot? #f) (transient? #f)
-               (respawn-limit (5 . 7)) (respawn-delay 1))))))
+               (respawn-limit (5 . 7)) (respawn-delay 1)
+              (recent-messages ()))))))
 "
 
 # Make sure we get an 'error' sexp when querying a nonexistent service.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]