From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:48475) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iakUx-00079y-Pe for guix-patches@gnu.org; Fri, 29 Nov 2019 12:56:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iakUu-0006YC-Ed for guix-patches@gnu.org; Fri, 29 Nov 2019 12:56:06 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:55795) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iakUu-0006UB-BJ for guix-patches@gnu.org; Fri, 29 Nov 2019 12:56:04 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iakUs-00079T-AN for guix-patches@gnu.org; Fri, 29 Nov 2019 12:56:02 -0500 Subject: [bug#38429] [PATCH] Add scron service. Resent-Message-ID: Received: from eggs.gnu.org ([2001:470:142:3::10]:46877) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iakTt-0006eD-KJ for guix-patches@gnu.org; Fri, 29 Nov 2019 12:55:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iakTo-0003fa-CF for guix-patches@gnu.org; Fri, 29 Nov 2019 12:55:00 -0500 Received: from mout-p-202.mailbox.org ([2001:67c:2050::465:202]:62738) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iakTo-0003VO-1O for guix-patches@gnu.org; Fri, 29 Nov 2019 12:54:56 -0500 From: Robert Vollmert Date: Fri, 29 Nov 2019 18:53:56 +0100 Message-Id: <20191129175356.12403-1-rob@vllmrt.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 38429@debbugs.gnu.org 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 =3D \ %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 =20 + scron-job + scron-job? + scron-job-schedule + scron-job-command + scron-service-type scron-service)) =20 @@ -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: =20 @@ -55,34 +61,37 @@ (define-record-type* 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 '()))) =20 (define (crontab jobs) - (text-file "crontab" - (string-concatenate + (apply mixed-text-file "crontab" + (concatenate (map (match-lambda (($ schedule command) - (string-append schedule " " command "\n"))) + (list schedule " " command "\n"))) jobs)))) =20 -(define scron-shepherd-service +(define scron-shepherd-services (match-lambda (($ 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))))))) =20 (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 --=20 2.24.0