From patchwork Fri Jan 17 22:19:20 2025 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: 37124 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 A82ED27BBEA; Fri, 17 Jan 2025 22:21:43 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham 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 18C0C27BBE2 for ; Fri, 17 Jan 2025 22:21:43 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tYuiE-0006Gi-Gm; Fri, 17 Jan 2025 17:21:10 -0500 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 1tYuiC-0006Fj-Fw for guix-patches@gnu.org; Fri, 17 Jan 2025 17:21:08 -0500 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 1tYuiC-0002hT-74; Fri, 17 Jan 2025 17:21:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=hauk8xGQY6hjAZ9vhh9Qk3SigJI9htiY0MI/z856ATU=; b=vwn1YMQFC9kvoGjYp/PD1SMl+03KsClzcPKzxGdVEWl4Bpa0Ph+HFK/PQ/TO+lqFezz/ledcaHRNr/RCAvuChSjP62nnEJVoVhyvTnyb/HC/Rm0nyWvzbTSvivUc3f59NWK9p7//t7ml+Ws8osaOurx/2iEWeVmqXGArtGU0E2Q84T2UEZIPdDKM1HNc4GhUnbHKOlXqEuw64iONJTNifTgrMbfb6ykTGu28VNe8JH6S4717Pe92pRKipJAk0BMGnVQtk9ZF8BU07Z7oU5MdusFgCXm388VpZPREv3hG1KHKfb5EUNadyi7YRS4PQsr6MOZheD+1EQYqcTITOKOjTQ==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tYui5-0002YG-LB; Fri, 17 Jan 2025 17:21:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74997] [PATCH 1/4] services: shepherd: Add =?utf-8?b?4oCYdHJh?= =?utf-8?b?bnNpZW504oCZ?= and =?utf-8?b?4oCYdGltZXLigJku?= Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: herman@rimm.ee, ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Fri, 17 Jan 2025 22:21:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74997 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 74997@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , Herman Rimm , Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Herman Rimm , Ludovic =?utf-8?q?Cour?= =?utf-8?q?t=C3=A8s?= , Maxim Cournoyer Received: via spool by 74997-submit@debbugs.gnu.org id=B74997.17371524069348 (code B ref 74997); Fri, 17 Jan 2025 22:21:01 +0000 Received: (at 74997) by debbugs.gnu.org; 17 Jan 2025 22:20:06 +0000 Received: from localhost ([127.0.0.1]:39125 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tYuhA-0002QE-CL for submit@debbugs.gnu.org; Fri, 17 Jan 2025 17:20:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35810) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tYuh6-0002P0-Ih for 74997@debbugs.gnu.org; Fri, 17 Jan 2025 17:20:02 -0500 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 1tYuh1-0002L6-A0; Fri, 17 Jan 2025 17:19:55 -0500 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=hauk8xGQY6hjAZ9vhh9Qk3SigJI9htiY0MI/z856ATU=; b=bBCGOGjgJz9h74kZgoLd WtXuvAoYQjWS6ZRWgXoo9HZt7Xyfa5Y3xo3Bm5oiY0c6fqqKLiEqciFH8hewf1eMlKMxsmCpOeXP0 lMgXT6mtr3Ocs9pSutD0iOiBxmCnx5/OvU6yLMYKU9N+aRq++zmSJQWYQqzZ+wt6reTPuWvpIbEh7 3atANJoloa4XYThTYE4OYfL+c0GswBu41Ih1MCpOl71NDlu6Pr/Q1hrKB+MVi31CzOPulYJjaEHE8 zEuSgriAfjxTN2aOPn6zxrkI91U8zf11bnE/Os53rlC1vIt45opH6JpEjDq9HQ/FkafgUXv0TxU04 imDPTfYeH65lPw==; From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Fri, 17 Jan 2025 23:19:20 +0100 Message-ID: X-Mailer: git-send-email 2.47.1 In-Reply-To: References: 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-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/services/shepherd.scm (shepherd-timer-service-type) (shepherd-transient-service-type): New variables. * doc/guix.texi (Shepherd Services): Document them. Change-Id: I9b622e7e947e7a6384c2701a313d0c7080a0a5f6 Reviewed-by: Maxim Cournoyer --- doc/guix.texi | 33 ++++++++++++++++++++++++ gnu/services/shepherd.scm | 54 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 0015d739bb..3e377ca9f4 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -45684,6 +45684,39 @@ Shepherd Services (shepherd my-shepherd)))))) @end lisp +@cindex @code{transient} service, Shepherd +@defvar shepherd-transient-service-type +This service type represents the Shepherd's @code{transient} service, +which lets you spawn commands in the background and interact with them +as regular Shepherd service; it is similar to @command{systemd-run}. + +For example, the command below spawns @command{rsync} in the background, +in an environment where the @env{SSH_AUTH_SOCK} environment variable has +the given value: + +@example +herd spawn transient -E SSH_AUTH_SOCK=$SSH_AUTH_SOCK -- \ + rsync -e ssh -vur . backup.example.org: +@end example + +@xref{Transient Service Maker,,, shepherd, The GNU Shepherd Manual}, for +more info on the @code{transient} service. +@end defvar + +@cindex @code{timer} service, Shepherd +@defvar shepherd-timer-service-type +This is the service type representing the Shepherd's @code{timer} +service, which lets you schedule the execution of commands, similar to +the venerable @command{at} command. Here is an example: + +@example +herd schedule timer at 07:00 -- mpg123 Music/alarm.mp3 +@end example + +@xref{Timer Service,,, shepherd, The GNU Shepherd Manual}, for more info +on the @code{timer} service. +@end defvar + @defvar %shepherd-root-service This service represents PID@tie{}1. @end defvar diff --git a/gnu/services/shepherd.scm b/gnu/services/shepherd.scm index 0de3c9c55c..5f2625ac20 100644 --- a/gnu/services/shepherd.scm +++ b/gnu/services/shepherd.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2013-2016, 2018-2024 Ludovic Courtès +;;; Copyright © 2013-2016, 2018-2025 Ludovic Courtès ;;; Copyright © 2017 Clément Lassieur ;;; Copyright © 2018 Carlo Zancanaro ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen @@ -81,6 +81,8 @@ (define-module (gnu services shepherd) shepherd-service-upgrade user-processes-service-type + shepherd-timer-service-type + shepherd-transient-service-type assert-valid-graph)) @@ -668,4 +670,52 @@ (define user-processes-service-type seconds after @code{SIGTERM} has been sent are terminated with @code{SIGKILL}."))) -;;; shepherd.scm ends here + +;;; +;;; Timer and transient service maker. +;;; + +(define shepherd-timer-service-type + (shepherd-service-type + 'shepherd-timer + (const (shepherd-service + (provision '(timer)) + (requirement '(user-processes)) + (modules '((shepherd service timer))) + (free-form #~(timer-service + '#$provision + #:requirement '#$requirement)))) + #t ;ignored + (description "The Shepherd @code{timer} service lets you schedule commands +dynamically, similar to the @code{at} command that your grandparents would use +on that Slackware they got on a floppy disk. For example, consider this +command: + +@example +herd schedule timer at 07:00 -- mpg123 Music/alarm.mp3 +@end example + +It does exactly what you would expect."))) + +(define shepherd-transient-service-type + (shepherd-service-type + 'shepherd-transient + (const (shepherd-service + (provision '(transient)) + (requirement '(user-processes)) + (modules '((shepherd service transient))) + (free-form #~(transient-service + '#$provision + #:requirement '#$requirement)))) + #t ;ignored + (description "The Shepherd @code{transient} service lets you run commands +asynchronously, in the background, similar to @command{systemd-run}, as in +this example: + +@example +herd spawn transient -E SSH_AUTH_SOCK=$SSH_AUTH_SOCK -- \\ + rsync -e ssh -vur . backup.example.org: +@end example + +This runs @command{rsync} in the background, as a service that you can inspect +with @command{herd status} and stop with @command{herd stop}.")))