[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH shepherd] service: Factor out SEND-TO-SERVICE-CONTROLLER.
From: |
attila . lendvai |
Subject: |
[PATCH shepherd] service: Factor out SEND-TO-SERVICE-CONTROLLER. |
Date: |
Sun, 30 Jun 2024 18:13:07 +0200 |
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