guix-commits
[Top][All Lists]
Advanced

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

[shepherd] 22/32: service: Add 'start-in-the-background'.


From: Ludovic Courtès
Subject: [shepherd] 22/32: service: Add 'start-in-the-background'.
Date: Wed, 30 Mar 2022 11:01:32 -0400 (EDT)

civodul pushed a commit to branch master
in repository shepherd.

commit 162ef85e40e8b5548c9176006c6c6ea37286ecad
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Sun Mar 27 22:21:45 2022 +0200

    service: Add 'start-in-the-background'.
    
    * modules/shepherd/service.scm (start-in-the-background): New procedure.
    * doc/shepherd.texi (Service Convenience): Document it.
---
 doc/shepherd.texi            |  9 +++++++++
 modules/shepherd/service.scm | 18 ++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/doc/shepherd.texi b/doc/shepherd.texi
index 948ea55..2785bb2 100644
--- a/doc/shepherd.texi
+++ b/doc/shepherd.texi
@@ -861,6 +861,15 @@ current value of the @code{running} slot of the service.
 Start a registered service providing @var{obj}.
 @end deffn
 
+@deffn {procedure} start-in-the-background @var{services}
+Start the services named by @var{services}, a list of symbols, in the
+background.  In other words, this procedure returns immediately without
+waiting until all of @var{services} have been started.
+
+This procedure can be useful in a configuration file because it lets you
+interact right away with shepherd using the @command{herd} command.
+@end deffn
+
 @deffn {method} stop (obj <symbol>)
 Stop a registered service providing @var{obj}.
 @end deffn
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index d7c42b0..84c9a8b 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -58,6 +58,7 @@
             enable
             disable
             start
+            start-in-the-background
             stop
             action
             enforce
@@ -678,6 +679,23 @@ results."
                (apply action service the-action args))
              which-services))))
 
+(define (start-in-the-background services)
+  "Start the services named by @var{services}, a list of symbols, in the
+background.  In other words, this procedure returns immediately without
+waiting until all of @var{services} have been started.
+
+This procedure can be useful in a configuration file because it lets you
+interact right away with shepherd using the @command{herd} command."
+  (spawn-fiber
+   (lambda ()
+     (for-each (lambda (service)
+                 ;; Keep going if one of SERVICES fails to start.
+                 (guard (c ((service-error? c)
+                            (local-output
+                             (l10n "Failed to start ~a in the background.")
+                             service)))
+                   (start service)))
+               services))))
 
 
 



reply via email to

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