[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 02/07: service: Make sure the respawn limit is honored.
From: |
Ludovic Courtès |
Subject: |
[shepherd] 02/07: service: Make sure the respawn limit is honored. |
Date: |
Wed, 23 Mar 2016 21:41:04 +0000 |
civodul pushed a commit to branch master
in repository shepherd.
commit 8c8a010b425e56461289bae62a94ee401e5dad41
Author: Ludovic Courtès <address@hidden>
Date: Wed Mar 23 19:11:00 2016 +0100
service: Make sure the respawn limit is honored.
This fixes a bug whereby services would be respawned forever because the
'start' method would reset the 'last-respawns' field each time it
respawns a service. Regression introduced in version 0.3 (commit
063d09b2a29768e957a3d867fca5f2f7cd2489ab.)
Reported by Danny Milosavljevic <address@hidden>
at <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=23064>.
* modules/shepherd/service.scm (start): Leave the 'last-respawns' field
unchanged.
(stop): Reset the 'last-respawns' field.
* tests/respawn-throttling.sh: New file.
* Makefile.am (TESTS): Add it.
---
.gitignore | 2 +
Makefile.am | 1 +
modules/shepherd/service.scm | 8 ++--
tests/respawn-throttling.sh | 77 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 84 insertions(+), 4 deletions(-)
diff --git a/.gitignore b/.gitignore
index 632dafe..fe35476 100644
--- a/.gitignore
+++ b/.gitignore
@@ -54,3 +54,5 @@
/texinfo.tex
Makefile
Makefile.in
+/tests/respawn-throttling.log
+/tests/respawn-throttling.trs
diff --git a/Makefile.am b/Makefile.am
index 7ec0511..7a88c04 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -175,6 +175,7 @@ SUFFIXES = .go
TESTS = \
tests/basic.sh \
tests/respawn.sh \
+ tests/respawn-throttling.sh \
tests/misbehaved-client.sh \
tests/no-home.sh \
tests/status-sexp.sh \
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index b029476..791bb2a 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -311,9 +311,6 @@ wire."
problem)
(call-with-blocked-asyncs
(lambda ()
- ;; Reset the list of respawns.
- (slot-set! obj 'last-respawns '())
-
;; Start the service itself. Asyncs are blocked so that if
;; the newly-started process dies immediately, the SIGCHLD
;; handler is invoked later, once we have set the 'running'
@@ -337,7 +334,7 @@ wire."
;; latter fails, continue anyway. Return `#f' if it could be stopped.
(define-method (stop (obj <service>) . args)
;; Block asyncs so the SIGCHLD handler doesn't execute concurrently.
- ;; Notably, that makes sure the handler process the SIGCHLD for OBJ's
+ ;; Notably, that makes sure the handler processes the SIGCHLD for OBJ's
;; process once we're done; otherwise, it could end up respawning OBJ.
(call-with-blocked-asyncs
(lambda ()
@@ -374,6 +371,9 @@ wire."
;; OBJ is no longer running.
(slot-set! obj 'running #f)
+ ;; Reset the list of respawns.
+ (slot-set! obj 'last-respawns '())
+
;; Status message.
(let ((name (canonical-name obj)))
(if (running? obj)
diff --git a/tests/respawn-throttling.sh b/tests/respawn-throttling.sh
new file mode 100644
index 0000000..13ada5d
--- /dev/null
+++ b/tests/respawn-throttling.sh
@@ -0,0 +1,77 @@
+# GNU Shepherd --- Test respawn throttling.
+# Copyright © 2016 Ludovic Courtès <address@hidden>
+#
+# This file is part of the GNU Shepherd.
+#
+# The GNU Shepherd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or (at
+# your option) any later version.
+#
+# The GNU Shepherd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with the GNU Shepherd. If not, see <http://www.gnu.org/licenses/>.
+
+shepherd --version
+herd --version
+
+socket="t-socket-$$"
+conf="t-conf-$$"
+log="t-log-$$"
+pid="t-pid-$$"
+
+herd="herd -s $socket"
+
+trap "cat $log || true ;
+ rm -f $socket $conf $log ;
+ test -f $pid && kill \`cat $pid\` || true ; rm -f $pid" EXIT
+
+cat > "$conf"<<EOF
+(register-services
+ (make <service>
+ #:provides '(keeps-respawning)
+ #:start (make-forkexec-constructor '("false"))
+ #:stop (make-kill-destructor)
+ #:respawn? #t))
+EOF
+
+rm -f "$pid"
+shepherd -I -s "$socket" -c "$conf" -l "$log" --pid="$pid" &
+
+# Wait till it's ready.
+while ! test -f "$pid" ; do sleep 0.3 ; done
+shepherd_pid="`cat $pid`"
+
+kill -0 $shepherd_pid
+test -S "$socket"
+
+$herd start keeps-respawning
+
+# Maximum number of seconds to wait. XXX: It takes a while because SIGCHLD
+# handling is deferred until we leave the accept(2) call in (shepherd).
+count=15
+
+while [ $count -gt 0 ]
+do
+ sleep 1
+ if $herd status keeps-respawning | grep disabled
+ then
+ # The service is now disabled: success!
+ break
+ else
+ count=`expr $count - 1`
+ test $count -ge 0
+ fi
+done
+
+# Make sure the service is indeed stopped and disabled.
+$herd status keeps-respawning | grep stopped
+$herd status keeps-respawning | grep disabled
+if $herd start keeps-respawning
+then false; else true; fi
+
+grep -i "respawning too fast" "$log"
- [shepherd] branch master updated (66662cf -> e589b12), Ludovic Courtès, 2016/03/23
- [shepherd] 03/07: service: Choose a respawn limit slightly more lax., Ludovic Courtès, 2016/03/23
- [shepherd] 07/07: Update 'NEWS'., Ludovic Courtès, 2016/03/23
- [shepherd] 06/07: build: Bump to 0.3.1., Ludovic Courtès, 2016/03/23
- [shepherd] 02/07: service: Make sure the respawn limit is honored.,
Ludovic Courtès <=
- [shepherd] 01/07: service: Fix harmless typo., Ludovic Courtès, 2016/03/23
- [shepherd] 04/07: service: Improve wording of 'waitpid' "error" message., Ludovic Courtès, 2016/03/23
- [shepherd] 05/07: herd: Display the last respawn time., Ludovic Courtès, 2016/03/23