[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 06/06: service: Value of ‘root’ service is now a <process>.
From: |
Ludovic Courtès |
Subject: |
[shepherd] 06/06: service: Value of ‘root’ service is now a <process>. |
Date: |
Sat, 15 Jun 2024 19:16:13 -0400 (EDT) |
civodul pushed a commit to branch devel
in repository shepherd.
commit b8fcd5aa3adcf25af0777e8c5c3fa606e11e1514
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Sun Jun 16 00:09:02 2024 +0200
service: Value of ‘root’ service is now a <process>.
That way, ‘herd status root’ displays the PID of shepherd itself.
* modules/shepherd/service.scm (root-service): #:start returns
a <process>-returning lambda that registers to ‘%post-daemonize-hook’.
* tests/basic.sh: Test it.
* tests/daemonize.sh: Likewise.
* tests/status-sexp.sh: Adjust accordingly.
---
modules/shepherd/service.scm | 6 +++++-
tests/basic.sh | 3 +++
tests/daemonize.sh | 10 +++++++++-
tests/status-sexp.sh | 11 ++++++++++-
4 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 525f3bd..8c9d1c6 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -2781,7 +2781,11 @@ where prctl/PR_SET_CHILD_SUBREAPER is unsupported."
#:start (lambda args
(when (isatty? (current-output-port))
(display-version))
- #t)
+ (lambda (change-value)
+ (add-hook! %post-daemonize-hook
+ (lambda ()
+ (change-value (process (getpid) #f))))
+ (process (getpid) #f)))
#:stop (lambda (unused . args)
(local-output (l10n "Exiting shepherd..."))
(shutdown-services)
diff --git a/tests/basic.sh b/tests/basic.sh
index f3d4b44..4ab7927 100644
--- a/tests/basic.sh
+++ b/tests/basic.sh
@@ -87,6 +87,9 @@ test -S "$socket"
pristine_status=`$herd status -n 0` # Prep for 'reload' test.
echo $pristine_status | grep -E '(Start.*root|Stop.*test)'
+# This command should display shepherd's own PID.
+$herd status root | grep "PID $(cat "$pid")"
+
# The "Recent messages" bit should contain that phrase.
$herd status root | grep "Service root started"
diff --git a/tests/daemonize.sh b/tests/daemonize.sh
index df2430d..62e987f 100644
--- a/tests/daemonize.sh
+++ b/tests/daemonize.sh
@@ -1,5 +1,5 @@
# GNU Shepherd --- Check the 'daemonize' action of the root service.
-# Copyright © 2023 Ludovic Courtès <ludo@gnu.org>
+# Copyright © 2023-2024 Ludovic Courtès <ludo@gnu.org>
#
# This file is part of the GNU Shepherd.
#
@@ -59,6 +59,14 @@ shepherd -I -s "$socket" -c "$conf" --pid="$pid" --log="$log"
until test -f "$pid"; do sleep 0.5; done
+# Wait until it has daemonized.
+until grep "Now running as process [0-9]" "$log"; do sleep 0.2; done
+
+# This command should display shepherd's own PID, post-daemonize.
+new_pid="$($herd eval root '(getpid)' | tail -1)"
+kill -0 "$new_pid"
+$herd status root | grep "PID $new_pid"
+
$herd status
until $herd status a | grep running; do sleep 0.3; done
diff --git a/tests/status-sexp.sh b/tests/status-sexp.sh
index 3e0a14b..9e8d4e3 100644
--- a/tests/status-sexp.sh
+++ b/tests/status-sexp.sh
@@ -67,13 +67,22 @@ fetch_status="
(write-command (shepherd-command 'status 'root) sock)
(read sock))"
+shepherd_command="
+ $(cat /proc/$shepherd_pid/cmdline \
+ | xargs -0 \
+ | sed -e's/ /" "/g ; s/^/"/; s/$/"/')"
+
root_service_sexp="
(service (version 0)
(provides (root shepherd))
(requires ())
(respawn? #f)
(docstring \"The root service is used to operate on shepherd itself.\")
- (enabled? #t) (running #t) (conflicts ())
+ (enabled? #t)
+ (running (process (version 0)
+ (id $shepherd_pid)
+ (command ($shepherd_command))))
+ (conflicts ())
(last-respawns ())
(status-changes ((running . 0) (starting . 0)))
(startup-failures ())
- [shepherd] branch devel updated (25ef327 -> b8fcd5a), Ludovic Courtès, 2024/06/15
- [shepherd] 05/06: herd: Distinguish ‘herd status root’ from ‘herd status’., Ludovic Courtès, 2024/06/15
- [shepherd] 06/06: service: Value of ‘root’ service is now a <process>.,
Ludovic Courtès <=
- [shepherd] 04/06: shepherd: PID 1 logs to /dev/log by default, again., Ludovic Courtès, 2024/06/15
- [shepherd] 01/06: log-rotation: Add ‘files’ action., Ludovic Courtès, 2024/06/15
- [shepherd] 02/06: logger: File logger keeps an absolute log file name., Ludovic Courtès, 2024/06/15
- [shepherd] 03/06: shepherd: Use a file logger for the ‘root’ service., Ludovic Courtès, 2024/06/15