guix-commits
[Top][All Lists]
Advanced

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

[shepherd] 08/08: service: Print "already running" message in 'launch-se


From: Ludovic Courtès
Subject: [shepherd] 08/08: service: Print "already running" message in 'launch-service', not 'start'.
Date: Sat, 25 Mar 2023 17:53:07 -0400 (EDT)

civodul pushed a commit to branch master
in repository shepherd.

commit 353a91bb1b4b7ff26b54d466010bdb3cf5f77b0b
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Sat Mar 25 22:47:20 2023 +0100

    service: Print "already running" message in 'launch-service', not 'start'.
    
    That way, the message gets printed when running, say, "herd start
    root" (until now that command wouldn't print anything), but it's not
    printed when starting services in parallel and possibly calling 'start'
    several times on the same service.
    
    * modules/shepherd/service.scm (start): Move "already running" message
    to...
    (launch-service): ... here.
    * tests/basic.sh: Test it.
---
 modules/shepherd/service.scm | 18 ++++++++++--------
 tests/basic.sh               |  8 ++++++++
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 5edacf1..d221eab 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -702,8 +702,6 @@ while starting ~a: ~s")
                 (match (get-message reply)
                   (#f
                    ;; We lost the race: OBJ is already running.
-                  (local-output (l10n "Service ~a is already running.")
-                                (canonical-name obj))
                    (service-running-value obj))
                   ((? channel? notification)
                    ;; We won the race: we're responsible for starting OBJ
@@ -1074,12 +1072,16 @@ Used by `start'."
     (()
      (raise (condition (&missing-service-error (name name)))))
     ((possibilities ...)
-     (or (first-running possibilities)
-
-         ;; None running yet, start one.
-         (find (lambda (service)
-                 (apply start service args))
-               possibilities)))))
+     (let ((running (first-running possibilities)))
+       (if running
+           (begin
+             (local-output (l10n "Service ~a is already running.")
+                          (canonical-name running))
+             running)
+           ;; None running yet, start one.
+           (find (lambda (service)
+                   (apply start service args))
+                 possibilities))))))
 
 ;; Starting by name.
 (define-method (start (obj <symbol>) . args)
diff --git a/tests/basic.sh b/tests/basic.sh
index 32a1279..0ad2a07 100644
--- a/tests/basic.sh
+++ b/tests/basic.sh
@@ -264,6 +264,14 @@ if $herd status | grep "Stopped:"
 then false; else true; fi
 $herd status | grep -e "+ root"
 
+# Check that the "Service * already running" message gets printed only when
+# explicitly starting an already-running service.
+if grep "already running" "$log"
+then false; else true; fi
+
+$herd start root | grep "already running"
+grep "already running" "$log"
+
 $herd stop root
 ! kill -0 $shepherd_pid
 



reply via email to

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