[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 05/05: herd: Distinguish between stopped and one-shot service
From: |
Ludovic Courtès |
Subject: |
[shepherd] 05/05: herd: Distinguish between stopped and one-shot services. |
Date: |
Wed, 8 May 2019 10:24:37 -0400 (EDT) |
civodul pushed a commit to branch master
in repository shepherd.
commit fbb9c3fac745552eaf0f354bd0134cca7027bf17
Author: Ludovic Courtès <address@hidden>
Date: Wed May 8 16:19:19 2019 +0200
herd: Distinguish between stopped and one-shot services.
* modules/shepherd/scripts/herd.scm (display-status-summary): Partition
STOPPED into STOPPED and ONE-SHOT. Add an extra call to
'display-services' for one-shot services.
(display-service-status): Distinguish between "stopped" and
"stopped (one-shot)".
* tests/one-shot.sh: Test it all.
---
modules/shepherd/scripts/herd.scm | 58 +++++++++++++++++++++++++--------------
tests/one-shot.sh | 7 +++--
2 files changed, 42 insertions(+), 23 deletions(-)
diff --git a/modules/shepherd/scripts/herd.scm
b/modules/shepherd/scripts/herd.scm
index 2cfcafc..106de1e 100644
--- a/modules/shepherd/scripts/herd.scm
+++ b/modules/shepherd/scripts/herd.scm
@@ -26,6 +26,7 @@
#:use-module (ice-9 rdelim)
#:use-module (ice-9 match)
#:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-11)
#:use-module (srfi srfi-19)
#:export (main))
@@ -57,17 +58,30 @@ of pairs."
(format #t " ~a ~a~%" bullet
(service-canonical-name service)))
(sort services service<?)))) ;get deterministic output
- (call-with-values
- (lambda ()
- (partition (match-lambda
- (('service ('version 0 _ ...) properties ...)
- (car (assoc-ref properties 'running))))
- services))
- (lambda (started stopped)
- (display-services (l10n "Started:\n") "+"
- started)
- (display-services (l10n "Stopped:\n") "-"
- stopped))))
+
+ (let*-values (((started stopped)
+ (partition (match-lambda
+ (('service ('version 0 _ ...) properties ...)
+ (car (assoc-ref properties 'running))))
+ services))
+ ((one-shot stopped)
+ (partition (match-lambda
+ (('service ('version 0 _ ...) properties ...)
+ ;; Prior to 0.6.1, shepherd did not send the
+ ;; 'one-shot?' property; thus, do not assume
+ ;; that it's available.
+ (and=> (assoc-ref properties 'one-shot?) car)))
+ stopped)))
+ (display-services (l10n "Started:\n") "+"
+ started)
+ (display-services (l10n "Stopped:\n") "-"
+ stopped)
+
+ ;; TRANSLATORS: Here "one-shot" refers to "one-shot services". These are
+ ;; services that are immediately marked as stopped once their 'start'
+ ;; method has completed.
+ (display-services (l10n "One-shot:\n") "*"
+ one-shot)))
(define (display-detailed-status services)
"Display the detailed status of SERVICES."
@@ -78,17 +92,19 @@ of pairs."
(match service
(('service ('version 0 _ ...) properties ...)
(alist-let* properties (provides requires running respawn? enabled?
- conflicts last-respawns)
+ conflicts last-respawns one-shot?)
(format #t (l10n "Status of ~a:~%") (first provides))
- (if running
- (begin
- (format #t (l10n " It is started.~%"))
-
- ;; TRANSLATORS: The "~s" bit is most of the time a placeholder
- ;; for the PID (an integer) of the running process, and
- ;; occasionally for another Scheme object.
- (format #t (l10n " Running value is ~s.~%") running))
- (format #t (l10n " It is stopped.~%")))
+ (cond (running
+ (format #t (l10n " It is started.~%"))
+
+ ;; TRANSLATORS: The "~s" bit is most of the time a placeholder
+ ;; for the PID (an integer) of the running process, and
+ ;; occasionally for another Scheme object.
+ (format #t (l10n " Running value is ~s.~%") running))
+ (one-shot?
+ (format #t (l10n " It is stopped (one-shot).~%")))
+ (else
+ (format #t (l10n " It is stopped.~%"))))
(if enabled?
(format #t (l10n " It is enabled.~%"))
(format #t (l10n " It is disabled.~%")))
diff --git a/tests/one-shot.sh b/tests/one-shot.sh
index 93f545b..3d396e5 100644
--- a/tests/one-shot.sh
+++ b/tests/one-shot.sh
@@ -76,16 +76,19 @@ do
rm -f "$stamp"
$herd start test
test -f "$stamp"
- $herd status test | grep stopped
+ $herd status test | grep stopped.*one-shot
grep "test.*started" "$log"
$herd stop test # no-op since it's already stopped
done
+$herd status | grep -i '^one-shot'
+$herd status
+
rm -f "$stamp" "$stamp-2"
$herd start test-2
test -f "$stamp"
test -f "$stamp-2"
-$herd status test | grep stopped
+$herd status test | grep stopped.*one-shot
$herd status test-2 | grep started
$herd stop test-2
if test -f "$stamp-2"; then false; else true; fi