guix-patches
[Top][All Lists]
Advanced

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

[bug#38429] [PATCH] Add scron service.


From: Robert Vollmert
Subject: [bug#38429] [PATCH] Add scron service.
Date: Fri, 29 Nov 2019 18:53:56 +0100

It's a simple replacement for the mcron service.

If you have a mcron job definition like

(define cron-job
  #~(job "*/15 * * * *" #$(program-file ...)))

you can convert it into the valid scron job

(define cron-job
  (scron-job (schedule "/15 * * * *")
             (program-file ...)))

* gnu/services/scron.scm: New file.
* gnu/local.mk: Add it.
---
 gnu/local.mk           |  1 +
 gnu/services/scron.scm | 39 ++++++++++++++++++++++++---------------
 2 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/gnu/local.mk b/gnu/local.mk
index 56ff1d0f7b..ca8b6ecc1b 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -552,6 +552,7 @@ GNU_SYSTEM_MODULES =                                \
   %D%/services/nix.scm                         \
   %D%/services/nfs.scm                 \
   %D%/services/pam-mount.scm                   \
+  %D%/services/scron.scm                       \
   %D%/services/security-token.scm              \
   %D%/services/shepherd.scm                    \
   %D%/services/sound.scm                       \
diff --git a/gnu/services/scron.scm b/gnu/services/scron.scm
index dee0bad81e..0ea7cc9698 100644
--- a/gnu/services/scron.scm
+++ b/gnu/services/scron.scm
@@ -30,6 +30,11 @@
             scron-configuration-scron
             scron-configuration-jobs
 
+            scron-job
+            scron-job?
+            scron-job-schedule
+            scron-job-command
+
             scron-service-type
             scron-service))
 
@@ -40,7 +45,8 @@
 ;;
 ;;  (service scron-service-type
 ;;           (scron-configuration
-;;            (jobs (list (job "*/15 * * * *" "echo hello!")))))
+;;            (jobs (list (scron-job (schedule "*/15 * * * *")
+;;                                   (command  "echo hello!"))))))
 ;;;
 ;;; Code:
 
@@ -55,34 +61,37 @@
 (define-record-type* <scron-job> scron-job
   make-scron-job
   scron-job?
-  (schedule scron-job-schedule (default ""))
-  (command  scron-job-command  (default "")))
+  (schedule scron-job-schedule (default "* * * * *"))
+  (command  scron-job-command  (default '())))
 
 (define (crontab jobs)
-  (text-file "crontab"
-    (string-concatenate
+  (apply mixed-text-file "crontab"
+    (concatenate
       (map
         (match-lambda
           (($ <scron-job> schedule command)
-            (string-append schedule " " command "\n")))
+            (list schedule " " command "\n")))
         jobs))))
 
-(define scron-shepherd-service
+(define scron-shepherd-services
   (match-lambda
     (($ <scron-configuration> scron jobs)
-     (shepherd-service
-      (provision '(scron))
-      (requirement '(user-processes))
-      (start #~(make-forkexec-constructor
-                (list (string-append #$scron "/bin/crond") "-n" "-f" 
#$(crontab jobs))
-                #:log-file "/var/log/scron.log"))
-      (stop #~(make-kill-destructor))))))
+     (list
+       (shepherd-service
+        (provision '(scron))
+        (requirement '(user-processes))
+        (start #~(make-forkexec-constructor
+                  (list (string-append #$scron "/bin/crond")
+                        "-n" ; don't fork
+                        "-f" #$(crontab jobs))
+                  #:log-file "/var/log/scron.log"))
+        (stop #~(make-kill-destructor)))))))
 
 (define scron-service-type
   (service-type (name 'scron)
                 (extensions
                  (list (service-extension shepherd-root-service-type
-                                          (list scron-shepherd-service))))
+                                          scron-shepherd-services)))
                 (compose concatenate)
                 (extend (lambda (config jobs)
                           (scron-configuration
-- 
2.24.0






reply via email to

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