unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Carlo Zancanaro <carlo@zancanaro.id.au>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: 30532@debbugs.gnu.org
Subject: [bug#30532] [PATCH] Shepherd: Terminate all services upon SIGTERM or SIGHUP
Date: Wed, 28 Feb 2018 08:29:50 +1100	[thread overview]
Message-ID: <87a7vu9l4h.fsf@zancanaro.id.au> (raw)
In-Reply-To: <87lgfe4vft.fsf@gnu.org>


[-- Attachment #1.1: Type: text/plain, Size: 1094 bytes --]

Hey Ludo,

On Tue, Feb 27 2018, Ludovic Courtès wrote:
>> It's also worth noting that I had to run `gettextize` to get 
>> Shepherd
>> to build on current master, but I haven't included those 
>> changes in
>> this commit (because I don't know what should be committed and 
>> what
>> shouldn't).
>
> Right, I’m not sure what’s wrong with that.  I’ve committed the 
> same
> files under po/ as I did for Guix:
>
> --8<---------------cut 
> here---------------start------------->8---
> $ git ls-files po/
> po/Makevars
> po/POTFILES.in
> --8<---------------cut 
> here---------------end--------------->8---

If you clone shepherd from the repository, can you build it? 
Comparing the guix repository to the shepherd one I can't easily 
work out what needs to be done for this, but hopefully you can at 
least reproduce my problem.

> I have one request: since the three tests differ only in the 
> signal
> name, could you make it a single test file and have a loop like:
>
>   for signal in SIGTERM SIGHUP SIGINT

Updated patch is attached.

Carlo


[-- Attachment #1.2: 0001-Terminate-all-services-upon-SIGTERM-or-SIGHUP.patch --]
[-- Type: text/x-patch, Size: 3604 bytes --]

From 717456edd92ba753daf5dd40e2f8d51eab3e7a73 Mon Sep 17 00:00:00 2001
From: Carlo Zancanaro <carlo@zancanaro.id.au>
Date: Tue, 20 Feb 2018 02:52:47 +1100
Subject: [PATCH] Terminate all services upon SIGTERM or SIGHUP

* modules/shepherd.scm (main): Add SIGTERM and SIGHUP handlers which stop
  root-service.
* tests/sigint.sh: Rename to...
* tests/signals.sh: ... this, and add tests for SIGTERM and SIGUP.
---
 Makefile.am                     |  3 ++-
 modules/shepherd.scm            | 11 +++++++++++
 tests/{sigint.sh => signals.sh} | 23 ++++++++++++++---------
 3 files changed, 27 insertions(+), 10 deletions(-)
 rename tests/{sigint.sh => signals.sh} (72%)

diff --git a/Makefile.am b/Makefile.am
index a30b11d..1c394e1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,7 @@
 # Makefile.am -- How to build and install the Shepherd.
 # Copyright © 2002, 2003 Wolfgang Jährling <wolfgang@pro-linux.de>
 # Copyright © 2013, 2014, 2015, 2016, 2018 Ludovic Courtès <ludo@gnu.org>
+# Copyright © 2018 Carlo Zancanaro <carlo@zancanaro.id.au>
 #
 # This file is part of the GNU Shepherd.
 #
@@ -188,7 +189,7 @@ TESTS =						\
   tests/no-home.sh				\
   tests/pid-file.sh				\
   tests/status-sexp.sh				\
-  tests/sigint.sh
+  tests/signals.sh
 
 TEST_EXTENSIONS = .sh
 EXTRA_DIST += $(TESTS)
diff --git a/modules/shepherd.scm b/modules/shepherd.scm
index 5334657..650ba63 100644
--- a/modules/shepherd.scm
+++ b/modules/shepherd.scm
@@ -1,6 +1,7 @@
 ;; shepherd.scm -- The daemon shepherd.
 ;; Copyright (C) 2013, 2014, 2016, 2018 Ludovic Courtès <ludo@gnu.org>
 ;; Copyright (C) 2002, 2003 Wolfgang Jährling <wolfgang@pro-linux.de>
+;; Copyright (C) 2018 Carlo Zancanaro <carlo@zancanaro.id.au>
 ;;
 ;; This file is part of the GNU Shepherd.
 ;;
@@ -182,6 +183,16 @@
       (lambda _
         (stop root-service)))
 
+    ;; Stop everything when we get SIGTERM.
+    (sigaction SIGTERM
+      (lambda _
+        (stop root-service)))
+
+    ;; Stop everything when we get SIGHUP.
+    (sigaction SIGHUP
+      (lambda _
+        (stop root-service)))
+
     ;; Ignore SIGPIPE so that we don't die if a client closes the connection
     ;; prematurely.
     (sigaction SIGPIPE SIG_IGN)
diff --git a/tests/sigint.sh b/tests/signals.sh
similarity index 72%
rename from tests/sigint.sh
rename to tests/signals.sh
index 7354848..acb254a 100644
--- a/tests/sigint.sh
+++ b/tests/signals.sh
@@ -1,5 +1,6 @@
-# GNU Shepherd --- Make sure SIGINT is correctly handled.
+# GNU Shepherd --- Make sure SIGINT, SIGTERM, and SIGHUP are correctly handled.
 # Copyright © 2014, 2016 Ludovic Courtès <ludo@gnu.org>
+# Copyright © 2018 Carlo Zancanaro <carlo@zancanaro.id.au>
 #
 # This file is part of the GNU Shepherd.
 #
@@ -44,14 +45,18 @@ cat > "$conf"<<EOF
  (start 'test)
 EOF
 
-rm -f "$pid" "$stamp"
-shepherd -I -s "$socket" -c "$conf" --pid="$pid" --log="$log" &
+for signal in INT TERM HUP; do
 
-while [ ! -f "$pid" ] ; do sleep 0.5 ; done
+  rm -f "$pid" "$stamp" "$socket"
+  shepherd -I -s "$socket" -c "$conf" --pid="$pid" --log="$log" &
 
-# Send SIGINT to shepherd.
-kill -INT "`cat "$pid"`"
-while kill -0 "`cat "$pid"`" ; do sleep 0.5 ; done
+  while [ ! -f "$pid" ] ; do sleep 0.5 ; done
 
-# Make sure the service's 'stop' method was called.
-test -f "$stamp"
+  # Send signal to shepherd.
+  kill -$signal "`cat "$pid"`"
+  while kill -0 "`cat "$pid"`" ; do sleep 0.5 ; done
+
+  # Make sure the service's 'stop' method was called.
+  test -f "$stamp"
+
+done
-- 
2.16.1


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

  parent reply	other threads:[~2018-02-27 21:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-19 17:11 [bug#30532] [PATCH] Shepherd: Terminate all services upon SIGTERM or SIGHUP Carlo Zancanaro
2018-02-27  9:45 ` Ludovic Courtès
2018-02-27 17:22   ` Leo Famulari
2018-02-27 21:03     ` Ludovic Courtès
2018-02-27 21:19     ` Carlo Zancanaro
2018-02-27 21:30       ` Ludovic Courtès
2018-03-02  0:30       ` Leo Famulari
2018-03-02  7:25         ` Carlo Zancanaro
2018-02-27 21:29   ` Carlo Zancanaro [this message]
2018-03-01  9:55     ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a7vu9l4h.fsf@zancanaro.id.au \
    --to=carlo@zancanaro.id.au \
    --cc=30532@debbugs.gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).