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~%")