GNU bug report logs -
#71739
[PATCH] services: shepherd: Support “free-form” services.
Previous Next
Reported by: Ludovic Courtès <ludo <at> gnu.org>
Date: Sun, 23 Jun 2024 21:59:02 UTC
Severity: normal
Tags: patch
Done: Ludovic Courtès <ludo <at> gnu.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 71739 in the body.
You can then email your comments to 71739 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
pelzflorian <at> pelzflorian.de, ludo <at> gnu.org, matt <at> excalamus.com, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
:
bug#71739
; Package
guix-patches
.
(Sun, 23 Jun 2024 21:59:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Ludovic Courtès <ludo <at> gnu.org>
:
New bug report received and forwarded. Copy sent to
pelzflorian <at> pelzflorian.de, ludo <at> gnu.org, matt <at> excalamus.com, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
.
(Sun, 23 Jun 2024 21:59:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
* gnu/services/shepherd.scm (<shepherd-service>)[free-form]: New field.
[start]: Add default value.
(shepherd-service-file): Rename to…
(shepherd-service-file/regular): … this.
(shepherd-service-file/free-form): New procedure.
(shepherd-service-file): Dispatch to one of the two procedures above.
* doc/guix.texi (Shepherd Services): Document the ‘free-form’ field.
Change-Id: I206374e950ef6d1e4a996c0f507fb5fcd9cadde3
---
doc/guix.texi | 26 +++++++++++++++++++++++++-
gnu/services/shepherd.scm | 25 ++++++++++++++++++++++---
2 files changed, 47 insertions(+), 4 deletions(-)
Hi!
This patch fixes a limitation that became apparent with Shepherd 0.10,
where users could not instantiate services from the built-in service
collection for which they do not explicitly specify the ‘start’
and ‘stop’ methods (see REPL service example below).
Thoughts?
Ludo’.
diff --git a/doc/guix.texi b/doc/guix.texi
index 0102fd0fad3..4d9145445cc 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -43909,7 +43909,7 @@ Shepherd Services
When true, this is the delay in seconds before restarting a failed
service.
-@item @code{start}
+@item @code{start} (default: @code{#~(const #t)})
@itemx @code{stop} (default: @code{#~(const #f)})
The @code{start} and @code{stop} fields refer to the Shepherd's
facilities to start and stop processes (@pxref{Service De- and
@@ -43928,6 +43928,30 @@ Shepherd Services
herd @var{action} @var{service} [@var{arguments}@dots{}]
@end example
+@item @code{free-form} (default: @code{#f})
+When set, this field replaces the @code{start}, @code{stop}, and
+@code{actions} fields. It is meant to be used when the service
+definition comes from some other source, typically the service
+collection provided by the Shepherd proper (@pxref{Service Collection,,,
+shepherd, The GNU Shepherd Manual}).
+
+@cindex REPL service, for shepherd
+For example, the snippet below defines a service for the Shepherd's
+built-in @acronym{REPL, read-eval-print loop} service (@pxref{REPL
+Service,,, shepherd, The GNU Shepherd Manual}):
+
+@lisp
+(shepherd-service
+ (provision '(repl))
+ (modules '((shepherd service repl)))
+ (free-form #~(repl-service)))
+@end lisp
+
+In this case, the service object is returned by the @code{repl-service}
+procedure of the Shepherd, so all the @code{free-form} G-expression does
+is call that procedure. Note that the @code{provision} field must be
+consistent with the actual service provision.
+
@item @code{auto-start?} (default: @code{#t})
Whether this service should be started automatically by the Shepherd. If it
is @code{#f} the service has to be started manually with @code{herd start}.
diff --git a/gnu/services/shepherd.scm b/gnu/services/shepherd.scm
index ccc8e61a33c..05534ab3173 100644
--- a/gnu/services/shepherd.scm
+++ b/gnu/services/shepherd.scm
@@ -60,6 +60,7 @@ (define-module (gnu services shepherd)
shepherd-service-respawn?
shepherd-service-start
shepherd-service-stop
+ shepherd-service-free-form
shepherd-service-auto-start?
shepherd-service-modules
@@ -217,7 +218,10 @@ (define-record-type* <shepherd-service>
(default #f))
(respawn-delay shepherd-service-respawn-delay
(default #f))
- (start shepherd-service-start) ;g-expression (procedure)
+ (free-form shepherd-service-free-form ;#f | g-expression (service)
+ (default #f))
+ (start shepherd-service-start ;g-expression (procedure)
+ (default #~(const #t)))
(stop shepherd-service-stop ;g-expression (procedure)
(default #~(const #f)))
(actions shepherd-service-actions ;list of <shepherd-action>
@@ -298,8 +302,8 @@ (define (shepherd-service-file-name service)
provisions)
".scm")))
-(define (shepherd-service-file service)
- "Return a file defining SERVICE."
+(define (shepherd-service-file/regular service)
+ "Return a file defining SERVICE, a service whose 'free-form' field is #f."
(scheme-file (shepherd-service-file-name service)
(with-imported-modules %default-imported-modules
#~(begin
@@ -332,6 +336,21 @@ (define (shepherd-service-file service)
#~(#$name #$doc #$proc)))
(shepherd-service-actions service))))))))
+(define (shepherd-service-file/free-form service)
+ "Return a file defining SERVICE, a service whose 'free-form' field is set."
+ (scheme-file (shepherd-service-file-name service)
+ (with-imported-modules %default-imported-modules
+ #~(begin
+ (use-modules #$@(shepherd-service-modules service))
+
+ #$(shepherd-service-free-form service)))))
+
+(define (shepherd-service-file service)
+ "Return a file defining SERVICE."
+ (if (shepherd-service-free-form service)
+ (shepherd-service-file/free-form service)
+ (shepherd-service-file/regular service)))
+
(define (scm->go file shepherd)
"Compile FILE, which contains code to be loaded by shepherd's config file,
and return the resulting '.go' file. SHEPHERD is used as shepherd package."
base-commit: 2aeb37def258ad4dd23aaf57ed32f0be44d1bea5
--
2.45.1
Information forwarded
to
guix-patches <at> gnu.org
:
bug#71739
; Package
guix-patches
.
(Mon, 24 Jun 2024 13:08:03 GMT)
Full text and
rfc822 format available.
Message #8 received at 71739 <at> debbugs.gnu.org (full text, mbox):
Hi Maxim,
(Cc’ing 71739, which is actually the right one. :-))
Maxim Cournoyer <maxim.cournoyer <at> gmail.com> skribis:
> Ludovic Courtès <ludo <at> gnu.org> writes:
[...]
>> +@item @code{free-form} (default: @code{#f})
>> +When set, this field replaces the @code{start}, @code{stop}, and
>> +@code{actions} fields. It is meant to be used when the service
>> +definition comes from some other source, typically the service
>> +collection provided by the Shepherd proper (@pxref{Service Collection,,,
>> +shepherd, The GNU Shepherd Manual}).
>> +
>> +@cindex REPL service, for shepherd
>> +For example, the snippet below defines a service for the Shepherd's
>> +built-in @acronym{REPL, read-eval-print loop} service (@pxref{REPL
>> +Service,,, shepherd, The GNU Shepherd Manual}):
>> +
>> +@lisp
>> +(shepherd-service
>> + (provision '(repl))
>> + (modules '((shepherd service repl)))
>> + (free-form #~(repl-service)))
>> +@end lisp
[...]
> Hm, if free-form is expected to be a built-in procedure provided by
> Shepherd, should we call it 'built-in' instead of 'free-form' ?
I view it as something more generic: it’s typically, but not just, for
when the service comes from a procedure defined in the Shepherd itself.
Other use case is when as a service author you need more freedom that
what you get with the ‘start’ and ‘stop’ fields, like:
(shepherd-service
;; …
(free-from #~(let ((whatever (spawn-fiber …)))
(service '(foo) #:start …))))
It’s probably going to be a relatively marginal use case, but it’s good
to have that extra level of flexibility.
WDYT?
Thanks!
Ludo’.
Information forwarded
to
guix-patches <at> gnu.org
:
bug#71739
; Package
guix-patches
.
(Tue, 25 Jun 2024 03:24:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 71739 <at> debbugs.gnu.org (full text, mbox):
Hi Ludovic,
Ludovic Courtès <ludo <at> gnu.org> writes:
[...]
>> Hm, if free-form is expected to be a built-in procedure provided by
>> Shepherd, should we call it 'built-in' instead of 'free-form' ?
>
> I view it as something more generic: it’s typically, but not just, for
> when the service comes from a procedure defined in the Shepherd itself.
>
> Other use case is when as a service author you need more freedom that
> what you get with the ‘start’ and ‘stop’ fields, like:
>
> (shepherd-service
> ;; …
> (free-from #~(let ((whatever (spawn-fiber …)))
> (service '(foo) #:start …))))
>
> It’s probably going to be a relatively marginal use case, but it’s good
> to have that extra level of flexibility.
>
> WDYT?
Thanks for the extra explanation and example. The extra flexibility
sounds good to me!
Reviewed-by: Maxim Cournoyer <maxim.cournoyer <at> gmail>
--
Thanks,
Maxim
Reply sent
to
Ludovic Courtès <ludo <at> gnu.org>
:
You have taken responsibility.
(Wed, 26 Jun 2024 22:22:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Ludovic Courtès <ludo <at> gnu.org>
:
bug acknowledged by developer.
(Wed, 26 Jun 2024 22:22:03 GMT)
Full text and
rfc822 format available.
Message #16 received at 71739-done <at> debbugs.gnu.org (full text, mbox):
Maxim Cournoyer <maxim.cournoyer <at> gmail.com> skribis:
> Thanks for the extra explanation and example. The extra flexibility
> sounds good to me!
>
> Reviewed-by: Maxim Cournoyer <maxim.cournoyer <at> gmail>
Pushed as 0a220c1599613b7bee38c0bf8bc1bb3e9cbcaeb8, thanks!
Ludo’.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Thu, 25 Jul 2024 11:24:08 GMT)
Full text and
rfc822 format available.
This bug report was last modified 1 year and 58 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.