[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 16/16: service: Add 'start-in-the-background'.
From: |
Ludovic Courtès |
Subject: |
[shepherd] 16/16: service: Add 'start-in-the-background'. |
Date: |
Sun, 27 Mar 2022 17:08:30 -0400 (EDT) |
civodul pushed a commit to branch wip-fibers
in repository shepherd.
commit 4ef79ea1889ad7077005894b4d05b0862647df90
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 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))))
- [shepherd] 06/16: service: 'read-pid-file' no longer blocks., (continued)
- [shepherd] 06/16: service: 'read-pid-file' no longer blocks., Ludovic Courtès, 2022/03/27
- [shepherd] 04/16: build: Capture the source and object directories of Fibers., Ludovic Courtès, 2022/03/27
- [shepherd] 09/16: service: 'make-forkexec-constructor' spawns a logging fiber., Ludovic Courtès, 2022/03/27
- [shepherd] 01/16: shepherd: Factorize out the main loop., Ludovic Courtès, 2022/03/27
- [shepherd] 07/16: service: 'read-pid-file' uses (@ (guile) sleep) when it's not suspendable., Ludovic Courtès, 2022/03/27
- [shepherd] 03/16: Use Fibers., Ludovic Courtès, 2022/03/27
- [shepherd] 05/16: shepherd: Use one fiber for signal handling, and one for clients., Ludovic Courtès, 2022/03/27
- [shepherd] 10/16: doc: Fix inetutils cross-reference., Ludovic Courtès, 2022/03/27
- [shepherd] 11/16: service: Remove unused 'make-init.d-service'., Ludovic Courtès, 2022/03/27
- [shepherd] 14/16: service: Allow 'running' value to be a thunk., Ludovic Courtès, 2022/03/27
- [shepherd] 16/16: service: Add 'start-in-the-background'.,
Ludovic Courtès <=