guix-commits
[Top][All Lists]
Advanced

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

[shepherd] 03/03: service: Use 'lookup-service' instead of 'lookup-servi


From: Ludovic Courtès
Subject: [shepherd] 03/03: service: Use 'lookup-service' instead of 'lookup-services'.
Date: Sat, 8 Apr 2023 18:21:35 -0400 (EDT)

civodul pushed a commit to branch wip-goopsless
in repository shepherd.

commit a353fa5bbbd62d6e6d64284064f5a5da8ebe20de
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Sun Apr 9 00:11:23 2023 +0200

    service: Use 'lookup-service' instead of 'lookup-services'.
    
    * modules/shepherd/service.scm (launch-service): Change to use
    'lookup-service' (singular).
    (stop <symbol>): Likewise.
    (action <symbol>): Likewise.
    (first-running, lookup-running, lookup-running-or-providing): Remove.
---
 modules/shepherd/service.scm | 91 +++++++++++++++-----------------------------
 1 file changed, 30 insertions(+), 61 deletions(-)

diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index d07add7..8ff89db 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -78,9 +78,6 @@
             action
             doc
 
-            first-running
-            lookup-running
-            lookup-running-or-providing
             for-each-service
             respawn-service
             handle-SIGCHLD
@@ -1114,47 +1111,45 @@ service state and to send requests to the service 
monitor."
 (define (launch-service name args)
   "Try to start (with PROC) a service providing NAME; return #f on failure.
 Used by `start'."
-  (match (lookup-services name)
-    (()
+  (match (lookup-service name)
+    (#f
      (raise (condition (&missing-service-error (name name)))))
-    ((possibilities ...)
-     (let ((running (first-running possibilities)))
-       (if running
-           (begin
-             (local-output (l10n "Service ~a is already running.")
-                          (service-canonical-name running))
-             running)
-           ;; None running yet, start one.
-           (find (lambda (service)
-                   (apply start service args))
-                 possibilities))))))
+    (service
+     (if (eq? 'running (service-status service))
+         (begin
+           (local-output (l10n "Service ~a is already running.")
+                        (service-canonical-name service))
+           service)
+         (apply start service args)))))
 
 ;; Starting by name.
 (define-method (start (obj <symbol>) . args)
   (launch-service obj args))
 
 ;; Stopping by name.
-(define-method (stop (obj <symbol>) . args)
-  (let ((which (find (negate service-stopped?)
-                     (lookup-services obj))))
-    (if which
-       (apply stop which args)
-        ;; Only print an error if the service does not exist.
-        (match (lookup-services obj)
-          (()
-           (raise (condition (&missing-service-error (name obj)))))
-          ((stopped . _)
-           (list))))))
-
-(define-method (action (obj <symbol>) the-action . args)
+(define-method (stop (name <symbol>) . args)
+  (match (lookup-service name)
+    (#f
+     (raise (condition (&missing-service-error (name name)))))
+    (service
+     ;; XXX: This used to return a list of results, on the grounds that there
+     ;; could be several services called NAME.  Clients like 'herd' expect a
+     ;; list.
+     (if (service-stopped? service)
+         '()
+         (apply stop service args)))))
+
+(define-method (action (name <symbol>) the-action . args)
   "Perform THE-ACTION on all the services named OBJ.  Return the list of
 results."
-  (let ((which-services (lookup-running-or-providing obj)))
-    (if (null? which-services)
-        (raise (condition (&missing-service-error (name obj))))
-        (map (lambda (service)
-               (apply action service the-action args))
-             which-services))))
+  (match (lookup-service name)
+    (#f
+     (raise (condition (&missing-service-error (name name)))))
+    (service
+     ;; XXX: This used to return a list of action results, on the grounds that
+     ;; there could be several services called NAME.  Clients like 'herd'
+     ;; expect a list so now we return a singleton.
+     (list (apply action service the-action args)))))
 
 (define (start-in-the-background services)
   "Start the services named by @var{services}, a list of symbols, in the
@@ -1185,32 +1180,6 @@ background:~{ ~a~}."
   *unspecified*)
 
 
-
-;; Check if any of SERVICES is running.  If this is the case, return
-;; it.  If none, return `#f'.  Only the first one found will be
-;; returned; this is because this is mainly intended to be applied on
-;; the return value of `lookup-services', where no more than one will
-;; ever run at the same time.
-(define (first-running services)
-  (find (lambda (service)
-          (eq? 'running (service-status service)))
-        services))
-
-;; Return the running service that provides NAME, or false if none.
-(define (lookup-running name)
-  (first-running (lookup-services name)))
-
-;; Lookup the running service providing SYM, and return it as a
-;; one-element list.  If none is running, return a list of all
-;; services which provide SYM.
-(define (lookup-running-or-providing sym)
-  (match (lookup-running sym)
-    ((? service? service)
-     (list service))
-    (#f
-     (lookup-services sym))))
-
-
 ;;;
 ;;; Starting/stopping services.
 ;;;



reply via email to

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