guix-commits
[Top][All Lists]
Advanced

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

[shepherd] 02/04: service: 'daemonize' action does nothing when services


From: Ludovic Courtès
Subject: [shepherd] 02/04: service: 'daemonize' action does nothing when services are already running.
Date: Sat, 2 Apr 2022 11:23:35 -0400 (EDT)

civodul pushed a commit to branch master
in repository shepherd.

commit 3197c1c161d10b7f76771a2943f20fdafc5cc14a
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Thu Mar 31 11:40:05 2022 +0200

    service: 'daemonize' action does nothing when services are already running.
    
    * modules/shepherd/service.scm (root-service): In 'daemonize' action, do
    nothing if services other than ROOT-SERVICE are already running.
---
 modules/shepherd/service.scm | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 14d5d2e..90cccd6 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -2018,15 +2018,22 @@ if previously spawned children terminate.  Therefore, 
this action should
 usually only be used (if at all) *before* children get spawned for which
 we want to receive these signals."
       (lambda (running)
-        (case (getpid)
-          ((1)
-           (local-output (l10n "Running as PID 1, so not daemonizing.")))
-          (else
-           (if (zero? (primitive-fork))
-               (begin
-                 (catch-system-error (prctl PR_SET_CHILD_SUBREAPER 1))
-                 #t)
-               (primitive-exit 0))))))
+        (cond ((= 1 (getpid))
+               (local-output (l10n "Running as PID 1, so not daemonizing.")))
+              ((fold-services (lambda (service found?)
+                                (or found?
+                                    (and (running? service)
+                                         (not (eq? service root-service)))))
+                              #f)
+               (local-output
+                (l10n "Services already running, so not daemonizing."))
+               #f)
+              (else
+               (if (zero? (primitive-fork))
+                   (begin
+                     (catch-system-error (prctl PR_SET_CHILD_SUBREAPER 1))
+                     #t)
+                   (primitive-exit 0))))))
      (persistency
       "Save the current state of running and non-running services.
 This status gets written into a file on termination, so that we can



reply via email to

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