From: Robert Vollmert <rob@vllmrt.net>
To: 38429@debbugs.gnu.org
Cc: Robert Vollmert <rob@vllmrt.net>
Subject: [bug#38429] [PATCH] Add scron service.
Date: Fri, 29 Nov 2019 18:53:56 +0100 [thread overview]
Message-ID: <20191129175356.12403-1-rob@vllmrt.net> (raw)
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
next reply other threads:[~2019-11-29 17:56 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-29 17:53 Robert Vollmert [this message]
2019-11-29 18:07 ` [bug#38429] [PATCH] Add scron service 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
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=20191129175356.12403-1-rob@vllmrt.net \
--to=rob@vllmrt.net \
--cc=38429@debbugs.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.