From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id t7pZOnVOUWJ8aAEAgWs5BA (envelope-from ) for ; Sat, 09 Apr 2022 11:14:29 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id KBfQMXVOUWKmIgAAG6o9tA (envelope-from ) for ; Sat, 09 Apr 2022 11:14:29 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 3BA5714DA0 for ; Sat, 9 Apr 2022 11:14:29 +0200 (CEST) Received: from localhost ([::1]:42484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nd7Aq-0000Jv-Ff for larch@yhetil.org; Sat, 09 Apr 2022 05:14:28 -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 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1649495669; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=mcz6YpA7Hu7KEGV4Jv5P7pYYDW3UJVMKZC+bJW6fRIs=; b=B49g8/excY8bYpY5iHH9vmzBrCELG11x/yIbOST32aRfRMBUHJRKhXrdsPSixAVvKzoVNc r09vaybf/i6YKxpOXWGeVHWYlPEn5Apd1+c2FyGHjYFgVbOxFc4ap1jgzGxwqG1Cd5bEEo 4oSMcG/pcByWmCverHA1fvNJBu8gKD5E8XObv29VJLDkGyeluqVzbBALrkqvGemJikUKKs g8wjrpFLiMKbCpcD1BlKp2aU/8Zk94YeNS14y4VISlTazs5wI6fv9ZMItbqMObAz/98eUi 6iSB06SK96zM1jl8wgopy0FDOEmHswAK1BIYJO9bWBd7WncT3l9HFVJu5t3APw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1649495669; a=rsa-sha256; cv=none; b=RpoBzyLXfij1L8hUpSxxK184eyGY7IHMr0RxYF2/OaSvBZeLJXMA6KBt4hzfkZHEKbDgdN 3EyQI7uyyE7eZYKCy2NNCZR99wAwzvqgOvNtCA2/KrY5oNPQ4Z4XclZmVsg6gOpq93CErH 9FY5SRHo4aAebvySSsKDBBUw3dZId86tT4n2IrI2N5DEs6NCP0H5uPGHM1C4tVgpxQla9S eAWLNASAOjz3Ju93lQF4MbY0B0kgQS7bSyhVUQHClfcSA1YRijwWLVDSv6Fi7K/7G0kSjL tSdX59Gm9Tu/kXEL8UTaGZAgZbA96IT5yu4Jy1X9ImsYflV47x+v1NZZv02/kg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=H8QmrEQS; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -2.47 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=H8QmrEQS; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 3BA5714DA0 X-Spam-Score: -2.47 X-Migadu-Scanner: scn1.migadu.com X-TUID: ncw1qRcMqweA * 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~%") -- 2.35.1