From unknown Sun Aug 10 16:46:15 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#50717] [PATCH] Shepherd: Add respawn-limit paramter to service class. Resent-From: Ryan Sundberg Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 21 Sep 2021 07:43:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 50717 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 50717@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.163221013921089 (code B ref -1); Tue, 21 Sep 2021 07:43:01 +0000 Received: (at submit) by debbugs.gnu.org; 21 Sep 2021 07:42:19 +0000 Received: from localhost ([127.0.0.1]:44756 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mSaPy-0005U4-Uc for submit@debbugs.gnu.org; Tue, 21 Sep 2021 03:42:19 -0400 Received: from lists.gnu.org ([209.51.188.17]:36726) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mSaPx-0005Tv-Lm for submit@debbugs.gnu.org; Tue, 21 Sep 2021 03:42:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60588) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSaPx-0001H1-AN for guix-patches@gnu.org; Tue, 21 Sep 2021 03:42:17 -0400 Received: from mail.arctype.co ([138.68.9.245]:36307) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mSaPv-0001Kr-BN for guix-patches@gnu.org; Tue, 21 Sep 2021 03:42:17 -0400 Received: from authenticated-user (mail.arctype.co [138.68.9.245]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by mail.arctype.co (Postfix) with ESMTPSA id 4898E13B228 for ; Tue, 21 Sep 2021 07:42:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=arctype.co; s=mail; t=1632210134; bh=IYe4WbCIEWLswRwoBw4WT1XBRSJLxIoFOS9Vy3TFBto=; h=From:Subject:To:Date:From; b=eqoyOVcv9RWwYtDHJ9tFDQnHgAQfB8omPz0pxTWdbjn26dlwob/HNPTrnMcsDv510 6BXJCyLslkc37RXSDNibazJwOg8OwjBub4g3T/Boq/6rww/wHDRk5AWKshpPC1nRXA IsXSIk3cs39EwljpNQVE66HlcE0KCSIsI+7CjV2jsYaZ/jgDUIqqMmFBgj8yiIGcFY H9UFY49R4qP4Akdu1ijfMw5io4aoJ9YCsdhSC8I0Bvk5DJEfGC2VVWJfK9D3As+lQr bR4c+uRG2uPlS61l5fISmOdZ7xnvoSSpEe4e5+vtdYtKg1PUJdAwOX+3XC6kOpFQeI gH58NgDzq2Ozg== From: Ryan Sundberg Message-ID: Date: Tue, 21 Sep 2021 00:42:14 -0700 MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="5F1MO3h6HH3PTydpZ6m6wRDLrudMvCluj" Received-SPF: pass client-ip=138.68.9.245; envelope-from=ryan@arctype.co; helo=mail.arctype.co X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --5F1MO3h6HH3PTydpZ6m6wRDLrudMvCluj Content-Type: multipart/mixed; boundary="evv5Iw2azlJuHV9aLokrRzq4xIzYp2aRK"; protected-headers="v1" From: Ryan Sundberg To: guix-patches@gnu.org Message-ID: Subject: [PATCH] Shepherd: Add respawn-limit paramter to service class. --evv5Iw2azlJuHV9aLokrRzq4xIzYp2aRK Content-Type: multipart/mixed; boundary="------------C1B8ABC6D3E9CF634893F368" Content-Language: en-US This is a multi-part message in MIME format. --------------C1B8ABC6D3E9CF634893F368 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello Guix devs, This patch to GNU Shepherd removes the hard-coded respawn limit and makes it a configurable option. The respawn limit works generally the same way as before, allowing N respawns in M seconds: #:respawn-limit '(N . M) We can disable respawns by setting N to 0, which will abort the service after the first crash. Likewise, we can always respawn by setting #:respawn-limit #f Sincerely, Ryan Sundberg --------------C1B8ABC6D3E9CF634893F368 Content-Type: text/x-patch; charset=UTF-8; name="0001-service-Add-respawn-limit-paramter-to-the-service-cl.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename*0="0001-service-Add-respawn-limit-paramter-to-the-service-cl.pa"; filename*1="tch" =46rom 94ad8057c6f9a020f12efd78d482b0cf4fe160ec Mon Sep 17 00:00:00 2001 From: Ryan Sundberg Date: Sun, 11 Jul 2021 13:54:04 -0700 Subject: [PATCH] service: Add respawn-limit paramter to the service class= =2E Makes respawn-limit a configurable parameter on service. In addition, we allow the limit to be set to #f to indicate no respawn limit. * modules/shepherd/service.scm: Add respawn-limit --- modules/shepherd/service.scm | 86 +++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm index ad8608b..d741e0b 100644 --- a/modules/shepherd/service.scm +++ b/modules/shepherd/service.scm @@ -134,30 +134,6 @@ ((_) '()))) =20 -;; Respawning CAR times in CDR seconds will disable the service. -;; -;; XXX: The terrible hack in (shepherd) using SIGALRM to work around -;; unreliable SIGCHLD delivery means that it might take up to 1 second f= or -;; SIGCHLD to be delivered. Thus, arrange for the car to be lower than = the -;; cdr. -(define respawn-limit '(5 . 7)) - -(define (respawn-limit-hit? respawns times seconds) - "Return true of RESPAWNS, the list of times at which a given service w= as -respawned, shows that it has been respawned more than TIMES in SECONDS."= - (define now (current-time)) - - ;; Note: This is O(TIMES), but TIMES is typically small. - (let loop ((times times) - (respawns respawns)) - (match respawns - (() - #f) - ((last-respawn rest ...) - (or (zero? times) - (and (> (+ last-respawn seconds) now) - (loop (- times 1) rest))))))) - (define-class () ;; List of provided service-symbols. The first one is also called ;; the `canonical name' and must be unique to this service. @@ -221,7 +197,16 @@ respawned, shows that it has been respawned more tha= n TIMES in SECONDS." (last-respawns #:init-form '()) ;; A replacement for when this service is stopped. (replacement #:init-keyword #:replacement - #:init-value #f)) + #:init-value #f) + ;; Respawning CAR times in CDR seconds will disable the service. + ;; + ;; Respawn limit (times, seconds). Set to #f to disable respawn limits= =2E + ;; XXX: The terrible hack in (shepherd) using SIGALRM to work around + ;; unreliable SIGCHLD delivery means that it might take up to 1 second=20 for + ;; SIGCHLD to be delivered. Thus, arrange for the car to be lower tha= n the + ;; cdr. + (respawn-limit #:init-keyword #:respawn-limit + #:init-value '(5 . 7))) =20 (define (service? obj) "Return true if OBJ is a service." @@ -587,8 +572,6 @@ clients." (define-method (depends-resolved? (obj )) (every lookup-running (required-by obj))) =20 -=0C - (define (launch-service name proc args) "Try to start (with PROC) a service providing NAME; return #f on failu= re. Used by `start' and `enforce'." @@ -648,8 +631,24 @@ results." (apply action service the-action args)) which-services)))) =20 - -=0C +(define-method (respawn-limit-hit? (serv )) + "Return true if service SERV shows that it has been respawned more tha= n it's +respawn-limit TIMES in SECONDS. If the respawn-limit is #f, apply no lim= it." + (match (slot-ref serv 'respawn-limit) + (#f #f) + ((times . seconds) + (let* ((now (current-time)) + (respawns (slot-ref serv 'last-respawns))) + ;; Note: This is O(TIMES), but TIMES is typically small. + (let loop ((times times) + (respawns respawns)) + (match respawns + (() + #f) + ((last-respawn rest ...) + (or (zero? times) + (and (> (+ last-respawn seconds) now) + (loop (- times 1) rest)))))))))) =20 ;; Handling of unprovided service-symbols. This can be called in ;; either of the following ways (i.e. with either three or four @@ -1140,18 +1139,25 @@ attempted to respawn the service a number of time= s already and it keeps dying, then disable it." (slot-set! serv 'running #f) (if (and (respawn? serv) - (not (respawn-limit-hit? (slot-ref serv 'last-respawns) - (car respawn-limit) - (cdr respawn-limit)))) + (not (respawn-limit-hit? serv))) (if (not (slot-ref serv 'waiting-for-termination?)) - (begin - ;; Everything is okay, start it. - (local-output (l10n "Respawning ~a.") - (canonical-name serv)) - (slot-set! serv 'last-respawns - (cons (current-time) - (slot-ref serv 'last-respawns))) - (start serv)) + (match (slot-ref serv 'respawn-limit) + (#f + (begin + (local-output (l10n "Respawning ~a.") + (canonical-name serv)) + (start serv))) + ((respawn-limit-times . _) + (let ((last-respawns (slot-ref serv 'last-respawns))) + ;; Everything is okay, start it. + (local-output (l10n "Respawning ~a.") + (canonical-name serv)) + (slot-set! serv 'last-respawns + (cons (current-time) + ;; Only take the last n times here to pr= event unbounded + ;; list growth + (take last-respawns (min (length last-re= spawns) respawn-limit-times)))) + (start serv)))) ;; We have just been waiting for the ;; termination. The `running' slot has already ;; been set to `#f' by `stop'. --=20 2.31.1 --------------C1B8ABC6D3E9CF634893F368-- --evv5Iw2azlJuHV9aLokrRzq4xIzYp2aRK-- --5F1MO3h6HH3PTydpZ6m6wRDLrudMvCluj Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wsB5BAABCAAjFiEEyVG5Gm1pvFAzyXC2aiMi+MCr96sFAmFJjNYFAwAAAAAACgkQaiMi+MCr96ts mgf5AYCVru8WK6L9+nXfJUepwu3PgkjyQGEgzYneh8vaEOiXdMnsTSlDGv1GirLm/2KeutUui8e4 jlJ3hKLap5WPbTUMUvL5lU73i3iTNam8WucMVJUdyYk45gqQ7drkYrS2U5KTBP3cz5TVV/9fxrMZ lTR6BfWULzRxV5InMElDX7unrKpzwR1KpUPgvdSIppmIq23w6rdFD+/EFV9y0/MBjTCvTt5Qdhkq hX587jggfiwkD/4H7lR5GPnHNuAoKM9Ls7tmjBpHuumDTUkeSqU7OvZf2sIX7y5+DnP+LE4mtPrL uCk7nNtkKMUHIgpD+j5YHfcmyBTZAEkCo7po+QWttg== =xaCP -----END PGP SIGNATURE----- --5F1MO3h6HH3PTydpZ6m6wRDLrudMvCluj-- From unknown Sun Aug 10 16:46:15 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#50717] [PATCH] Shepherd: Add respawn-limit paramter to service class. Resent-From: Mathieu Othacehe Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 01 Oct 2021 10:12:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50717 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ryan Sundberg Cc: 50717@debbugs.gnu.org Received: via spool by 50717-submit@debbugs.gnu.org id=B50717.16330830931805 (code B ref 50717); Fri, 01 Oct 2021 10:12:02 +0000 Received: (at 50717) by debbugs.gnu.org; 1 Oct 2021 10:11:33 +0000 Received: from localhost ([127.0.0.1]:54729 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mWFVt-0000T2-97 for submit@debbugs.gnu.org; Fri, 01 Oct 2021 06:11:33 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39494) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mWFVr-0000Sq-0a for 50717@debbugs.gnu.org; Fri, 01 Oct 2021 06:11:32 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:41274) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mWFVl-0004to-ER; Fri, 01 Oct 2021 06:11:25 -0400 Received: from 2a01cb000492e90078753f5c96c7583f.ipv6.abo.wanadoo.fr ([2a01:cb00:492:e900:7875:3f5c:96c7:583f]:44076 helo=meije) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWFVj-000544-Fs; Fri, 01 Oct 2021 06:11:25 -0400 From: Mathieu Othacehe References: Date: Fri, 01 Oct 2021 10:11:20 +0000 In-Reply-To: (Ryan Sundberg's message of "Tue, 21 Sep 2021 00:42:14 -0700") Message-ID: <878rzdoy0n.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hello Ryan, > We can disable respawns by setting N to 0, which will abort the service > after the first crash. Likewise, we can always respawn by setting > > #:respawn-limit #f Looks nice, thanks for the patch. I have the following error while applying it though: --8<---------------cut here---------------start------------->8--- Applying: service: Add respawn-limit paramter to the service class. error: corrupt patch at line 52 --8<---------------cut here---------------end--------------->8--- Could you try to send it with git-send-email? It would also be nice to add unit tests dedicated to this new feature and update the documentation. Thanks, Mathieu From unknown Sun Aug 10 16:46:15 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Ryan Sundberg Subject: bug#50717: closed (Re: [bug#50717] [PATCH] Shepherd: Add respawn-limit paramter to service class.) Message-ID: References: <87il4bgye8.fsf@gnu.org> X-Gnu-PR-Message: they-closed 50717 X-Gnu-PR-Package: guix-patches X-Gnu-PR-Keywords: patch Reply-To: 50717@debbugs.gnu.org Date: Tue, 02 Jan 2024 22:33:01 +0000 Content-Type: multipart/mixed; boundary="----------=_1704234781-15483-1" This is a multi-part message in MIME format... ------------=_1704234781-15483-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #50717: [PATCH] Shepherd: Add respawn-limit paramter to service class. which was filed against the guix-patches package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 50717@debbugs.gnu.org. --=20 50717: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D50717 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1704234781-15483-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 50717-done) by debbugs.gnu.org; 2 Jan 2024 22:32:20 +0000 Received: from localhost ([127.0.0.1]:51511 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rKnJ6-00040k-H3 for submit@debbugs.gnu.org; Tue, 02 Jan 2024 17:32:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36370) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rKnJ1-00040U-Bz for 50717-done@debbugs.gnu.org; Tue, 02 Jan 2024 17:32:19 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rKnIs-0005ET-Tb; Tue, 02 Jan 2024 17:32:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=h5b2wBfWxPX6jyPYozCyBhpWoCXczo/MS7VRx9zHNnU=; b=bzDGMf4F6LqSoh9sJ03x kMMZMOlj/7Mkr0m9+6U0f1qmvKKCBkFFX91+VJ5FTI1mcAKGtlRwiQ/QzOz3C0+gEG/qa7US+iozl m17KWdauUaXIbc2ur64Pi8bSjNYB3PAHY7NTNLfLvWP+lWq+HOuhMsrmHDJ6sIHTI5hr1sQ/m8rZp s7/wg1ghCbuVAu409DhVi2wyeYE8khVYLsDOkhjsJkdGylRfBYEnB+isyWFrntYouyWCdBU5auTNg enAOS0YsqzLSZ84HDZqmALMQk0atBQd51VyQxGAjYVix/NPpb9Njyh+heZokoRzFpdNBK5qwF1HXO ehu4WcrNXNd2qg==; From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Ryan Sundberg Subject: Re: [bug#50717] [PATCH] Shepherd: Add respawn-limit paramter to service class. In-Reply-To: (Ryan Sundberg's message of "Tue, 21 Sep 2021 00:42:14 -0700") References: Date: Tue, 02 Jan 2024 23:31:59 +0100 Message-ID: <87il4bgye8.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 50717-done Cc: 50717-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hi Ryan, Ryan Sundberg skribis: > This patch to GNU Shepherd removes the hard-coded respawn limit and > makes it a configurable option. > The respawn limit works generally the same way as before, allowing N > respawns in M seconds: > > #:respawn-limit '(N . M) This is was eventually implemented (independently, oops!) in commit 93baa23baee1e0c62d46d9fd041fc1dabc081f26 (June 2023), which made it in 0.10.2. Thanks, Ludo=E2=80=99. ------------=_1704234781-15483-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 21 Sep 2021 07:42:19 +0000 Received: from localhost ([127.0.0.1]:44756 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mSaPy-0005U4-Uc for submit@debbugs.gnu.org; Tue, 21 Sep 2021 03:42:19 -0400 Received: from lists.gnu.org ([209.51.188.17]:36726) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mSaPx-0005Tv-Lm for submit@debbugs.gnu.org; Tue, 21 Sep 2021 03:42:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60588) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSaPx-0001H1-AN for guix-patches@gnu.org; Tue, 21 Sep 2021 03:42:17 -0400 Received: from mail.arctype.co ([138.68.9.245]:36307) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mSaPv-0001Kr-BN for guix-patches@gnu.org; Tue, 21 Sep 2021 03:42:17 -0400 Received: from authenticated-user (mail.arctype.co [138.68.9.245]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by mail.arctype.co (Postfix) with ESMTPSA id 4898E13B228 for ; Tue, 21 Sep 2021 07:42:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=arctype.co; s=mail; t=1632210134; bh=IYe4WbCIEWLswRwoBw4WT1XBRSJLxIoFOS9Vy3TFBto=; h=From:Subject:To:Date:From; b=eqoyOVcv9RWwYtDHJ9tFDQnHgAQfB8omPz0pxTWdbjn26dlwob/HNPTrnMcsDv510 6BXJCyLslkc37RXSDNibazJwOg8OwjBub4g3T/Boq/6rww/wHDRk5AWKshpPC1nRXA IsXSIk3cs39EwljpNQVE66HlcE0KCSIsI+7CjV2jsYaZ/jgDUIqqMmFBgj8yiIGcFY H9UFY49R4qP4Akdu1ijfMw5io4aoJ9YCsdhSC8I0Bvk5DJEfGC2VVWJfK9D3As+lQr bR4c+uRG2uPlS61l5fISmOdZ7xnvoSSpEe4e5+vtdYtKg1PUJdAwOX+3XC6kOpFQeI gH58NgDzq2Ozg== From: Ryan Sundberg Subject: [PATCH] Shepherd: Add respawn-limit paramter to service class. To: guix-patches@gnu.org Message-ID: Date: Tue, 21 Sep 2021 00:42:14 -0700 MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="5F1MO3h6HH3PTydpZ6m6wRDLrudMvCluj" Received-SPF: pass client-ip=138.68.9.245; envelope-from=ryan@arctype.co; helo=mail.arctype.co X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --5F1MO3h6HH3PTydpZ6m6wRDLrudMvCluj Content-Type: multipart/mixed; boundary="evv5Iw2azlJuHV9aLokrRzq4xIzYp2aRK"; protected-headers="v1" From: Ryan Sundberg To: guix-patches@gnu.org Message-ID: Subject: [PATCH] Shepherd: Add respawn-limit paramter to service class. --evv5Iw2azlJuHV9aLokrRzq4xIzYp2aRK Content-Type: multipart/mixed; boundary="------------C1B8ABC6D3E9CF634893F368" Content-Language: en-US This is a multi-part message in MIME format. --------------C1B8ABC6D3E9CF634893F368 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello Guix devs, This patch to GNU Shepherd removes the hard-coded respawn limit and makes it a configurable option. The respawn limit works generally the same way as before, allowing N respawns in M seconds: #:respawn-limit '(N . M) We can disable respawns by setting N to 0, which will abort the service after the first crash. Likewise, we can always respawn by setting #:respawn-limit #f Sincerely, Ryan Sundberg --------------C1B8ABC6D3E9CF634893F368 Content-Type: text/x-patch; charset=UTF-8; name="0001-service-Add-respawn-limit-paramter-to-the-service-cl.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename*0="0001-service-Add-respawn-limit-paramter-to-the-service-cl.pa"; filename*1="tch" =46rom 94ad8057c6f9a020f12efd78d482b0cf4fe160ec Mon Sep 17 00:00:00 2001 From: Ryan Sundberg Date: Sun, 11 Jul 2021 13:54:04 -0700 Subject: [PATCH] service: Add respawn-limit paramter to the service class= =2E Makes respawn-limit a configurable parameter on service. In addition, we allow the limit to be set to #f to indicate no respawn limit. * modules/shepherd/service.scm: Add respawn-limit --- modules/shepherd/service.scm | 86 +++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm index ad8608b..d741e0b 100644 --- a/modules/shepherd/service.scm +++ b/modules/shepherd/service.scm @@ -134,30 +134,6 @@ ((_) '()))) =20 -;; Respawning CAR times in CDR seconds will disable the service. -;; -;; XXX: The terrible hack in (shepherd) using SIGALRM to work around -;; unreliable SIGCHLD delivery means that it might take up to 1 second f= or -;; SIGCHLD to be delivered. Thus, arrange for the car to be lower than = the -;; cdr. -(define respawn-limit '(5 . 7)) - -(define (respawn-limit-hit? respawns times seconds) - "Return true of RESPAWNS, the list of times at which a given service w= as -respawned, shows that it has been respawned more than TIMES in SECONDS."= - (define now (current-time)) - - ;; Note: This is O(TIMES), but TIMES is typically small. - (let loop ((times times) - (respawns respawns)) - (match respawns - (() - #f) - ((last-respawn rest ...) - (or (zero? times) - (and (> (+ last-respawn seconds) now) - (loop (- times 1) rest))))))) - (define-class () ;; List of provided service-symbols. The first one is also called ;; the `canonical name' and must be unique to this service. @@ -221,7 +197,16 @@ respawned, shows that it has been respawned more tha= n TIMES in SECONDS." (last-respawns #:init-form '()) ;; A replacement for when this service is stopped. (replacement #:init-keyword #:replacement - #:init-value #f)) + #:init-value #f) + ;; Respawning CAR times in CDR seconds will disable the service. + ;; + ;; Respawn limit (times, seconds). Set to #f to disable respawn limits= =2E + ;; XXX: The terrible hack in (shepherd) using SIGALRM to work around + ;; unreliable SIGCHLD delivery means that it might take up to 1 second=20 for + ;; SIGCHLD to be delivered. Thus, arrange for the car to be lower tha= n the + ;; cdr. + (respawn-limit #:init-keyword #:respawn-limit + #:init-value '(5 . 7))) =20 (define (service? obj) "Return true if OBJ is a service." @@ -587,8 +572,6 @@ clients." (define-method (depends-resolved? (obj )) (every lookup-running (required-by obj))) =20 -=0C - (define (launch-service name proc args) "Try to start (with PROC) a service providing NAME; return #f on failu= re. Used by `start' and `enforce'." @@ -648,8 +631,24 @@ results." (apply action service the-action args)) which-services)))) =20 - -=0C +(define-method (respawn-limit-hit? (serv )) + "Return true if service SERV shows that it has been respawned more tha= n it's +respawn-limit TIMES in SECONDS. If the respawn-limit is #f, apply no lim= it." + (match (slot-ref serv 'respawn-limit) + (#f #f) + ((times . seconds) + (let* ((now (current-time)) + (respawns (slot-ref serv 'last-respawns))) + ;; Note: This is O(TIMES), but TIMES is typically small. + (let loop ((times times) + (respawns respawns)) + (match respawns + (() + #f) + ((last-respawn rest ...) + (or (zero? times) + (and (> (+ last-respawn seconds) now) + (loop (- times 1) rest)))))))))) =20 ;; Handling of unprovided service-symbols. This can be called in ;; either of the following ways (i.e. with either three or four @@ -1140,18 +1139,25 @@ attempted to respawn the service a number of time= s already and it keeps dying, then disable it." (slot-set! serv 'running #f) (if (and (respawn? serv) - (not (respawn-limit-hit? (slot-ref serv 'last-respawns) - (car respawn-limit) - (cdr respawn-limit)))) + (not (respawn-limit-hit? serv))) (if (not (slot-ref serv 'waiting-for-termination?)) - (begin - ;; Everything is okay, start it. - (local-output (l10n "Respawning ~a.") - (canonical-name serv)) - (slot-set! serv 'last-respawns - (cons (current-time) - (slot-ref serv 'last-respawns))) - (start serv)) + (match (slot-ref serv 'respawn-limit) + (#f + (begin + (local-output (l10n "Respawning ~a.") + (canonical-name serv)) + (start serv))) + ((respawn-limit-times . _) + (let ((last-respawns (slot-ref serv 'last-respawns))) + ;; Everything is okay, start it. + (local-output (l10n "Respawning ~a.") + (canonical-name serv)) + (slot-set! serv 'last-respawns + (cons (current-time) + ;; Only take the last n times here to pr= event unbounded + ;; list growth + (take last-respawns (min (length last-re= spawns) respawn-limit-times)))) + (start serv)))) ;; We have just been waiting for the ;; termination. The `running' slot has already ;; been set to `#f' by `stop'. --=20 2.31.1 --------------C1B8ABC6D3E9CF634893F368-- --evv5Iw2azlJuHV9aLokrRzq4xIzYp2aRK-- --5F1MO3h6HH3PTydpZ6m6wRDLrudMvCluj Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wsB5BAABCAAjFiEEyVG5Gm1pvFAzyXC2aiMi+MCr96sFAmFJjNYFAwAAAAAACgkQaiMi+MCr96ts mgf5AYCVru8WK6L9+nXfJUepwu3PgkjyQGEgzYneh8vaEOiXdMnsTSlDGv1GirLm/2KeutUui8e4 jlJ3hKLap5WPbTUMUvL5lU73i3iTNam8WucMVJUdyYk45gqQ7drkYrS2U5KTBP3cz5TVV/9fxrMZ lTR6BfWULzRxV5InMElDX7unrKpzwR1KpUPgvdSIppmIq23w6rdFD+/EFV9y0/MBjTCvTt5Qdhkq hX587jggfiwkD/4H7lR5GPnHNuAoKM9Ls7tmjBpHuumDTUkeSqU7OvZf2sIX7y5+DnP+LE4mtPrL uCk7nNtkKMUHIgpD+j5YHfcmyBTZAEkCo7po+QWttg== =xaCP -----END PGP SIGNATURE----- --5F1MO3h6HH3PTydpZ6m6wRDLrudMvCluj-- ------------=_1704234781-15483-1--