all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: attila.lendvai@gmail.com
To: guix-devel@gnu.org
Cc: Attila Lendvai <attila@lendvai.name>
Subject: [PATCH shepherd] service: Factor out SEND-TO-SERVICE-CONTROLLER.
Date: Sun, 30 Jun 2024 18:13:07 +0200	[thread overview]
Message-ID: <20240630161303.22507-10-attila@lendvai.name> (raw)
In-Reply-To: <20240630161303.22507-2-attila@lendvai.name>

From: Attila Lendvai <attila@lendvai.name>

* modules/shepherd/service.scm (service-running-value): New function.
(query-service-controller), (enable-service), (disable-service),
(record-service-respawn-time), (start-service), (stop-service),
(service-registry), (handle-service-termination): Use it.
---
 modules/shepherd/service.scm | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index b5f3e23..ae9fbed 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -776,11 +776,15 @@ wire."
   "Return the \"canonical\" name of @var{service}."
   (car (service-provision service)))
 
+(define (send-to-service-controller service message)
+  "Send @var{message} to the service's control channel of @var{message}."
+  (put-message (service-control service) message))
+
 (define (query-service-controller service message)
   "Send @var{message} to the service's control channel of @var{message} and
 wait for its reply."
   (let ((reply (make-channel)))
-    (put-message (service-control service) (list message reply))
+    (send-to-service-controller service (list message reply))
     (get-message reply)))
 
 (define service-running-value
@@ -836,11 +840,11 @@ wait for its reply."
 
 (define (enable-service service)
   "Enable @var{service}."
-  (put-message (service-control service) 'enable))
+  (send-to-service-controller service 'enable))
 
 (define (disable-service service)
   "Disable @var{service}."
-  (put-message (service-control service) 'disable))
+  (send-to-service-controller service 'disable))
 
 (define (register-service-logger service logger)
   "Register @var{logger}, a value as returned by
@@ -850,7 +854,7 @@ wait for its reply."
 
 (define (record-service-respawn-time service)
   "Record the current time as the last respawn time for @var{service}."
-  (put-message (service-control service) 'record-respawn-time))
+  (send-to-service-controller service 'record-respawn-time))
 
 (define (service-running? service)
   "Return true if @var{service} is not stopped."
@@ -949,7 +953,7 @@ found in the service registry."
           #f)
         ;; Start the service itself.
         (let ((reply (make-channel)))
-          (put-message (service-control service) `(start ,reply))
+          (send-to-service-controller service `(start ,reply))
           (match (get-message reply)
             (#f
              ;; We lost the race: SERVICE is already running.
@@ -1008,7 +1012,7 @@ in a list."
                             '())))
         ;; Stop the service itself.
         (let ((reply (make-channel)))
-          (put-message (service-control service) `(stop ,reply))
+          (send-to-service-controller service `(stop ,reply))
           (match (get-message reply)
             (#f
              #f)
@@ -1184,7 +1188,7 @@ requests arriving on @var{channel}."
       ;; Terminate the controller of each of SERVICES and return REGISTERED
       ;; minus SERVICES.
       (for-each (lambda (service)
-                  (put-message (service-control service) 'terminate))
+                  (send-to-service-controller service 'terminate))
                 services)
       (vhash-fold (lambda (name service result)
                     (if (memq service services)
@@ -1211,8 +1215,7 @@ requests arriving on @var{channel}."
           (loop (register service)))
          ((_ . old)
           (let ((reply (make-channel)))
-            (put-message (service-control old)
-                         `(replace-if-running ,service ,reply))
+            (send-to-service-controller old `(replace-if-running ,service ,reply))
             (match (get-message reply)
               (#t (loop registered))
               (#f
@@ -2603,8 +2606,7 @@ been sent, send it @code{SIGKILL}."
 @var{service}; @var{status} is the process's exit status as returned by
 @code{waitpid}.  This procedure is called right after the process has
 terminated."
-  (put-message (service-control service)
-               `(handle-termination ,pid ,status)))
+  (send-to-service-controller service `(handle-termination ,pid ,status)))
 
 (define (respawn-service serv)
   "Respawn a service that has stopped running unexpectedly. If we have
-- 
2.45.2



      parent reply	other threads:[~2024-06-30 17:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-30 16:12 [PATCH shepherd] service: Add custom printer for <service> attila.lendvai
2024-06-30 16:13 ` [PATCH shepherd] service: Rename to QUERY-SERVICE-CONTROLLER and use CUT attila.lendvai
2024-06-30 16:13 ` [PATCH shepherd] service: Factor out SEND-TO-PROCESS-MONITOR attila.lendvai
2024-06-30 16:13 ` [PATCH shepherd] service: Factor out SEND-TO-REGISTRY attila.lendvai
2024-06-30 16:13 ` attila.lendvai [this message]

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=20240630161303.22507-10-attila@lendvai.name \
    --to=attila.lendvai@gmail.com \
    --cc=attila@lendvai.name \
    --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.