aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2025-03-22 11:46:57 +0100
committerLudovic Courtès <ludo@gnu.org>2025-03-23 19:30:57 +0100
commita35fa2d2cb5b53c19e7841fb5752a2e31f3c55fe (patch)
treea5dffab785301e098c56ceb78885bfc029b68829
parent230f1a9c1cbf3893f9d6eb13c70630f052727eb5 (diff)
downloadguix-a35fa2d2cb5b53c19e7841fb5752a2e31f3c55fe.tar.gz
guix-a35fa2d2cb5b53c19e7841fb5752a2e31f3c55fe.zip
services: shepherd: Add ‘shepherd-timer’.
* gnu/services/shepherd.scm (shepherd-timer): New procedure. * gnu/home/services/shepherd.scm: Re-export it. Suggested-by: Luis Guilherme Coelho <lgcoelho@disroot.org> Reviewed-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Change-Id: I5f702d4119eee47381a7a1ac650b8ad3fc5e6cdd
-rw-r--r--gnu/home/services/shepherd.scm3
-rw-r--r--gnu/services/shepherd.scm26
2 files changed, 28 insertions, 1 deletions
diff --git a/gnu/home/services/shepherd.scm b/gnu/home/services/shepherd.scm
index 25f1641b32..b4d826f6bb 100644
--- a/gnu/home/services/shepherd.scm
+++ b/gnu/home/services/shepherd.scm
@@ -53,7 +53,8 @@
shepherd-action
shepherd-configuration-action
- shepherd-trigger-action))
+ shepherd-trigger-action
+ shepherd-timer))
(define-record-type* <home-shepherd-configuration>
home-shepherd-configuration make-home-shepherd-configuration
diff --git a/gnu/services/shepherd.scm b/gnu/services/shepherd.scm
index e7e414b920..c8e01c9d83 100644
--- a/gnu/services/shepherd.scm
+++ b/gnu/services/shepherd.scm
@@ -72,6 +72,7 @@
shepherd-action-procedure
shepherd-configuration-action
+ shepherd-timer
shepherd-trigger-action
%default-modules
@@ -257,6 +258,31 @@ DEFAULT is given, use it as the service's default value."
"Return the 'canonical name' of SERVICE."
(first (shepherd-service-provision service)))
+(define %default-timer-documentation
+ "Periodically run a command.") ;no i18n since it gets in the shepherd process
+
+(define* (shepherd-timer provision schedule command
+ #:key
+ (requirement '())
+ (documentation %default-timer-documentation))
+ "Return a Shepherd service with the given PROVISION periodically running
+COMMAND, a list-valued gexp, according to SCHEDULE, a string in Vixie cron
+syntax or a gexp providing a Shepherd calendar event. DOCUMENTATION is the
+string that appears when running 'herd doc SERVICE'."
+ (shepherd-service
+ (provision provision)
+ (requirement requirement)
+ (modules '((shepherd service timer)))
+ (start #~(make-timer-constructor
+ #$(if (string? schedule)
+ #~(cron-string->calendar-event #$schedule)
+ schedule)
+ (command '(#$@command))
+ #:wait-for-termination? #t))
+ (stop #~(make-timer-destructor))
+ (documentation documentation)
+ (actions (list shepherd-trigger-action))))
+
(define (assert-valid-graph services)
"Raise an error if SERVICES does not define a valid shepherd service graph,
for instance if a service requires a nonexistent service, or if more than one