[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 04/05: herd: 'status' shows starting and stopping services se
From: |
Ludovic Courtès |
Subject: |
[shepherd] 04/05: herd: 'status' shows starting and stopping services separately. |
Date: |
Fri, 21 Apr 2023 16:59:19 -0400 (EDT) |
civodul pushed a commit to branch master
in repository shepherd.
commit abc0874aa4065532c7beb1e460401dd1af253cc4
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Thu Apr 20 22:09:40 2023 +0200
herd: 'status' shows starting and stopping services separately.
* modules/shepherd/scripts/herd.scm (live-service-status-predicate): New
procedure.
(display-status-summary): Use it to filter based on the status. Display
'starting' and 'stopping' services separately.
* tests/starting-status.sh: Test it.
---
modules/shepherd/scripts/herd.scm | 16 +++++++++++++++-
tests/starting-status.sh | 1 +
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/modules/shepherd/scripts/herd.scm
b/modules/shepherd/scripts/herd.scm
index b9e989b..6457c8d 100644
--- a/modules/shepherd/scripts/herd.scm
+++ b/modules/shepherd/scripts/herd.scm
@@ -53,6 +53,12 @@
"Return the 'canonical name' of @var{service}."
(first (live-service-provision service)))
+(define (live-service-status-predicate status)
+ "Return a predicate that returns true when passed a service with the given
+@var{status}."
+ (lambda (service)
+ (eq? status (live-service-status service))))
+
(define-syntax alist-let*
(syntax-rules ()
"Bind the given KEYs in EXP to the corresponding items in ALIST. ALIST
@@ -96,15 +102,23 @@ into a @code{live-service} record."
(live-service-canonical-name service)))
(sort services service<?)))) ;get deterministic output
- (let* ((started stopped (partition live-service-running-value services))
+ (let* ((started (filter (live-service-status-predicate 'running) services))
+ (stopped (filter (live-service-status-predicate 'stopped) services))
+ (starting (filter (live-service-status-predicate 'starting) services))
+ (stopping (filter (live-service-status-predicate 'stopping) services))
(one-shot stopped (partition live-service-one-shot? stopped))
(failing stopped
(partition (compose pair? live-service-startup-failures)
stopped)))
(display-services (highlight (l10n "Started:\n")) "+"
started)
+ (display-services (highlight (l10n "Starting:\n")) "^"
+ starting)
+
(display-services (highlight (l10n "Stopped:\n")) "-"
stopped)
+ (display-services (highlight (l10n "Stopping:\n")) "v"
+ stopping)
;; TRANSLATORS: Here "one-shot" refers to "one-shot services". These are
;; services that are immediately marked as stopped once their 'start'
diff --git a/tests/starting-status.sh b/tests/starting-status.sh
index df05933..4074e7e 100644
--- a/tests/starting-status.sh
+++ b/tests/starting-status.sh
@@ -60,6 +60,7 @@ $herd start test &
herd_pid=$!
$herd status
+$herd status | grep ' ^ test'
$herd status test
$herd status test | grep starting