From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id gNl9FGr2gl83XwAA0tVLHw (envelope-from ) for ; Sun, 11 Oct 2020 12:11:22 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id SNJ1EGr2gl/cJAAAbx9fmQ (envelope-from ) for ; Sun, 11 Oct 2020 12:11:22 +0000 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 A8BCB9404D5 for ; Sun, 11 Oct 2020 12:11:21 +0000 (UTC) Received: from localhost ([::1]:51718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRaC7-0007kV-Fo for larch@yhetil.org; Sun, 11 Oct 2020 08:11:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43040) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRaBq-0007kM-36 for guix-patches@gnu.org; Sun, 11 Oct 2020 08:11:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:55960) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kRaBp-0005e2-QA for guix-patches@gnu.org; Sun, 11 Oct 2020 08:11:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kRaBp-00043c-LZ for guix-patches@gnu.org; Sun, 11 Oct 2020 08:11:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#43921] [Shepherd PATCH v2 2/2] Add User Service example. References: <874kn1rtgn.fsf@gnu.org> In-Reply-To: <874kn1rtgn.fsf@gnu.org> Resent-From: "Jan (janneke) Nieuwenhuizen" Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 11 Oct 2020 12:11:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 43921 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 43921@debbugs.gnu.org Cc: Efraim Flashner Received: via spool by 43921-submit@debbugs.gnu.org id=B43921.160241821615526 (code B ref 43921); Sun, 11 Oct 2020 12:11:01 +0000 Received: (at 43921) by debbugs.gnu.org; 11 Oct 2020 12:10:16 +0000 Received: from localhost ([127.0.0.1]:39273 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kRaB1-00042H-Pr for submit@debbugs.gnu.org; Sun, 11 Oct 2020 08:10:16 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36038) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kRaAy-00041z-VZ for 43921@debbugs.gnu.org; Sun, 11 Oct 2020 08:10:10 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:51068) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRaAt-0005Pb-8F; Sun, 11 Oct 2020 08:10:03 -0400 Received: from [2001:980:1b4f:1:42d2:832d:bb59:862] (port=49564 helo=dundal.fritz.box) by fencepost.gnu.org with esmtpa (Exim 4.82) (envelope-from ) id 1kRaAs-0006lK-EU; Sun, 11 Oct 2020 08:10:02 -0400 From: "Jan (janneke) Nieuwenhuizen" Date: Sun, 11 Oct 2020 14:10:00 +0200 Message-Id: <20201011121000.26307-1-janneke@gnu.org> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -1.0 (-) 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-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Spam-Score: 0.99 X-TUID: 0kV3aW5aaIms * modules/shepherd/support.scm: Export %user-cache-dir, %user-config-dir, %user-runtime-dir. * doc/shepherd.texi (User Service examples): Use them in new subsection with example. Co-authored-by: Efraim Flashner --- doc/shepherd.texi | 79 ++++++++++++++++++++++++++++++++++-- modules/shepherd/support.scm | 4 ++ 2 files changed, 79 insertions(+), 4 deletions(-) diff --git a/doc/shepherd.texi b/doc/shepherd.texi index 7c9a739..e6207b3 100644 --- a/doc/shepherd.texi +++ b/doc/shepherd.texi @@ -13,6 +13,7 @@ Copyright @copyright{} @value{OLD-YEARS} Wolfgang J@"ahrling@* Copyright @copyright{} @value{NEW-YEARS} Ludovic Courtès@* Copyright @copyright{} 2020 Brice Waegeneire@* Copyright @copyright{} 2020 Oleg Pykhalov +Copyright @copyright{} 2020 Jan (janneke) Nieuwenhuizen@* Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -146,10 +147,11 @@ configuration file. When it is started with superuser privileges, it tries to use @code{/etc/shepherd.scm}. When started as normal user, it looks for a file called @code{$XDG_CONFIG_HOME/shepherd/init.scm}. If the @code{XDG_CONFIG_HOME} environment variable is not defined, -@code{$HOME/.config/shepherd/init.scm} is used instead. With the option -@code{--config} (or, for short, @code{-c}), you can specify where to -look instead. So if you want to start @command{shepherd} with an -alternative file, use one of the following commands: +@code{$HOME/.config/shepherd/init.scm} is used instead (@pxref{User +Service examples}). With the option @code{--config} (or, for short, +@code{-c}), you can specify where to look instead. So if you want to +start @command{shepherd} with an alternative file, use one of the +following commands: @example shepherd --config=/etc/shepherd.scm.old @@ -1025,6 +1027,75 @@ also specifies some more initial values for the slots: (restart (...))))) @end lisp +@menu +* User Service examples:: +@end menu + +@node User Service examples +@subsection User Service examples + +For starters, use a toplevel @code{$XDG_CONFIG_HOME/shepherd/init.scm} +that looks like this: + +@lisp +;;; Commentary: +;;; +;;; Add to your ~/.bash_profile: +;;; +;;; if [[ ! -S ${XDG_RUN_HOME-$HOME/.cache}/shepherd/socket ]]; then +;;; shepherd +;;; fi +;;; +;;; Code: + +(use-modules (shepherd service) + ((ice-9 ftw) #:select (scandir))) + +;; Load all the files in the directory 'init.d' with a suffix '.scm'. +(for-each + (lambda (file) + (load (string-append "init.d/" file))) + (scandir (string-append (dirname (current-filename)) "/init.d") + (lambda (file) + (string-suffix? ".scm" file)))) + +;; Send shepherd into the background +(action 'shepherd 'daemonize) +@end lisp + +Then, individual user services can be put in +@code{$XDG_CONFIG_HOME/shepherd/init.d/}, e.g., for ssh-agent + +@lisp +;;; Commentary: +;;; +;;; Add to your ~/.bash_profile: +;;; +;;; SSH_AUTH_SOCK=${XDG_RUN_HOME-$HOME/.cache}/ssh-agent/socket +;;; export SSH_AUTH_SOCK +;;; +;;; Code: + +(use-modules (shepherd support)) + +(define ssh-agent + (make + #:provides '(ssh-agent) + #:docstring "Run `ssh-agent'" + #:start (let ((socket-dir (string-append %user-runtime-dir "/ssh-agent"))) + (unless (file-exists? socket-dir) + (mkdir-p socket-dir) + (chmod socket-dir #o700)) + (make-forkexec-constructor + `("ssh-agent" "-D" "-a" ,(string-append socket-dir "/socket")) + #:log-file (string-append %user-cache-dir "/ssh-agent.log"))) + #:stop (make-kill-destructor) + #:respawn? #t)) +(register-services ssh-agent) + +(start ssh-agent) +@end lisp + @c @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @node The root and unknown services diff --git a/modules/shepherd/support.scm b/modules/shepherd/support.scm index fe64a05..bf34ada 100644 --- a/modules/shepherd/support.scm +++ b/modules/shepherd/support.scm @@ -61,6 +61,10 @@ persistency persistency-state-file + %user-cache-dir + %user-config-dir + %user-runtime-dir + verify-dir)) (define-syntax-rule (if-2.0 subsequent alternate) -- Jan Nieuwenhuizen | GNU LilyPond http://lilypond.org Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.com