guix-commits
[Top][All Lists]
Advanced

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

[shepherd] 01/05: timer: Add #:log-file to ‘make-timer-constructor’.


From: Ludovic Courtès
Subject: [shepherd] 01/05: timer: Add #:log-file to ‘make-timer-constructor’.
Date: Thu, 28 Mar 2024 15:39:07 -0400 (EDT)

civodul pushed a commit to branch devel
in repository shepherd.

commit 35f8d5e220ef674a83a7e09a10d7cf8e0f5fbea2
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Mon Mar 25 14:53:11 2024 +0100

    timer: Add #:log-file to ‘make-timer-constructor’.
    
    * modules/shepherd/service/timer.scm (make-timer-constructor):
    Add #:log-file and pass it to ‘start-command’.
    * tests/services/timer.sh: Test it.
    * doc/shepherd.texi (Timers): Document it.
---
 doc/shepherd.texi                  | 3 +++
 modules/shepherd/service/timer.scm | 7 ++++++-
 tests/services/timer.sh            | 9 ++++++---
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/doc/shepherd.texi b/doc/shepherd.texi
index 5274fb0..ca7e755 100644
--- a/doc/shepherd.texi
+++ b/doc/shepherd.texi
@@ -1469,6 +1469,9 @@ calendar event as returned by @code{calendar-event}.  
@var{action} may be
 either a command (returned by @code{command}) or a thunk; in the latter case,
 the thunk must be suspendable or it could block the whole shepherd process.
 
+When @var{log-file} is true, log the output of @var{action} to that file
+rather than in the global shepherd log.
+
 When @var{wait-for-termination?} is true, wait until @var{action} has finished
 before considering executing it again; otherwise, perform @var{action}
 strictly on every occurrence of @var{event}, at the risk of having multiple
diff --git a/modules/shepherd/service/timer.scm 
b/modules/shepherd/service/timer.scm
index 5eeb3de..068a93f 100644
--- a/modules/shepherd/service/timer.scm
+++ b/modules/shepherd/service/timer.scm
@@ -394,13 +394,17 @@ list, to be executed as @var{user} and @var{group}, with 
the given
 (define sleep (@ (fibers) sleep))
 
 (define* (make-timer-constructor event action
-                                 #:key wait-for-termination?)
+                                 #:key log-file
+                                 wait-for-termination?)
   "Return a procedure for use as the @code{start} method of a service.  The
 procedure will perform @var{action} at every occurrence of @code{event}, a
 calendar event as returned by @code{calendar-event}.  @var{action} may be
 either a command (returned by @code{command}) or a thunk; in the latter case,
 the thunk must be suspendable or it could block the whole shepherd process.
 
+When @var{log-file} is true, log the output of @var{action} to that file
+rather than in the global shepherd log.
+
 When @var{wait-for-termination?} is true, wait until @var{action} has finished
 before considering executing it again; otherwise, perform @var{action}
 strictly on every occurrence of @var{event}, at the risk of having multiple
@@ -450,6 +454,7 @@ instances running concurrently."
               (if (command? action)
                   (let ((pid status (start-command
                                      (command-arguments action)
+                                     #:log-file log-file
                                      #:user (command-user action)
                                      #:group (command-group action)
                                      #:environment-variables
diff --git a/tests/services/timer.sh b/tests/services/timer.sh
index 023c111..a4bb165 100644
--- a/tests/services/timer.sh
+++ b/tests/services/timer.sh
@@ -24,10 +24,11 @@ conf="t-conf-$$"
 log="t-log-$$"
 pid="t-pid-$$"
 service_pid="t-service-pid-$$"
+service_log="t-service-log-$$"
 
 herd="herd -s $socket"
 
-trap "cat $log || true; rm -f $socket $conf $log $service_pid;
+trap "cat $log || true; rm -f $socket $conf $log $service_pid $service_log;
       test -f $pid && kill \`cat $pid\` || true; rm -f $pid" EXIT
 
 cat > "$conf" <<EOF
@@ -40,7 +41,8 @@ cat > "$conf" <<EOF
   (list (service '(timer-with-command)
                 #:start (make-timer-constructor
                          (calendar-event #:seconds (iota 60))
-                         (command '("sh" "-c" "echo Hi from \$PWD.")))
+                         (command '("sh" "-c" "echo Hi from \$PWD."))
+                          #:log-file "$service_log")
                 #:stop (make-timer-destructor))
         (service '(timer-with-procedure)
                  #:start (make-timer-constructor
@@ -78,7 +80,8 @@ shepherd_pid="`cat $pid`"
 
 $herd start timer-with-command
 sleep 2
-grep "Hi from " "$log"
+grep "Hi from " "$service_log"
+$herd status timer-with-command | grep "Log file: $service_log"
 $herd status timer-with-command | grep "Hi from " # recent messages
 $herd status timer-with-command | grep "exited successfully" # recent runs
 $herd stop timer-with-command



reply via email to

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