[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 12/12: herd: Report 'starting' and 'stopping' service statuse
From: |
Ludovic Courtès |
Subject: |
[shepherd] 12/12: herd: Report 'starting' and 'stopping' service statuses. |
Date: |
Sun, 19 Feb 2023 16:58:37 -0500 (EST) |
civodul pushed a commit to branch wip-service-monitor
in repository shepherd.
commit da158c565520354e24ba2ef8d3ae3739eccdd5f6
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Sun Feb 19 22:37:21 2023 +0100
herd: Report 'starting' and 'stopping' service statuses.
Previously "herd status SERVICE" would report either "started" or
"stopped".
* modules/shepherd/scripts/herd.scm (display-service-status): Check
'status' field. Report 'starting' and 'stopping' statuses.
* tests/starting-status.sh, tests/stopping-status.sh,
tests/system-star.sh: Adjust accordingly.
---
modules/shepherd/scripts/herd.scm | 39 +++++++++++++++++++++++++--------------
tests/starting-status.sh | 5 ++---
tests/stopping-status.sh | 3 +--
tests/system-star.sh | 6 +++---
4 files changed, 31 insertions(+), 22 deletions(-)
diff --git a/modules/shepherd/scripts/herd.scm
b/modules/shepherd/scripts/herd.scm
index 9e22b70..9f401ef 100644
--- a/modules/shepherd/scripts/herd.scm
+++ b/modules/shepherd/scripts/herd.scm
@@ -1,5 +1,5 @@
;; herd.scm -- The program to herd the Shepherd.
-;; Copyright (C) 2013-2014, 2016, 2018-2019, 2021-2022 Ludovic Courtès
<ludo@gnu.org>
+;; Copyright (C) 2013-2014, 2016, 2018-2019, 2021-2023 Ludovic Courtès
<ludo@gnu.org>
;; Copyright (C) 2002, 2003 Wolfgang Jährling <wolfgang@pro-linux.de>
;;
;; This file is part of the GNU Shepherd.
@@ -91,22 +91,33 @@ of pairs."
"Display the status of SERVICE, an sexp."
(match service
(('service ('version 0 _ ...) properties ...)
- (alist-let* properties (provides requires running respawn? enabled?
+ (alist-let* properties (provides requires status running respawn? enabled?
conflicts last-respawns one-shot? transient?)
(format #t (l10n "Status of ~a:~%") (first provides))
- (cond (running
- (if transient?
- (format #t (l10n " It is started and transient.~%"))
- (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
+
+ ;; Note: Shepherd up to 0.9.x included did not provide 'status', hence
+ ;; the 'or' below.
+ (match (or status (if running 'running 'stopped))
+ ('running
+ (if transient?
+ (format #t (l10n " It is started and transient.~%"))
+ (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))
+ ('stopped
+ (if one-shot?
+ (format #t (l10n " It is stopped (one-shot).~%"))
(format #t (l10n " It is stopped.~%"))))
+ ('starting
+ (format #t (l10n " It is starting.~%")))
+ ('stopping
+ (format #t (l10n " It is being stopped.~%")))
+ (x
+ (format #t (l10n " Unknown status '~a'~%.") x)))
+
(if enabled?
(format #t (l10n " It is enabled.~%"))
(format #t (l10n " It is disabled.~%")))
diff --git a/tests/starting-status.sh b/tests/starting-status.sh
index e0a2c45..1db1f69 100644
--- a/tests/starting-status.sh
+++ b/tests/starting-status.sh
@@ -1,5 +1,5 @@
# GNU Shepherd --- Test the "starting" status.
-# Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
+# Copyright © 2022, 2023 Ludovic Courtès <ludo@gnu.org>
#
# This file is part of the GNU Shepherd.
#
@@ -59,10 +59,9 @@ shepherd_pid="`cat $pid`"
$herd start test &
herd_pid=$!
-# Currently, 'test' is considered as "stopped" while starting.
$herd status
$herd status test
-$herd status test | grep stopped
+$herd status test | grep starting
$herd start test &
herd_pid2=$!
diff --git a/tests/stopping-status.sh b/tests/stopping-status.sh
index e7dce8c..b8dfff5 100644
--- a/tests/stopping-status.sh
+++ b/tests/stopping-status.sh
@@ -64,10 +64,9 @@ $herd status test | grep started
$herd stop test &
herd_pid=$!
-# Currently, 'test' is considered as "running" while being stopped.
$herd status
$herd status test
-$herd status test | grep started
+$herd status test | grep "being stopped"
$herd stop test &
herd_pid2=$!
diff --git a/tests/system-star.sh b/tests/system-star.sh
index 15ff522..3e56498 100755
--- a/tests/system-star.sh
+++ b/tests/system-star.sh
@@ -1,5 +1,5 @@
# GNU Shepherd --- Test whether 'system*' is blocking.
-# Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
+# Copyright © 2022-2023 Ludovic Courtès <ludo@gnu.org>
#
# This file is part of the GNU Shepherd.
#
@@ -70,8 +70,8 @@ kill -0 $shepherd_pid
# 'herd start' will block until the script exits...
$herd start test &
-# ... so at this point the service is stopped.
-$herd status test | grep "stopped"
+# ... so at this point the service is starting or about to start.
+$herd status test | grep -E "(starting|stopped)"
# Touch $stamp. The shell script passed to 'system*' should complete shortly
# after that.
- [shepherd] 01/12: service: Remove 'stop-delay?' and 'waiting-for-termination?'., (continued)
- [shepherd] 01/12: service: Remove 'stop-delay?' and 'waiting-for-termination?'., Ludovic Courtès, 2023/02/19
- [shepherd] 02/12: service: Handle service state in a monitoring agent., Ludovic Courtès, 2023/02/19
- [shepherd] 06/12: service: 'stop' blocks when a service is already being stopped., Ludovic Courtès, 2023/02/19
- [shepherd] 09/12: service: Rename "service monitor" to "service registry"., Ludovic Courtès, 2023/02/19
- [shepherd] 10/12: service: Clarify expected statuses., Ludovic Courtès, 2023/02/19
- [shepherd] 05/12: service: 'start-in-the-background' starts services in parallel., Ludovic Courtès, 2023/02/19
- [shepherd] 03/12: service: 'start' blocks when a service is already being started., Ludovic Courtès, 2023/02/19
- [shepherd] 04/12: service: Start dependent services in parallel., Ludovic Courtès, 2023/02/19
- [shepherd] 07/12: service: 'service-running-value' uses a fresh channel for each reply., Ludovic Courtès, 2023/02/19
- [shepherd] 11/12: service: Communicate the service status symbol to clients., Ludovic Courtès, 2023/02/19
- [shepherd] 12/12: herd: Report 'starting' and 'stopping' service statuses.,
Ludovic Courtès <=
- [shepherd] 08/12: service: Associate a control fiber with each service., Ludovic Courtès, 2023/02/19