[PATCH] services: herd: Fix matching ok responses and add stop service procedure

  • Done
  • quality assurance status badge
Details
3 participants
  • Danny Milosavljevic
  • Ludovic Courtès
  • Christopher Baines
Owner
unassigned
Submitted by
Christopher Baines
Severity
normal

Debbugs page

Christopher Baines wrote 8 years ago
(address . guix-patches@gnu.org)
20170805222646.149cb45a@cbaines.net
Patches incoming...
-----BEGIN PGP SIGNATURE-----

iQKTBAEBCgB9FiEEPonu50WOcg2XVOCyXiijOwuE9XcFAlmGOBZfFIAAAAAALgAo
aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNF
ODlFRUU3NDU4RTcyMEQ5NzU0RTBCMjVFMjhBMzNCMEI4NEY1NzcACgkQXiijOwuE
9Xc2xw//RsHZmm6t+lZ9TKY0tuVpWwOpYFHacTwF3STIEas/M1gouFEQOotE28J+
ZqDFMBADyEuggBuFdP/IBTyMMk9jD+qikkNDXCFc+5hmH7pmH6M0jJk+PGZTxL2j
E2N6x6uMYlgtEYU8JU7AEHN5b73Ii7Jj4FZ8ONsk9+DTkSc7TjuWm/EDMJaxbsa3
8oYdsWuqb+iQ8QzqLsDwnw0Aj5jjtATnUDJNJyqx+s5DseevaBtZIsScM9TWLeg6
LrcjMOenGMQMZfRx+s2Tb56ZX/ie1ykQEBNufkGa0Utb2L8HoDqwXSgO8aF042ZO
lUCImNDATXzJQWFPMgZQvRlr8K4u5TdnZrKJNSuNCCDoGmwp0OPp/2d2If0g0YzA
HUQ1yECYp/hKNQw/3HJs41Vy+ZwElub1RCiVIOS+0emTNZqErM2Izrs1RmFD6PRU
8MCerdQJ0xYlr7nurZHs8om8GSIMxiawM8Dwb9iJN9AlpupscDLTNgcCApPaVx5U
+qYaBuiPvhD1To7y9OhUyDPcVzHcgFFo0vQwPvSn41wT9LsXqkwbNLaROXfNADEA
BuGZhxdQahruGblWWa+aOBfgZLIQSCU0K513YbgI/keaYzVS/uZnZ3aLtvXNCpDd
Jihd5FRS1Fc7/boUcfhxLtbKz3IotEfZuGGnXXnovTUlWKU/id4=
=pEE/
-----END PGP SIGNATURE-----


Christopher Baines wrote 8 years ago
[PATCH 2/2] services: herd: Add a stop-service procedure.
(address . 27977@debbugs.gnu.org)
20170805213034.1012-2-mail@cbaines.net
* gnu/services/herd.scm (stop-service): New procedure.
---
gnu/services/herd.scm | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

