Subject: bug#77109: [feature] [shepherd] Accept multiple services for actions

From: Tomas Volf <[email-masked]>
Date: Fri, 21 Mar 2025 00:34:28 +0100

Maxim Cournoyer <[email-masked]> writes:

>> I am not sure having different semantics for restart and any other
>> action is a good idea though.
>>
>> But what I think would be a good idea is for start, stop, restart to
>> signal an error when additional unexpected arguments are provided.
>
> Failing to change the behavior as suggested, that would still be an
> improvement, yes.  But then you'd also be special casing these actions,
> as actions are designed to receive an arbitrary number of arguments and
> cannot forcibly know which ones are really used/necessary in advance?

But the default implementation of `restart' knows it takes no arguments.
So something like the following.

--8<---------------cut here---------------start------------->8---
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 79d14cf..68c4cca 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -1115,6 +1115,10 @@ the action."
       ;; Restarting is done in the obvious way.
       ((restart)
        (lambda (running . args)
+         (unless (null? args)
+           (local-output
+            (l10n "Action `restart' of ~a takes no arguments.")
+            (service-canonical-name service)))
          (let ((stopped-services (stop-service service)))
            (for-each start-service
                      (remove transient-service? stopped-services))
--8<---------------cut here---------------end--------------->8---

Dunno, just an (untested) idea. ¯\_(ツ)_/¯

Tomas

-- 
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.