all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [bug#38429] [PATCH] Add scron service.
@ 2019-11-29 17:53 Robert Vollmert
  2019-11-29 18:07 ` Robert Vollmert
  2019-12-03 12:46 ` [bug#38429] [PATCH 1/5] document scron Robert Vollmert
  0 siblings, 2 replies; 12+ messages in thread
From: Robert Vollmert @ 2019-11-29 17:53 UTC (permalink / raw)
  To: 38429; +Cc: Robert Vollmert

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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-12-08  3:24 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-29 17:53 [bug#38429] [PATCH] Add scron service Robert Vollmert
2019-11-29 18:07 ` Robert Vollmert
2019-12-02  9:01   ` Ludovic Courtès
2019-12-03 12:46 ` [bug#38429] [PATCH 1/5] document scron Robert Vollmert
2019-12-03 12:46   ` [bug#38429] [PATCH 2/5] scron-service: remove job defaults Robert Vollmert
2019-12-03 12:46   ` [bug#38429] [PATCH 3/5] scron: Add description Robert Vollmert
2019-12-03 12:46   ` [bug#38429] [PATCH 4/5] scron: add system test Robert Vollmert
2019-12-03 12:50     ` Robert Vollmert
2019-12-03 12:46   ` [bug#38429] [PATCH 5/5] gnu/services: Add description to mcron-service-type Robert Vollmert
2019-12-07 23:32   ` [bug#38429] [PATCH 1/5] document scron Ludovic Courtès
2019-12-07 23:43     ` Robert Vollmert
2019-12-07 23:46       ` bug#38429: " Ludovic Courtès

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.