* [shepherd] Stopping service twice should not say “not found”
@ 2019-02-03 22:27 Ricardo Wurmus
2019-02-04 22:41 ` Ludovic Courtès
0 siblings, 1 reply; 2+ messages in thread
From: Ricardo Wurmus @ 2019-02-03 22:27 UTC (permalink / raw)
To: guix-devel
[-- Attachment #1: Type: text/plain, Size: 981 bytes --]
Hi,
requesting that a shepherd service (e.g. ’foo’) that has already been
stopped be stopped again produces the error "service 'foo' could not be
found". This is confusing because it implies that ’foo’ is not a valid
name.
(shepherd service) defines a method “stop” that uses “lookup-running” to
find running services:
--8<---------------cut here---------------start------------->8---
;; Stopping by name.
(define-method (stop (obj <symbol>) . args)
(let ((which (lookup-running obj)))
(if (not which)
(let ((unknown (lookup-running 'unknown)))
(if (and unknown
(defines-action? unknown 'stop))
(apply action unknown 'stop obj args)
(raise (condition (&missing-service-error (name obj))))))
(apply stop which args))))
--8<---------------cut here---------------end--------------->8---
I think it would be better to ignore “stop” when it’s run on a stopped
service. Here’s a patch.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-service-Don-t-raise-error-when-stopping-an-already-s.patch --]
[-- Type: text/x-patch, Size: 1881 bytes --]
From c285d0f085e8e9c6a4ad347643f7186807735189 Mon Sep 17 00:00:00 2001
From: Ricardo Wurmus <rekado@elephly.net>
Date: Sun, 3 Feb 2019 23:25:22 +0100
Subject: [PATCH] service: Don't raise error when stopping an already stopped
service.
* modules/shepherd/service.scm (stop): If a service by the given name exists
and is already stopped, then don't raise an error.
---
modules/shepherd/service.scm | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 34a55a1..9f38886 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -4,6 +4,7 @@
;; Copyright (C) 2014 Alex Sassmannshausen <alex.sassmannshausen@gmail.com>
;; Copyright (C) 2016 Alex Kost <alezost@gmail.com>
;; Copyright (C) 2018 Carlo Zancanaro <carlo@zancanaro.id.au>
+;; Copyright (C) 2019 Ricardo Wurmus <rekado@elephly.net>
;;
;; This file is part of the GNU Shepherd.
;;
@@ -592,13 +593,17 @@ Used by `start' and `enforce'."
;; Stopping by name.
(define-method (stop (obj <symbol>) . args)
(let ((which (lookup-running obj)))
- (if (not which)
- (let ((unknown (lookup-running 'unknown)))
+ (if which
+ (apply stop which args)
+ (let ((unknown (lookup-running 'unknown)))
(if (and unknown
(defines-action? unknown 'stop))
(apply action unknown 'stop obj args)
- (raise (condition (&missing-service-error (name obj))))))
- (apply stop which args))))
+ ;; Only print an error if the service does not exist.
+ (match (lookup-services name)
+ (()
+ (raise (condition (&missing-service-error (name obj)))))
+ (_ #f)))))))
(define-method (action (obj <symbol>) the-action . args)
"Perform THE-ACTION on all the services named OBJ. Return the list of
--
2.20.1
[-- Attachment #3: Type: text/plain, Size: 12 bytes --]
--
Ricardo
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [shepherd] Stopping service twice should not say “not found”
2019-02-03 22:27 [shepherd] Stopping service twice should not say “not found” Ricardo Wurmus
@ 2019-02-04 22:41 ` Ludovic Courtès
0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2019-02-04 22:41 UTC (permalink / raw)
To: Ricardo Wurmus; +Cc: guix-devel
Hello,
Ricardo Wurmus <rekado@elephly.net> skribis:
> requesting that a shepherd service (e.g. ’foo’) that has already been
> stopped be stopped again produces the error "service 'foo' could not be
> found". This is confusing because it implies that ’foo’ is not a valid
> name.
Indeed.
> From c285d0f085e8e9c6a4ad347643f7186807735189 Mon Sep 17 00:00:00 2001
> From: Ricardo Wurmus <rekado@elephly.net>
> Date: Sun, 3 Feb 2019 23:25:22 +0100
> Subject: [PATCH] service: Don't raise error when stopping an already stopped
> service.
>
> * modules/shepherd/service.scm (stop): If a service by the given name exists
> and is already stopped, then don't raise an error.
LGTM, though could you add a test? There are already tests that grep
the output of “herd stop foo”; you’d just grep it a second time and
ensure it’s empty, and also ensure that $? is zero.
Thanks!
Ludo’.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-02-04 22:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-03 22:27 [shepherd] Stopping service twice should not say “not found” Ricardo Wurmus
2019-02-04 22:41 ` Ludovic Courtès
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).