Toggle diff (27 lines)
diff --git a/gnu/services/herd.scm b/gnu/services/herd.scm
index 49400aba4..e16d51b9d 100644
--- a/gnu/services/herd.scm
+++ b/gnu/services/herd.scm
@@ -49,7 +49,8 @@
unload-services
unload-service
load-services
- start-service))
+ start-service
+ stop-service))
;;; Commentary:
;;;
@@ -222,6 +223,10 @@ returns a shepherd <service> object."
(with-shepherd-action name ('start) result
result))
+(define (stop-service name)
+ (with-shepherd-action name ('stop) result
+ result))
+
;; Local Variables:
;; eval: (put 'alist-let* 'scheme-indent-function 2)
;; eval: (put 'with-shepherd 'scheme-indent-function 1)
--
2.13.1
Christopher Baines wrote 8 years ago
[PATCH 1/2] services: herd: Fix matching ok responses from shepherd service.
(address . 27977@debbugs.gnu.org)
20170805213034.1012-1-mail@cbaines.net
Previously the match expression case for a successful response
(where error is #f) required that the result component contained a list with a
single element.

As far as I see when looking at the responses from the shepherd, this is not
normally the case. Therefore, to avoid treating successful responses as
errors, make the match requirement more permissive, accepting any value.

* gnu/services/herd.scm (invoke-action): Change match condition for ok responses.
---
gnu/services/herd.scm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Toggle diff (15 lines)
diff --git a/gnu/services/herd.scm b/gnu/services/herd.scm
index f8d60a480..49400aba4 100644
--- a/gnu/services/herd.scm
+++ b/gnu/services/herd.scm
@@ -146,7 +146,7 @@ result. Otherwise return #f."
(force-output sock)
(match (read sock)
- (('reply ('version 0 _ ...) ('result (result)) ('error #f)
+ (('reply ('version 0 _ ...) ('result result) ('error #f)
('messages messages))
(for-each display-message messages)
(cont result))
--
2.13.1
Danny Milosavljevic wrote 8 years ago
Re: [bug#27977] [PATCH 2/2] services: herd: Add a stop-service procedure.
(name . Christopher Baines)(address . mail@cbaines.net)(address . 27977@debbugs.gnu.org)
20170808101401.036301f9@scratchpost.org
LGTM!
Danny Milosavljevic wrote 8 years ago
Re: [bug#27977] [PATCH 1/2] services: herd: Fix matching ok responses from shepherd service.
(name . Christopher Baines)(address . mail@cbaines.net)(address . 27977@debbugs.gnu.org)
20170808101642.7446f27f@scratchpost.org
LGTM!
Christopher Baines wrote 8 years ago
Re: [bug#27977] [PATCH 2/2] services: herd: Add a stop-service procedure.
(name . Danny Milosavljevic)(address . dannym@scratchpost.org)(address . 27977-done@debbugs.gnu.org)
20170808205304.2e1e5ed0@cbaines.net
On Tue, 8 Aug 2017 10:14:01 +0200
Danny Milosavljevic <dannym@scratchpost.org> wrote:

Toggle quote (2 lines)
> LGTM!

Thanks for your review Danny.

I've now pushed :)
-----BEGIN PGP SIGNATURE-----

iQKTBAEBCgB9FiEEPonu50WOcg2XVOCyXiijOwuE9XcFAlmKFqBfFIAAAAAALgAo
aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNF
ODlFRUU3NDU4RTcyMEQ5NzU0RTBCMjVFMjhBMzNCMEI4NEY1NzcACgkQXiijOwuE
9Xd1UQ/+Mt+gjuXRK/6l+foFtA9fHg8muSGWYWmy/SQ40oVo2pAoUJfypMOrXi0j
tGqSC0CVbgBreRvN6k8AJIAlEitUi4tzX2pm+WhBT/9qWgtckmf2AtPqWMhfpgtM
Fn9BN5LCHcvy9j96lMT69Vt2DDTcGFBcuSmCisiykAIUNj6EfnBUs82PKj922m1A
bZyI42AfJpqGlEQy+n9l+FYS42ms20nuTFVxcXi6/mFzEL09tt/GxFuTp5m6ELiI
ORfkQr6y9t7+eIUqII4Z/5r1poIlSIEDo0l6/VRL6Rp2qIPSm0yLtBiszxx+4K9b
Ca4ln7lx5izhRJ7TW5RtALNQsTgWZVLIxa0GVQNB2zARndyxRuN54iOrcad5Ibtw
mvR61BXwZucCFS+1WpJrRfxxfYyIZ9+akljTOXK8etms8ixVbNEKyPOWQw6v9PKs
GW4YFMO3OSk/G13y3Elk9J6FzgHkvqF/XwNhznpHrVNjFwK1jlFP2c1AHucY9gj3
RLgARq5m+nxLHJprFTlLhTqyl7njlPcPRIArB5LwltDvVnhGcM24K6j/nVYvQY3E
tAvZprO9ChTj12ssF4kx4Dqkn8fKBwpK09Dvh9oy9d81cY5yb20zgWeiNHpCS9x5
Ln+tLZaOOKOBx00o3AMd3rZO72l2v+wi762Qk8afCopu6aqoTXo=
=IQvi
-----END PGP SIGNATURE-----


Closed
Ludovic Courtès wrote 8 years ago
Re: [bug#27977] [PATCH 1/2] services: herd: Fix matching ok responses from shepherd service.
(name . Christopher Baines)(address . mail@cbaines.net)(address . 27977@debbugs.gnu.org)
87a82r7p4n.fsf@gnu.org
Christopher Baines <mail@cbaines.net> skribis:

Toggle quote (4 lines)
> Previously the match expression case for a successful response
> (where error is #f) required that the result component contained a list with a
> single element.

Good catch!

Ludo’.
Ludovic Courtès wrote 8 years ago
(name . Christopher Baines)(address . mail@cbaines.net)(address . 27977@debbugs.gnu.org)
87h8wz38hf.fsf@gnu.org
Christopher Baines <mail@cbaines.net> skribis:

Toggle quote (25 lines)
> Previously the match expression case for a successful response
> (where error is #f) required that the result component contained a list with a
> single element.
>
> As far as I see when looking at the responses from the shepherd, this is not
> normally the case. Therefore, to avoid treating successful responses as
> errors, make the match requirement more permissive, accepting any value.
>
> * gnu/services/herd.scm (invoke-action): Change match condition for ok responses.
> ---
> gnu/services/herd.scm | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gnu/services/herd.scm b/gnu/services/herd.scm
> index f8d60a480..49400aba4 100644
> --- a/gnu/services/herd.scm
> +++ b/gnu/services/herd.scm
> @@ -146,7 +146,7 @@ result. Otherwise return #f."
> (force-output sock)
>
> (match (read sock)
> - (('reply ('version 0 _ ...) ('result (result)) ('error #f)
> + (('reply ('version 0 _ ...) ('result result) ('error #f)
> ('messages messages))

Actually this is not OK (it broke system tests because
‘current-services’ was now getting a single-element list instead of the
list of service sexps.)

The reason for this is that the ‘action’ method in the Shepherd, when
invoked on a symbol, returns a list of results, one for each service of
that name:

(define-method (action (obj <symbol>) the-action . args)
"Perform THE-ACTION on all the services named OBJ. Return the list of
results."
(let ((which-services (lookup-running-or-providing obj)))
(if (null? which-services)
(let ((unknown (lookup-running 'unknown)))
(if (and unknown
(defines-action? unknown 'action))
(apply action unknown 'action the-action args)
(raise (condition (&missing-service-error (name obj))))))
(map (lambda (service)
(apply action service the-action args))
which-services))))

(With the exception of actions called on the ‘unknown’ service, which we
should probably get rid of.)

So either we revert the change, or we do this:
Toggle diff (51 lines)
diff --git a/gnu/services/herd.scm b/gnu/services/herd.scm
index e16d51b9d..7614c7f9f 100644
--- a/gnu/services/herd.scm
+++ b/gnu/services/herd.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2016 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2016, 2017 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
;;;
;;; This file is part of GNU Guix.
@@ -186,7 +186,11 @@ of pairs."
"Return the list of currently defined Shepherd services, represented as
<live-service> objects. Return #f if the list of services could not be
obtained."
- (with-shepherd-action 'root ('status) services
+ (with-shepherd-action 'root ('status) results
+ ;; We get a list of results, one for each service with the name 'root'.
+ ;; In practice there's only one such service though.
+ (match results
+ ((services _ ...)
(match services
((('service ('version 0 _ ...) _ ...) ...)
(map (lambda (service)
@@ -194,22 +198,22 @@ obtained."
(live-service provides requires running)))
services))
(x
- #f))))
+ #f))))))
(define (unload-service service)
"Unload SERVICE, a symbol name; return #t on success."
(with-shepherd-action 'root ('unload (symbol->string service)) result
- result))
+ (first result)))
(define (%load-file file)
"Load FILE in the Shepherd."
(with-shepherd-action 'root ('load file) result
- result))
+ (first result)))
(define (eval-there exp)
"Eval EXP in the Shepherd."
(with-shepherd-action 'root ('eval (object->string exp)) result
- result))
+ (first result)))
(define (load-services files)
"Load and register the services from FILES, where FILES contain code that
Probably this patch is better than reverting.

Thoughts?

Ludo’.
Christopher Baines wrote 8 years ago
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 27977@debbugs.gnu.org)
20170822174452.3784d96c@cbaines.net
On Tue, 22 Aug 2017 17:52:44 +0200
ludo@gnu.org (Ludovic Courtès) wrote:

Toggle quote (4 lines)
> Probably this patch is better than reverting.
>
> Thoughts?

I had to apply that patch with --ignore-whitespace-change, as the code
in the middle of (current-services) has been indented outside of that
patch.

I think I get what is going on. As far as I understand it, the (match
results ((services _ ...) ... bit is equivilent to the use of first in
the other procedures, which suggests to me that you could use first in
(current-services)? I'm guessing that the only difference is that they
will fail differently on the empty list?

Also, I've successfully ran the memcached service test with this
change, so there is no regression there which is good :)
-----BEGIN PGP SIGNATURE-----

iQKTBAEBCgB9FiEEPonu50WOcg2XVOCyXiijOwuE9XcFAlmcX4ZfFIAAAAAALgAo
aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNF
ODlFRUU3NDU4RTcyMEQ5NzU0RTBCMjVFMjhBMzNCMEI4NEY1NzcACgkQXiijOwuE
9Xc3bg/+IQFpklYoiy1N9S5YBorUu/3RPO9JfbUtSpa88bk81WPZ+xQdxKFGmSOB
8bOYF21Pu82BhSTJxpGWfYaTzO51tI8phW4S8Il4EJIbuly+s0Bs73kzaXKqdLO6
JLSSzXMSDrmWt+9/U6IAhxnFJboJcK6LOVN4dOjkRCZ3ueTnoJDG7JCItvW6if9e
PANzSjuT5ygu3gWjlHkyEha+i7pnhaMXHYeKlzXZ8WfDC+MGW2z51VF736X3TRFk
F9ovIJrz9TawgWWZRKDpJcZD1gYc+0izatwLCH15xph3YmG2s1FJrbbQjYu2z/m4
jLaaiKQJ57xNnkQ0+7fQZGF4o8GuP6dfb8m4e9a/Nzb6ri6OobwVGE1Jy2Jd/sfg
FJSX6mmKgesfexCWHgfntPj13wLTbsEUkwKjAG6hwKnothRDrRMfpFeg11LAvCCh
ZRe8cBvgw64jnd+PnuMfrB9+I4gIvcPQUU5idqv2MsyW5/+pKQPi6Se/YLtGcNAz
utjYDNUjIdjPffhdYHTxXogdzaKXlPvlXro/HxFQfmshUP0i4OILtmN7d3S2hCNa
cG0EpPrfU1Nk4YfRV6U+0h17Qrelbi2A5pb/5zaWdI4v8j/ERA7h55rYfB0Sd03o
InS7tzWb5uuowfpMv4hl+Kdf9XN+0vh5YHQLunF6sz+cgVUzEus=
=H9os
-----END PGP SIGNATURE-----


Ludovic Courtès wrote 8 years ago
(name . Christopher Baines)(address . mail@cbaines.net)(address . 27977-done@debbugs.gnu.org)
87a82rnsle.fsf@gnu.org
Christopher Baines <mail@cbaines.net> skribis:

Toggle quote (11 lines)
> On Tue, 22 Aug 2017 17:52:44 +0200
> ludo@gnu.org (Ludovic Courtès) wrote:
>
>> Probably this patch is better than reverting.
>>
>> Thoughts?
>
> I had to apply that patch with --ignore-whitespace-change, as the code
> in the middle of (current-services) has been indented outside of that
> patch.

Right, sorry about that (I have -bB in ‘vc-diff-switches’).

Toggle quote (6 lines)
> I think I get what is going on. As far as I understand it, the (match
> results ((services _ ...) ... bit is equivilent to the use of first in
> the other procedures, which suggests to me that you could use first in
> (current-services)? I'm guessing that the only difference is that they
> will fail differently on the empty list?

Yes. I’ve pushed it as 7d14082d56462f7bef4254d65a21fd265fbce471.

Thanks,
Ludo’.
Closed
?
Your comment

This issue is archived.

To comment on this conversation send an email to 27977@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 27977
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch
You may also tag this issue. See list of standard tags. For example, to set the confirmed and easy tags
mumi command -t +confirmed -t +easy
Or, remove the moreinfo tag and set the help tag
mumi command -t -moreinfo -t +help