From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51571) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fpKi3-0005vV-5v for guix-patches@gnu.org; Mon, 13 Aug 2018 17:49:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fpKhy-0003dl-6F for guix-patches@gnu.org; Mon, 13 Aug 2018 17:49:07 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:44973) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fpKhy-0003dh-2I for guix-patches@gnu.org; Mon, 13 Aug 2018 17:49:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fpKhx-0007tV-Sj for guix-patches@gnu.org; Mon, 13 Aug 2018 17:49:01 -0400 Subject: [bug#32433] [PATCH] services: nginx: Get the Shepherd to respawn NGINX. Resent-Message-ID: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51440) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fpKhE-0005t5-R0 for guix-patches@gnu.org; Mon, 13 Aug 2018 17:48:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fpKh9-0003QI-Vs for guix-patches@gnu.org; Mon, 13 Aug 2018 17:48:16 -0400 Received: from mail.lassieur.org ([83.152.10.219]:54140) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fpKh9-0003OV-L3 for guix-patches@gnu.org; Mon, 13 Aug 2018 17:48:11 -0400 Received: from localhost.localdomain (88.191.118.83 [88.191.118.83]) by mail.lassieur.org (OpenSMTPD) with ESMTPSA id 8c7e18e8 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO) for ; Mon, 13 Aug 2018 21:48:05 +0000 (UTC) From: =?UTF-8?Q?Cl=C3=A9ment?= Lassieur Date: Mon, 13 Aug 2018 23:47:50 +0200 Message-Id: <20180813214750.714-1-clement@lassieur.org> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 32433@debbugs.gnu.org * gnu/services/web.scm (nginx-shepherd-service): Change 'start' (that is, all actions that don't send a signal to the master process) to return the PID. Wait until the PID file is created and contains an integer because it might be created after the parent process exits. --- gnu/services/web.scm | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/gnu/services/web.scm b/gnu/services/web.scm index 97976509b..467656444 100644 --- a/gnu/services/web.scm +++ b/gnu/services/web.scm @@ -599,19 +599,33 @@ of index files." (nginx file run-directory) (let* ((nginx-binary (file-append nginx "/sbin/nginx")) + (pid-file (in-vicinity run-directory "pid")) (nginx-action (lambda args #~(lambda _ (invoke #$nginx-binary "-c" #$(or file (default-nginx-config config)) - #$@args))))) + #$@args) + (match '#$args + (("-s" . _) #t) + (_ + (let loop ((duration 0)) + ;; https://bugs.launchpad.net/ubuntu/+source/nginx/+bug/1581864/comments/7 + (sleep duration) + (if (file-exists? #$pid-file) + (let ((pid (call-with-input-file #$pid-file read))) + ;; it could be # + (if (integer? pid) pid (loop 1))) + (loop 1))))))))) ;; TODO: Add 'reload' action. (list (shepherd-service (provision '(nginx)) (documentation "Run the nginx daemon.") (requirement '(user-processes loopback)) + (modules `((ice-9 match) + ,@%default-modules)) (start (nginx-action "-p" run-directory)) (stop (nginx-action "-s" "stop"))))))) -- 2.18.0