guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

One-shot Shepherd services


From: Ludovic Courtès
Subject: One-shot Shepherd services
Date: Thu, 18 Apr 2019 23:38:41 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux)

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’.

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 <address@hidden>
+;;; Copyright © 2013, 2014, 2015, 2016, 2018, 2019 Ludovic Courtès 
<address@hidden>
 ;;; Copyright © 2017 Clément Lassieur <address@hidden>
 ;;; Copyright © 2018 Carlo Zancanaro <address@hidden>
 ;;;
@@ -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 via email to

[Prev in Thread] Current Thread [Next in Thread]