From patchwork Sat Apr 9 09:13:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 38463 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 697F327BBEB; Sat, 9 Apr 2022 10:14:12 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 1B10F27BBEA for ; Sat, 9 Apr 2022 10:14:12 +0100 (BST) Received: from localhost ([::1]:42044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nd7AZ-0008SL-6Z for patchwork@mira.cbaines.net; Sat, 09 Apr 2022 05:14:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nd7AQ-0008RW-PJ for guix-patches@gnu.org; Sat, 09 Apr 2022 05:14:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:42823) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nd7AQ-0003lR-Gi for guix-patches@gnu.org; Sat, 09 Apr 2022 05:14:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nd7AQ-0008Nz-C7 for guix-patches@gnu.org; Sat, 09 Apr 2022 05:14:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54811] [PATCH 1/3] publish: Use SRFI-71 instead of SRFI-11. References: <20220409091246.6979-1-ludo@gnu.org> In-Reply-To: <20220409091246.6979-1-ludo@gnu.org> Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 09 Apr 2022 09:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54811 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 54811@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 54811-submit@debbugs.gnu.org id=B54811.164949563632188 (code B ref 54811); Sat, 09 Apr 2022 09:14:02 +0000 Received: (at 54811) by debbugs.gnu.org; 9 Apr 2022 09:13:56 +0000 Received: from localhost ([127.0.0.1]:36713 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nd7AH-0008My-Tx for submit@debbugs.gnu.org; Sat, 09 Apr 2022 05:13:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:60498) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nd7AG-0008Mg-II for 54811@debbugs.gnu.org; Sat, 09 Apr 2022 05:13:52 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:46960) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nd7AB-0003kD-Ay; Sat, 09 Apr 2022 05:13:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=SryT9h6F89eVe/pvqBP8Y9PIeGCaGEY6hWVl1LI1CLQ=; b=cnL9fjk6yvSJu9 B7Sy+O8Za5J6I1gdHMbUaDDDR80Fi6H1i2UZibJe2RJgui7RhQbN5KhvlLzxT0xFNd2k8x1n27/Ii D2L38dP6gqHhR3V5sJB2crzztdvlU+1xJv8ExGQiT0qap8t4FqxXYIGFHcWDInpZ297Xh0FCGjS91 Uvm/dCWWz/f0naPMm6e5ixW3ojE9m4euQSWhz4jZ1H7fDuiU2kn3Q7zIUEXLDjS8tD4/BsqBGsWif t/UbjiHHC9AltQnRWWZ3O+uGdPdhaeIRv8uIhBSBc3DaKW49AmJeHOEV7E+EEBtfEl3Ta6G5O/65J rb4u7sVP4LXB0KPsTF7w==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:58682 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nd7AA-00086k-V0; Sat, 09 Apr 2022 05:13:47 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Sat, 9 Apr 2022 11:13:38 +0200 Message-Id: <20220409091340.7013-1-ludo@gnu.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/scripts/publish.scm (make-request-handler): Use 'let' instead of 'let-values'. --- guix/scripts/publish.scm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/guix/scripts/publish.scm b/guix/scripts/publish.scm index 870dfc11e9..d6eb65d912 100644 --- a/guix/scripts/publish.scm +++ b/guix/scripts/publish.scm @@ -36,11 +36,11 @@ (define-module (guix scripts publish) #:use-module (srfi srfi-2) #:use-module (srfi srfi-9) #:use-module (srfi srfi-9 gnu) - #:use-module (srfi srfi-11) #:use-module (srfi srfi-19) #:use-module (srfi srfi-26) #:use-module (srfi srfi-34) #:use-module (srfi srfi-37) + #:use-module (srfi srfi-71) #:use-module (web http) #:use-module (web request) #:use-module (web response) @@ -1190,8 +1190,7 @@ (define (handle request body) ;; Preserve the request's 'connection' header in the response, so that the ;; server can close the connection if this is requested by the client. (lambda (request body) - (let-values (((response response-body) - (handle request body))) + (let ((response response-body (handle request body))) (values (preserve-connection-headers request response) response-body)))) From patchwork Sat Apr 9 09:13:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 38465 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 5FB7C27BBEA; Sat, 9 Apr 2022 10:14:29 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id AB20A27BBE9 for ; Sat, 9 Apr 2022 10:14:28 +0100 (BST) Received: from localhost ([::1]:42484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nd7Ap-0000Jv-TU for patchwork@mira.cbaines.net; Sat, 09 Apr 2022 05:14:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nd7AR-0008Rf-7c for guix-patches@gnu.org; Sat, 09 Apr 2022 05:14:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:42824) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nd7AQ-0003lX-Sx for guix-patches@gnu.org; Sat, 09 Apr 2022 05:14:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nd7AQ-0008O6-OM for guix-patches@gnu.org; Sat, 09 Apr 2022 05:14:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54811] [PATCH 2/3] publish: Support systemd-style socket activation. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 09 Apr 2022 09:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54811 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 54811@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 54811-submit@debbugs.gnu.org id=B54811.164949563632200 (code B ref 54811); Sat, 09 Apr 2022 09:14:02 +0000 Received: (at 54811) by debbugs.gnu.org; 9 Apr 2022 09:13:56 +0000 Received: from localhost ([127.0.0.1]:36717 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nd7AJ-0008N9-Sr for submit@debbugs.gnu.org; Sat, 09 Apr 2022 05:13:56 -0400 Received: from eggs.gnu.org ([209.51.188.92]:60502) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nd7AH-0008Mj-O2 for 54811@debbugs.gnu.org; Sat, 09 Apr 2022 05:13:54 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:46962) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nd7AC-0003kJ-3u; Sat, 09 Apr 2022 05:13:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=mcz6YpA7Hu7KEGV4Jv5P7pYYDW3UJVMKZC+bJW6fRIs=; b=H8QmrEQS/MbUV8uKXj5i Y6OG+T2K1YFxf+TW5z4Bwnd0LDHfIpEjJ3aCNKQDOsyxYAScvFP6jID2SUh6SlQcegVa+EtHbb18g ViY0Pw+7FCpbXbSSfQ6Rx34HBRbI9J8LpjMYEDmG0lTl80J9wQFLuwFmahZYwUUHzl/9wHT0vSkyq efeTVoGkTF4hrzU8L8ubCYQjOAk+Lc2JiByPSLDR2qjLvYJSpGvIgOPIzful6A1HE8T3Ng31p3831 agNoBrDUuPfP33TjW8/AO3kFMiT+VkcvQ91jhc7kjFhHktrjrrX/BJ3COVIzWdMRot9I+PXLHArsD f1bNoTt4jtsr2g==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:58682 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nd7AB-00086k-Ho; Sat, 09 Apr 2022 05:13:47 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Sat, 9 Apr 2022 11:13:39 +0200 Message-Id: <20220409091340.7013-2-ludo@gnu.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220409091340.7013-1-ludo@gnu.org> References: <20220409091340.7013-1-ludo@gnu.org> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/scripts/publish.scm (systemd-socket): New procedure. (guix-publish): Add 'style' variable. Adjust startup message depending on whether STYLE is 'systemd. * doc/guix.texi (Invoking guix publish): Mention socket activation. --- doc/guix.texi | 5 +++++ guix/scripts/publish.scm | 34 +++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 59db00e581..16bd858a3b 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -14041,6 +14041,11 @@ spawn an HTTP server on port 8080: guix publish @end example +@cindex socket activation, for @command{guix publish} +@command{guix publish} can also be started following the systemd +``socket activation'' protocol (@pxref{Service De- and Constructors, +@code{make-systemd-constructor},, shepherd, The GNU Shepherd Manual}). + Once a publishing server has been authorized, the daemon may download substitutes from it. @xref{Getting Substitutes from Other Servers}. diff --git a/guix/scripts/publish.scm b/guix/scripts/publish.scm index d6eb65d912..a4b9565f91 100644 --- a/guix/scripts/publish.scm +++ b/guix/scripts/publish.scm @@ -1235,6 +1235,23 @@ (define (open-server-socket address) (bind sock address) sock)) +(define (systemd-socket) + "If this program is being spawned through systemd-style \"socket +activation\", whereby the listening socket is passed as file descriptor 3, +return the corresponding socket." + (and (equal? (and=> (getenv "LISTEN_PID") string->number) + (getpid)) + (match (getenv "LISTEN_FDS") + ((= string->number 1) + (let ((sock (fdopen 3 "r+0"))) + (configure-socket sock) + sock)) + ((= string->number (? integer? n)) + (leave (G_ "~a: unexpected number of startup file descriptors") + n)) + (_ + #f)))) + (define (gather-user-privileges user) "Switch to the identity of USER, a user name." (catch 'misc-error @@ -1280,7 +1297,12 @@ (define-command (guix-publish . args) (make-socket-address (sockaddr:fam addr) (sockaddr:addr addr) port))) - (socket (open-server-socket address)) + (socket style (match (systemd-socket) + (#f + (values (open-server-socket address) + 'normal)) + (socket + (values socket 'systemd)))) (nar-path (assoc-ref opts 'nar-path)) (repl-port (assoc-ref opts 'repl)) (cache (assoc-ref opts 'cache)) @@ -1305,10 +1327,12 @@ (define-command (guix-publish . args) (cache-bypass-threshold (or (assoc-ref opts 'cache-bypass-threshold) (cache-bypass-threshold)))) - (info (G_ "publishing ~a on ~a, port ~d~%") - %store-directory - (inet-ntop (sockaddr:fam address) (sockaddr:addr address)) - (sockaddr:port address)) + (if (eq? style 'systemd) + (info (G_ "publishing (started via socket activation)~%")) + (info (G_ "publishing ~a on ~a, port ~d~%") + %store-directory + (inet-ntop (sockaddr:fam address) (sockaddr:addr address)) + (sockaddr:port address))) (for-each (lambda (compression) (info (G_ "using '~a' compression method, level ~a~%") From patchwork Sat Apr 9 09:13:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 38464 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 3BD2527BBEB; Sat, 9 Apr 2022 10:14:29 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id BFA6D27BBEA for ; Sat, 9 Apr 2022 10:14:28 +0100 (BST) Received: from localhost ([::1]:42472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nd7Ap-0000Jf-Tm for patchwork@mira.cbaines.net; Sat, 09 Apr 2022 05:14:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nd7AR-0008Rp-HG for guix-patches@gnu.org; Sat, 09 Apr 2022 05:14:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:42825) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nd7AR-0003lc-8K for guix-patches@gnu.org; Sat, 09 Apr 2022 05:14:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nd7AR-0008OE-4G for guix-patches@gnu.org; Sat, 09 Apr 2022 05:14:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54811] [PATCH 3/3] daemon: Support systemd-style socket activation. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 09 Apr 2022 09:14:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54811 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 54811@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 54811-submit@debbugs.gnu.org id=B54811.164949563732210 (code B ref 54811); Sat, 09 Apr 2022 09:14:03 +0000 Received: (at 54811) by debbugs.gnu.org; 9 Apr 2022 09:13:57 +0000 Received: from localhost ([127.0.0.1]:36719 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nd7AL-0008NR-Eu for submit@debbugs.gnu.org; Sat, 09 Apr 2022 05:13:57 -0400 Received: from eggs.gnu.org ([209.51.188.92]:60506) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nd7AJ-0008Mm-Ms for 54811@debbugs.gnu.org; Sat, 09 Apr 2022 05:13:56 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:46964) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nd7AC-0003kN-Mv; Sat, 09 Apr 2022 05:13:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=aXuSOoUD9PFCYxpT6+JbDOPQcLH7omCCf5f8oHqBu1s=; b=j/BNaR5/P/EASeBJz0or jXIueR6NdAmbjp214A9ODRbBY2GzWZXS8EX5Fr/767LQo3toaYpzq4KWFbftTTky7tnVovcKu1e/T dxJXCFNC60zxSuqMEWr9ckbHzZF+tSmkMuvwD9YOV7jKRgRQLKNKgpW1O/IssUrGCtX8zbCQXNvw9 VTB5xRAvDvdg6aJeRs78QxB1P9VfLvKbAio61gTR3TW/gg9DVuoY9LOMVLAZJAs52ZZTh1bFho4LX N+ADNazKHTlUNb9jwDUfx/lVFMQ1v+OJqnstq9AxiJtHzvZAgXCPAHUzOG6xZ4xTn/EA7ZyDM4KCd g2R3saDgryIMsA==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:58682 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nd7AC-00086k-AM; Sat, 09 Apr 2022 05:13:48 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Sat, 9 Apr 2022 11:13:40 +0200 Message-Id: <20220409091340.7013-3-ludo@gnu.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220409091340.7013-1-ludo@gnu.org> References: <20220409091340.7013-1-ludo@gnu.org> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * nix/nix-daemon/guix-daemon.cc (SD_LISTEN_FDS_START): New macro. (systemd_activation_sockets): New function. (main): Use it. Remove obsolete 'printMsg' call. * doc/guix.texi (Invoking guix-daemon): Document socket activation. --- doc/guix.texi | 6 ++++- nix/nix-daemon/guix-daemon.cc | 42 ++++++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 16bd858a3b..81fec35eb7 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -1554,7 +1554,11 @@ is normally run as @code{root} like this: # guix-daemon --build-users-group=guixbuild @end example -@noindent +@cindex socket activation, for @command{guix-daemon} +This daemon can also be started following the systemd ``socket +activation'' protocol (@pxref{Service De- and Constructors, +@code{make-systemd-constructor},, shepherd, The GNU Shepherd Manual}). + For details on how to set it up, @pxref{Setting Up the Daemon}. @cindex chroot diff --git a/nix/nix-daemon/guix-daemon.cc b/nix/nix-daemon/guix-daemon.cc index 36a06a3fae..d7ab9c5e64 100644 --- a/nix/nix-daemon/guix-daemon.cc +++ b/nix/nix-daemon/guix-daemon.cc @@ -1,5 +1,5 @@ /* GNU Guix --- Functional package management for GNU - Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2021 Ludovic Courtès + Copyright (C) 2012-2019, 2021-2022 Ludovic Courtès Copyright (C) 2006, 2010, 2012, 2014 Eelco Dolstra This file is part of GNU Guix. @@ -434,6 +434,31 @@ listening_sockets (const std::list &options) return result; } +/* First file descriptor provided at startup using systemd-style socket + activation. */ +#define SD_LISTEN_FDS_START 3 + +/* Return a list of file descriptors of listening sockets provided following + the systemd "socket activation" protocol. Return the empty list if we are + not being socket-activated. */ +static std::vector +systemd_activation_sockets () +{ + std::vector result; + + if (getEnv ("LISTEN_PID") == std::to_string (getpid ())) + { + unsigned int fdCount; + if (string2Int (getEnv ("LISTEN_FDS"), fdCount)) + { + for (unsigned int i = 0; i < fdCount; i++) + result.push_back (SD_LISTEN_FDS_START + i); + } + } + + return result; +} + int main (int argc, char *argv[]) @@ -494,7 +519,17 @@ main (int argc, char *argv[]) argp_parse (&argp, argc, argv, 0, 0, 0); - auto sockets = listening_sockets (listen_options); + auto sockets = systemd_activation_sockets (); + if (sockets.empty ()) + /* We were not "socket-activated" so open the sockets specified by + LISTEN_OPTIONS. */ + sockets = listening_sockets (listen_options); + else + printMsg (lvlInfo, + format (ngettext ("socket-activated with %1% socket", + "socket-activated with %1% sockets", + sockets.size ())) + % sockets.size ()); /* Effect all the changes made via 'settings.set'. */ settings.update (); @@ -531,9 +566,6 @@ using `--build-users-group' is highly recommended\n")); format ("automatic deduplication set to %1%") % settings.autoOptimiseStore); - printMsg (lvlDebug, - format ("listening on `%1%'") % settings.nixDaemonSocketFile); - run (sockets); } catch (std::exception &e)