anacron: New feature (require a clean exit from job)

Topi Rinkinen ubuntu.com at topisoft.fi
Tue Dec 23 04:59:55 UTC 2008


Package: anacron
Version: 2.3-13ubuntu2.1
Severity: wishlist
Tags: patch

A new feature (-r flag) requiring a clean exit from the job (exit value 0)
before updating the timestamp.
This is advantageous for e.g. backups, which might require that succesful
completion is done each day.
If the job exits with non-zero exit value, the job is run again when
anacron starts next time.


-- System Information:
Debian Release: lenny/sid
  APT prefers hardy-updates
  APT policy: (500, 'hardy-updates'), (500, 'hardy-security'), (500, 'hardy')
Architecture: i386 (i686)

Kernel: Linux 2.6.24-22-generic (SMP w/1 CPU core)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages anacron depends on:
ii  debianutils              2.28.2-0ubuntu1 Miscellaneous utilities specific t
ii  libc6                    2.7-10ubuntu4   GNU C Library: Shared libraries
ii  lsb-base                 3.2-4ubuntu1    Linux Standard Base 3.2 init scrip

Versions of packages anacron recommends:
ii  cron                   3.0pl1-100ubuntu2 management of regular background p
ii  postfix [mail-transpor 2.5.1-2ubuntu1.2  High-performance mail transport ag
ii  sysklogd [system-log-d 1.5-1ubuntu1      System Logging Daemon

-- no debconf information
-------------- next part --------------
diff -Nur --from-file=anacron-2.3-13.orig anacron-2.3-13.orig/anacron.8 anacron-2.3-13/anacron.8
--- anacron-2.3-13.orig/anacron.8	2008-12-23 05:20:08.000000000 +0200
+++ anacron-2.3-13/anacron.8	2008-12-23 05:58:31.000000000 +0200
@@ -2,7 +2,7 @@
 .SH NAME
 anacron \- runs commands periodically
 .SH SYNOPSIS
-.B anacron \fR[\fB-s\fR] [\fB-f\fR] [\fB-n\fR] [\fB-d\fR] [\fB-q\fR]
+.B anacron \fR[\fB-s\fR] [\fB-f\fR] [\fB-n\fR] [\fB-d\fR] [\fB-q\fR] [\fB-r\fR]
 [\fB-t anacrontab\fR] [\fB-S spooldir\fR] [\fIjob\fR] ...
 .br
 .B anacron [\fB-S spooldir\fR] -u [\fB-t anacrontab\fR] \fR[\fIjob\fR] ...
@@ -100,6 +100,12 @@
 .B -q
 Suppress messages to standard error.  Only applicable with \fB-d\fR.
 .TP
+.B -r
+Require a clean exit (return value 0) from the job before updating the timestamp.
+This can be used to run the job again soon (on the next anacron run),
+if the job failed for some reason. E.g. backup operation might be required
+to be succesful each day.
+.TP
 .B -t anacrontab
 Use specified anacrontab, rather than the default
 .TP
diff -Nur --from-file=anacron-2.3-13.orig anacron-2.3-13.orig/global.h anacron-2.3-13/global.h
--- anacron-2.3-13.orig/global.h	2008-12-23 05:20:08.000000000 +0200
+++ anacron-2.3-13/global.h	2008-12-23 05:48:15.000000000 +0200
@@ -82,6 +82,7 @@
 extern int old_umask;
 extern sigset_t old_sigmask;
 extern int serialize,force,update_only,now,no_daemon,quiet,testing_only;
+extern int require_clean_exit;
 extern int day_now;
 extern int year,month,day_of_month;
 extern int in_background;
diff -Nur --from-file=anacron-2.3-13.orig anacron-2.3-13.orig/main.c anacron-2.3-13/main.c
--- anacron-2.3-13.orig/main.c	2008-12-23 05:20:08.000000000 +0200
+++ anacron-2.3-13/main.c	2008-12-23 06:17:21.000000000 +0200
@@ -43,6 +43,7 @@
 char *spooldir;
 int serialize, force, update_only, now,
     no_daemon, quiet, testing_only;            /* command-line options */
+int require_clean_exit;
 char **args;                       /* vector of "job" command-line arguments */
 int nargs;                                     /* number of these */
 char *defarg = "*";
@@ -72,7 +73,7 @@
 static void
 print_usage()
 {
-    printf("Usage:  anacron [-s] [-f] [-n] [-d] [-q] [-t anacrontab] [-S spooldir] [job] ...\n"
+    printf("Usage:  anacron [-s] [-f] [-n] [-d] [-q] [-r] [-t anacrontab] [-S spooldir] [job] ...\n"
 	   "        anacron [-S spooldir] -u [job] ...\n"
 	   "        anacron [-V|-h]\n"
 	   "        anacron -T [-t anacrontab]\n"
@@ -82,6 +83,7 @@
 	   " -n  Run jobs with no delay, implies -s\n"
 	   " -d  Don't fork to the background\n"
 	   " -q  Suppress stderr messages, only applicable with -d\n"
+	   " -r  Require clean exit before updating timestamp\n"
 	   " -u  Update the timestamps without actually running anything\n"
 	   " -t  Use this anacrontab\n"
 	   " -V  Print version information\n"
@@ -101,10 +103,14 @@
 
     quiet = no_daemon = serialize = force = update_only = now = 0;
     opterr = 0;
-    while ((opt = getopt(argc, argv, "sfundqt:TS:Vh")) != EOF)
+    require_clean_exit = 0;
+    while ((opt = getopt(argc, argv, "rsfundqt:TS:Vh")) != EOF)
     {
 	switch (opt)
 	{
+	case 'r':
+  	    require_clean_exit = 1;
+	    break;
 	case 's':
 	    serialize = 1;
 	    break;
diff -Nur --from-file=anacron-2.3-13.orig anacron-2.3-13.orig/runjob.c anacron-2.3-13/runjob.c
--- anacron-2.3-13.orig/runjob.c	2008-12-23 05:20:08.000000000 +0200
+++ anacron-2.3-13/runjob.c	2008-12-23 05:45:15.000000000 +0200
@@ -276,14 +276,19 @@
     int mail_output;
     char *m;
 
-    update_timestamp(jr);
+    if(!require_clean_exit)
+      update_timestamp(jr);
     unlock(jr);
     if (file_size(jr->output_fd) > jr->mail_header_size) mail_output = 1;
     else mail_output = 0;
 
     m = mail_output ? " (mailing output)" : "";
     if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
+      {
+	if(require_clean_exit)
+	  update_timestamp(jr);
 	explain("Job `%s' terminated%s", jr->ident, m);
+      }
     else if (WIFEXITED(status))
 	explain("Job `%s' terminated (exit status: %d)%s",
 		jr->ident, WEXITSTATUS(status), m);


More information about the ubuntu-users mailing list