[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 01/01: service: Don't raise error when stopping an already st
From: |
Ricardo Wurmus |
Subject: |
[shepherd] 01/01: service: Don't raise error when stopping an already stopped service. |
Date: |
Tue, 5 Feb 2019 10:37:56 -0500 (EST) |
rekado pushed a commit to branch master
in repository shepherd.
commit 5368ee4a9f0e71a091883c0b6bddbcf33ab1ecf8
Author: Ricardo Wurmus <address@hidden>
Date: Sun Feb 3 23:25:22 2019 +0100
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.
* tests/basic.sh: Add test.
---
modules/shepherd/service.scm | 14 ++++++++++----
tests/basic.sh | 5 +++++
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 34a55a1..bc75eca 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -4,6 +4,7 @@
;; Copyright (C) 2014 Alex Sassmannshausen <address@hidden>
;; Copyright (C) 2016 Alex Kost <address@hidden>
;; Copyright (C) 2018 Carlo Zancanaro <address@hidden>
+;; Copyright (C) 2019 Ricardo Wurmus <address@hidden>
;;
;; This file is part of the GNU Shepherd.
;;
@@ -592,13 +593,18 @@ 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 obj)
+ (()
+ (raise (condition (&missing-service-error (name obj)))))
+ ((stopped . _)
+ (list))))))))
(define-method (action (obj <symbol>) the-action . args)
"Perform THE-ACTION on all the services named OBJ. Return the list of
diff --git a/tests/basic.sh b/tests/basic.sh
index 79caa32..27998bd 100644
--- a/tests/basic.sh
+++ b/tests/basic.sh
@@ -91,6 +91,11 @@ $herd stop test
$herd status test | grep stopped
+# Stopping a stopped service should be a no-op.
+out=$($herd stop test)
+test $?
+test -z "$out"
+
# Disable a service and make sure it cannot be started.
$herd disable test-2
if $herd start test-2