civodul pushed a commit to branch wip-fibers
in repository shepherd.
commit 4ef79ea1889ad7077005894b4d05b0862647df90
Author: Ludovic Courtès <[email protected]>
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 fbda56b..8be7dc2 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 aa12461..db482f8 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
@@ -675,6 +676,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))))