unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* One-shot Shepherd services
@ 2019-04-18 21:38 Ludovic Courtès
  2019-04-19  4:09 ` znavko
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Ludovic Courtès @ 2019-04-18 21:38 UTC (permalink / raw)
  To: Guix-devel

[-- 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)

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-05-04  5:52 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-18 21:38 One-shot Shepherd services Ludovic Courtès
2019-04-19  4:09 ` 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

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).