all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: Guix-devel <guix-devel@gnu.org>
Subject: One-shot Shepherd services
Date: Thu, 18 Apr 2019 23:38:41 +0200	[thread overview]
Message-ID: <87ftqfngda.fsf@gnu.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 1188 bytes --]

Hello Guix!

Today I added support for “one-shot” services in the Shepherd:

  https://git.savannah.gnu.org/cgit/shepherd.git/commit/?id=c121eedfff7a50feddcf08e173d2b0dd807e8804

One-shot services start, perform a short action, and are immediately
marked as “stopped.”  (systemd has something similar:
<https://www.freedesktop.org/software/systemd/man/systemd.service.html>.)

The use case is initialization or cleanup actions like the ‘user-homes’
service.  So far ‘user-homes’ is a regular service whose ‘start’ method
always fails; as a result, we always see this message:

  Service user-homes could not be started.

From there on, we’ll be able to mark this service as one-shot (patch
below), and thus shepherd will notice that it successfully started (or
not) and yet mark it as stopped, which was always the intent.

There are other cases where this could be useful.  For instance, we
could turn service activation snippets into one-shot services.

Since this augments the Shepherd API, I plan to release it as 0.6.0
in time for Guix 1.0.  It contains other rather minor changes compared
to 0.5.0.

Feedback welcome!

Ludo’.


[-- Attachment #2: Type: text/x-patch, Size: 4077 bytes --]

diff --git a/gnu/packages/admin.scm b/gnu/packages/admin.scm
index 3a250eeaa8..6b26da7316 100644
--- a/gnu/packages/admin.scm
+++ b/gnu/packages/admin.scm
@@ -45,6 +45,7 @@
   #:use-module (guix packages)
   #:use-module (guix utils)
   #:use-module (guix download)
+  #:use-module ((guix gexp) #:select (local-file))
   #:use-module (guix git-download)
   #:use-module (guix build-system cmake)
   #:use-module (guix build-system emacs)
@@ -192,6 +193,7 @@ and provides a \"top-like\" mode (monitoring).")
     (build-system gnu-build-system)
     (arguments
      '(#:configure-flags '("--localstatedir=/var")))
+    (replacement shepherd-next)
     (native-inputs
      `(("pkg-config" ,pkg-config)
 
@@ -214,6 +216,12 @@ interface and is based on GNU Guile.")
     (home-page "https://www.gnu.org/software/shepherd/")
     (properties '((ftp-server . "alpha.gnu.org")))))
 
+(define-public shepherd-next
+  (package
+    (inherit shepherd)
+    (version "0.5.1")
+    (source (local-file "/data/src/shepherd/shepherd-0.6.0-pre1.tar.gz"))))
+
 (define-public daemontools
   (package
     (name "daemontools")
diff --git a/gnu/services/shepherd.scm b/gnu/services/shepherd.scm
index 12d649f542..cf7e64a783 100644
--- a/gnu/services/shepherd.scm
+++ b/gnu/services/shepherd.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2013, 2014, 2015, 2016, 2018 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2013, 2014, 2015, 2016, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2017 Clément Lassieur <clement@lassieur.org>
 ;;; Copyright © 2018 Carlo Zancanaro <carlo@zancanaro.id.au>
 ;;;
@@ -44,6 +44,7 @@
             shepherd-service-provision
             shepherd-service-canonical-name
             shepherd-service-requirement
+            shepherd-service-one-shot?
             shepherd-service-respawn?
             shepherd-service-start
             shepherd-service-stop
@@ -149,6 +150,8 @@ DEFAULT is given, use it as the service's default value."
   (provision     shepherd-service-provision)           ;list of symbols
   (requirement   shepherd-service-requirement          ;list of symbols
                  (default '()))
+  (one-shot?     shepherd-service-one-shot?            ;Boolean
+                 (default #f))
   (respawn?      shepherd-service-respawn?             ;Boolean
                  (default #t))
   (start         shepherd-service-start)               ;g-expression (procedure)
@@ -238,6 +241,7 @@ stored."
                        #:docstring '#$(shepherd-service-documentation service)
                        #:provides '#$(shepherd-service-provision service)
                        #:requires '#$(shepherd-service-requirement service)
+                       #:one-shot? '#$(shepherd-service-one-shot? service)
                        #:respawn? '#$(shepherd-service-respawn? service)
                        #:start #$(shepherd-service-start service)
                        #:stop #$(shepherd-service-stop service)
diff --git a/gnu/system/shadow.scm b/gnu/system/shadow.scm
index 7dc36f4a45..13b8b14095 100644
--- a/gnu/system/shadow.scm
+++ b/gnu/system/shadow.scm
@@ -323,6 +323,7 @@ accounts among ACCOUNTS+GROUPS."
   (list (shepherd-service
          (requirement '(file-systems))
          (provision '(user-homes))
+         (one-shot? #t)
          (modules '((gnu build activation)
                     (gnu system accounts)))
          (start (with-imported-modules (source-module-closure
@@ -332,9 +333,7 @@ accounts among ACCOUNTS+GROUPS."
                       (activate-user-home
                        (map sexp->user-account
                             (list #$@(map user-account->gexp accounts))))
-                      #f)))                       ;stop
-         (stop #~(const #f))
-         (respawn? #f)
+                      #t)))                       ;success
          (documentation "Create user home directories."))))
 
 (define (shells-file shells)

             reply	other threads:[~2019-04-18 21:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-18 21:38 Ludovic Courtès [this message]
2019-04-19  4:09 ` One-shot Shepherd services znavko
2019-04-19  8:36   ` Ludovic Courtès
2019-04-19  6:40 ` Pierre Neidhardt
2019-04-19 15:02   ` User Services Joshua Branson
2019-04-19 15:33     ` Pierre Neidhardt
2019-04-30  3:33 ` One-shot Shepherd services Chris Marusich
2019-04-30 14:23   ` Ludovic Courtès
2019-04-30 17:24     ` Gábor Boskovits
2019-05-03 13:53       ` Ludovic Courtès
2019-05-04  5:52         ` Chris Marusich
2019-05-03 19:15 ` Thompson, David

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ftqfngda.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.