From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id sGWnEK+aeGY8EAEAe85BDQ:P1 (envelope-from ) for ; Sun, 23 Jun 2024 21:59:11 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id sGWnEK+aeGY8EAEAe85BDQ (envelope-from ) for ; Sun, 23 Jun 2024 23:59:11 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=eEUIkEGb; 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"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1719179951; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=nLRi1sleptdKRENL8H/eVhUC8arre3b/oXNR+s4lKFs=; b=TyrYg8S4iaTP2JAFcrnHgV912Kopml9EYBM8ai7Z33WZfXS9sPPJLG8/feHAyHwyyWpL11 2hJ5Zh7Xcu7mX/UYOSTbk1NR9+2eDym2m0wykO9vVkOR6/kQ+1h+o0aeMLQUQ1tVttS4WD ebezaJbDYziBdmcp34qDTu0EqxzliwncOWP6OF4oa7KNHebnxPfKC2rtYK58nNlK4jIka6 6bDHnK5Q0nJ62KmRTbT2txQfkOZrmgVg4Ed2WvpWpCgPJPD+6nQkjmdxjwi94GgSIV6zMb XHAEWr6EjJpcFMMtNpdqrUPVdUFOY8R0jwIDO0ivHeE+LXeSmUd5KQSiy1Pjdw== 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=eEUIkEGb; 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"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1719179951; a=rsa-sha256; cv=none; b=qBRJZeoCvbtF0PmTEOIg6dJhEWKK9F8lVVB8Ie1kgNs5IwpQxI2QceKZCZkofQfn13Oz0n Dl47vYOTg8e5DXEfmVH0n2dAmzRVAv25uV4fqati94umWBe5WhHrJ11dTTdcYXQhyfvElz fokVwi99ogo8oDy7nX05Qm1qm+5YUvyw9KPheyA1mGuiJeapmWVWC9TqLuzCxZo+qsYElY Ks/a1FTrCCB31trswdPPB2f/chfdomYZbl+ogwR8zS/hpA0aQD8EyqJw+SsHEn7LXgWCSY I/vmBK/OA2juC9UE64dQgOj+SzrI1peXdLSMEktT+ztEnDFlGx5gUqIFYLnZuw== 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 9060C15DB3 for ; Sun, 23 Jun 2024 23:59:10 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLVEm-0005Zu-Qy; Sun, 23 Jun 2024 17:59:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sLVEl-0005ZV-9v for guix-patches@gnu.org; Sun, 23 Jun 2024 17:59:03 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLVEl-0005gd-0U; Sun, 23 Jun 2024 17:59:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sLVEk-00036A-P9; Sun, 23 Jun 2024 17:59:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#71739] [PATCH] services: shepherd: Support =?UTF-8?Q?=E2=80=9Cfree-form=E2=80=9D?= services. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: pelzflorian@pelzflorian.de, ludo@gnu.org, matt@excalamus.com, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Sun, 23 Jun 2024 21:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 71739 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 71739@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Florian Pelz , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Matthew Trzcinski , Maxim Cournoyer X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: Florian Pelz , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Matthew Trzcinski , Maxim Cournoyer Received: via spool by submit@debbugs.gnu.org id=B.171917992111838 (code B ref -1); Sun, 23 Jun 2024 21:59:02 +0000 Received: (at submit) by debbugs.gnu.org; 23 Jun 2024 21:58:41 +0000 Received: from localhost ([127.0.0.1]:53108 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sLVEP-00034q-3V for submit@debbugs.gnu.org; Sun, 23 Jun 2024 17:58:41 -0400 Received: from lists.gnu.org ([209.51.188.17]:58396) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sLVEN-00034g-DJ for submit@debbugs.gnu.org; Sun, 23 Jun 2024 17:58:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sLVEM-0005Xo-GW for guix-patches@gnu.org; Sun, 23 Jun 2024 17:58:38 -0400 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 1sLVEM-0005ff-8a; Sun, 23 Jun 2024 17:58:38 -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=nLRi1sleptdKRENL8H/eVhUC8arre3b/oXNR+s4lKFs=; b=eEUIkEGbOSPsNU NBcUgZz5E8GMDqAa7pXh96//hYEd8+FnNMwNRMIK0AgmpKKGv+UNRiwq7n5JMJFhJJx6r8J7F/i1p kshm3Ls3PQTPfumQVX6YBi5dpeekQZHq5j2LhcSl4i2/U/zNMPu4bFGtQUd4AijM5VWRnZ+dy9PLb oeOiSQBt2pS9aCVvboDsB6KXPAaTfc5ig1y4/zWIRNSJU8ANUV/z6GJ5QAxMSa4XQ1cb/Q88znkXy vOus8EyYoI2HkLxiFFps3UF9qNkdMx7IlMnzHZUo5UjyuzFGiXyKQICLbjZOs4g1tXgRF0tsjkK0f 0KrwLuDmli4A09w2AYOg==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Sun, 23 Jun 2024 23:58:30 +0200 Message-ID: <7501182c5831ba86d4e600967fb944e9e1124352.1719066498.git.ludo@gnu.org> X-Mailer: git-send-email 2.45.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Queue-Id: 9060C15DB3 X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -4.76 X-Spam-Score: -4.76 X-TUID: j5oz2j+pyQFx Message-ID: <20240623215830.8YhIUpuEMHpuu_2kvg8l-OwTcCAN3KuPXP8tOa3LtqI@z> * gnu/services/shepherd.scm ()[free-form]: New field. [start]: Add default value. (shepherd-service-file): Rename to… (shepherd-service-file/regular): … this. (shepherd-service-file/free-form): New procedure. (shepherd-service-file): Dispatch to one of the two procedures above. * doc/guix.texi (Shepherd Services): Document the ‘free-form’ field. Change-Id: I206374e950ef6d1e4a996c0f507fb5fcd9cadde3 --- doc/guix.texi | 26 +++++++++++++++++++++++++- gnu/services/shepherd.scm | 25 ++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 4 deletions(-) Hi! This patch fixes a limitation that became apparent with Shepherd 0.10, where users could not instantiate services from the built-in service collection for which they do not explicitly specify the ‘start’ and ‘stop’ methods (see REPL service example below). Thoughts? Ludo’. diff --git a/doc/guix.texi b/doc/guix.texi index 0102fd0fad3..4d9145445cc 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -43909,7 +43909,7 @@ Shepherd Services When true, this is the delay in seconds before restarting a failed service. -@item @code{start} +@item @code{start} (default: @code{#~(const #t)}) @itemx @code{stop} (default: @code{#~(const #f)}) The @code{start} and @code{stop} fields refer to the Shepherd's facilities to start and stop processes (@pxref{Service De- and @@ -43928,6 +43928,30 @@ Shepherd Services herd @var{action} @var{service} [@var{arguments}@dots{}] @end example +@item @code{free-form} (default: @code{#f}) +When set, this field replaces the @code{start}, @code{stop}, and +@code{actions} fields. It is meant to be used when the service +definition comes from some other source, typically the service +collection provided by the Shepherd proper (@pxref{Service Collection,,, +shepherd, The GNU Shepherd Manual}). + +@cindex REPL service, for shepherd +For example, the snippet below defines a service for the Shepherd's +built-in @acronym{REPL, read-eval-print loop} service (@pxref{REPL +Service,,, shepherd, The GNU Shepherd Manual}): + +@lisp +(shepherd-service + (provision '(repl)) + (modules '((shepherd service repl))) + (free-form #~(repl-service))) +@end lisp + +In this case, the service object is returned by the @code{repl-service} +procedure of the Shepherd, so all the @code{free-form} G-expression does +is call that procedure. Note that the @code{provision} field must be +consistent with the actual service provision. + @item @code{auto-start?} (default: @code{#t}) Whether this service should be started automatically by the Shepherd. If it is @code{#f} the service has to be started manually with @code{herd start}. diff --git a/gnu/services/shepherd.scm b/gnu/services/shepherd.scm index ccc8e61a33c..05534ab3173 100644 --- a/gnu/services/shepherd.scm +++ b/gnu/services/shepherd.scm @@ -60,6 +60,7 @@ (define-module (gnu services shepherd) shepherd-service-respawn? shepherd-service-start shepherd-service-stop + shepherd-service-free-form shepherd-service-auto-start? shepherd-service-modules @@ -217,7 +218,10 @@ (define-record-type* (default #f)) (respawn-delay shepherd-service-respawn-delay (default #f)) - (start shepherd-service-start) ;g-expression (procedure) + (free-form shepherd-service-free-form ;#f | g-expression (service) + (default #f)) + (start shepherd-service-start ;g-expression (procedure) + (default #~(const #t))) (stop shepherd-service-stop ;g-expression (procedure) (default #~(const #f))) (actions shepherd-service-actions ;list of @@ -298,8 +302,8 @@ (define (shepherd-service-file-name service) provisions) ".scm"))) -(define (shepherd-service-file service) - "Return a file defining SERVICE." +(define (shepherd-service-file/regular service) + "Return a file defining SERVICE, a service whose 'free-form' field is #f." (scheme-file (shepherd-service-file-name service) (with-imported-modules %default-imported-modules #~(begin @@ -332,6 +336,21 @@ (define (shepherd-service-file service) #~(#$name #$doc #$proc))) (shepherd-service-actions service)))))))) +(define (shepherd-service-file/free-form service) + "Return a file defining SERVICE, a service whose 'free-form' field is set." + (scheme-file (shepherd-service-file-name service) + (with-imported-modules %default-imported-modules + #~(begin + (use-modules #$@(shepherd-service-modules service)) + + #$(shepherd-service-free-form service))))) + +(define (shepherd-service-file service) + "Return a file defining SERVICE." + (if (shepherd-service-free-form service) + (shepherd-service-file/free-form service) + (shepherd-service-file/regular service))) + (define (scm->go file shepherd) "Compile FILE, which contains code to be loaded by shepherd's config file, and return the resulting '.go' file. SHEPHERD is used as shepherd package." base-commit: 2aeb37def258ad4dd23aaf57ed32f0be44d1bea5 -- 2.45.1