tag 744753 + patch
thanks

Le Wed, 29 Oct 2014 10:50:27 +0100,
Laurent Bigonville <bi...@debian.org> a écrit :

> 
> Michael was proposing another solution. Instead of waking anacron at
> boot and just after sleep, we could run it every hour. So it would be
> quite unlikely that anacron is not run at all at least once a day on
> the machine of the user.
> 
> I personally don't have strong feeling about this. Looking at Fedora
> they are doing this too apparently.

OK, I've prepared the attached patch.

With this patch, anacron is only run by cron itself every hours and not
at boot when the machine is getting out of suspend.

Two things:

 - I'm wondering if the package shouldn't depends on cron daemon
   instead of recommending it now that cron is the only way anacron
   would run.
 - I've removed the calls to "anacron -u *", these looked useless to
   me as the timestamp files are updated after the run anyway. With the
   call to "anacron -u *" they were also updated at the beginning of the
   run.

Tell me what do you think about this.

Cheers,

Laurent Bigonville
diff -Nru anacron-2.3/debian/anacron.0anacron.cron.daily anacron-2.3/debian/anacron.0anacron.cron.daily
--- anacron-2.3/debian/anacron.0anacron.cron.daily	2012-02-18 11:51:51.000000000 +0100
+++ anacron-2.3/debian/anacron.0anacron.cron.daily	1970-01-01 01:00:00.000000000 +0100
@@ -1,12 +0,0 @@
-#!/bin/sh
-#
-# anacron's cron script
-#
-# This script updates anacron time stamps. It is called through run-parts
-# either by anacron itself or by cron.
-#
-# The script is called "0anacron" to assure that it will be executed
-# _before_ all other scripts.
-
-test -x /usr/sbin/anacron || exit 0
-anacron -u cron.daily
diff -Nru anacron-2.3/debian/anacron.0anacron.cron.hourly anacron-2.3/debian/anacron.0anacron.cron.hourly
--- anacron-2.3/debian/anacron.0anacron.cron.hourly	1970-01-01 01:00:00.000000000 +0100
+++ anacron-2.3/debian/anacron.0anacron.cron.hourly	2014-11-16 19:51:00.000000000 +0100
@@ -0,0 +1,27 @@
+#!/bin/sh
+#
+# anacron's cron script
+
+test -x /usr/sbin/anacron || exit 0
+test -r /etc/default/anacron && . /etc/default/anacron
+
+# Check whether 0anacron was run today already
+if test -r /var/spool/anacron/cron.daily; then
+    day=`cat /var/spool/anacron/cron.daily`
+fi
+if [ `date +%Y%m%d` = "$day" ]; then
+    exit 0;
+fi
+
+if test x"$ANACRON_RUN_ON_BATTERY_POWER" != x"yes" && test -x /usr/bin/on_ac_power
+then
+    /usr/bin/on_ac_power >/dev/null
+    if test $? -eq 1
+    then
+      exit 0
+    fi
+fi
+
+# on_ac_power doesn't exist, on_ac_power returns 0 (ac power being used)
+# or on_ac_power returns 255 (undefined, desktop machine without APM)
+/usr/sbin/anacron -s
diff -Nru anacron-2.3/debian/anacron.0anacron.cron.monthly anacron-2.3/debian/anacron.0anacron.cron.monthly
--- anacron-2.3/debian/anacron.0anacron.cron.monthly	2012-02-18 11:51:51.000000000 +0100
+++ anacron-2.3/debian/anacron.0anacron.cron.monthly	1970-01-01 01:00:00.000000000 +0100
@@ -1,12 +0,0 @@
-#!/bin/sh
-#
-# anacron's cron script
-#
-# This script updates anacron time stamps. It is called through run-parts
-# either by anacron itself or by cron.
-#
-# The script is called "0anacron" to assure that it will be executed
-# _before_ all other scripts.
-
-test -x /usr/sbin/anacron || exit 0
-anacron -u cron.monthly
diff -Nru anacron-2.3/debian/anacron.0anacron.cron.weekly anacron-2.3/debian/anacron.0anacron.cron.weekly
--- anacron-2.3/debian/anacron.0anacron.cron.weekly	2012-02-18 11:51:51.000000000 +0100
+++ anacron-2.3/debian/anacron.0anacron.cron.weekly	1970-01-01 01:00:00.000000000 +0100
@@ -1,12 +0,0 @@
-#!/bin/sh
-#
-# anacron's cron script
-#
-# This script updates anacron time stamps. It is called through run-parts
-# either by anacron itself or by cron.
-#
-# The script is called "0anacron" to assure that it will be executed
-# _before_ all other scripts.
-
-test -x /usr/sbin/anacron || exit 0
-anacron -u cron.weekly
diff -Nru anacron-2.3/debian/anacron.postinst anacron-2.3/debian/anacron.postinst
--- anacron-2.3/debian/anacron.postinst	1970-01-01 01:00:00.000000000 +0100
+++ anacron-2.3/debian/anacron.postinst	2014-11-16 19:32:15.000000000 +0100
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+set -e
+
+if [ "$1" = "configure" ]; then
+	if dpkg --compare-versions "$2" le-nl "2.3-22.1~"; then
+		update-rc.d anacron remove >/dev/null
+		deb-systemd-helper purge anacron.service
+		deb-systemd-helper unmask anacron.service
+	fi
+fi
+
+#DEBHELPER#
diff -Nru anacron-2.3/debian/anacron.service anacron-2.3/debian/anacron.service
--- anacron-2.3/debian/anacron.service	2013-12-01 14:57:42.000000000 +0100
+++ anacron-2.3/debian/anacron.service	1970-01-01 01:00:00.000000000 +0100
@@ -1,10 +0,0 @@
-[Unit]
-Description=Run anacron jobs
-After=time-sync.target
-ConditionACPower=true
-
-[Service]
-ExecStart=/usr/sbin/anacron -dsq
-
-[Install]
-WantedBy=multi-user.target
diff -Nru anacron-2.3/debian/apm.d anacron-2.3/debian/apm.d
--- anacron-2.3/debian/apm.d	2012-02-18 11:51:51.000000000 +0100
+++ anacron-2.3/debian/apm.d	1970-01-01 01:00:00.000000000 +0100
@@ -1,19 +0,0 @@
-#! /bin/sh
-
-# This script makes anacron jobs start to run when the machine is
-# plugged into AC power, or woken up.  For a laptop, these are the 
-# closest parallels to turning on a desktop.
-
-# The /etc/init.d/anacron script now normally tries to avoid running
-# anacron unless on AC power, so as to avoid running down the battery.
-# (Things like the slocate updatedb cause a lot of IO.)  Rather than
-# trying to second-guess which events reflect having or not having
-# power, we just try to run anacron every time and let it abort if
-# there's no AC.  You'll see a message on the cron syslog facility 
-# (typically /var/log/cron) if it does run.
-
-case "$1,$2" in
-change,power|resume,*)
-    /usr/sbin/invoke-rc.d anacron start >/dev/null   
-    ;;
-esac
diff -Nru anacron-2.3/debian/changelog anacron-2.3/debian/changelog
--- anacron-2.3/debian/changelog	2014-09-26 05:56:25.000000000 +0200
+++ anacron-2.3/debian/changelog	2014-11-16 20:02:20.000000000 +0100
@@ -1,3 +1,12 @@
+anacron (2.3-22.1) UNRELEASED; urgency=medium
+
+  * Non-maintainer upload.
+  * Run anacron every hours instead of once a day or after getting out of
+    sleep, this way it will run independently of the init system or the power
+    management framework. (Closes: #744753)
+
+ -- Laurent Bigonville <bi...@debian.org>  Sun, 16 Nov 2014 20:01:31 +0100
+
 anacron (2.3-22) unstable; urgency=low
 
   * Recommend virtual package "cron-daemon" (closes: #752509)
diff -Nru anacron-2.3/debian/control anacron-2.3/debian/control
--- anacron-2.3/debian/control	2014-09-03 05:10:06.000000000 +0200
+++ anacron-2.3/debian/control	2014-11-16 19:14:18.000000000 +0100
@@ -1,8 +1,7 @@
 Source: anacron
 Section: admin
 Priority: optional
-Build-Depends: debhelper (>= 9.20120410),
-	dh-systemd
+Build-Depends: debhelper (>= 9.20120410)
 Maintainer: Peter Eisentraut <pet...@debian.org>
 Uploaders: Antonio Radici <anto...@dyne.org>
 Standards-Version: 3.9.5
@@ -12,7 +11,7 @@
 
 Package: anacron
 Architecture: any
-Depends: ${shlibs:Depends}, debianutils (>= 1.7), ${misc:Depends}, lsb-base (>= 3.0-10)
+Depends: ${shlibs:Depends}, debianutils (>= 1.7), ${misc:Depends}, lsb-base (>= 3.0-10), init-system-helpers (>= 1.18~)
 Replaces: pe
 Recommends: cron | cron-daemon, rsyslog | system-log-daemon
 Suggests: default-mta | mail-transport-agent, powermgmt-base
diff -Nru anacron-2.3/debian/cron.d anacron-2.3/debian/cron.d
--- anacron-2.3/debian/cron.d	2012-02-18 11:51:51.000000000 +0100
+++ anacron-2.3/debian/cron.d	1970-01-01 01:00:00.000000000 +0100
@@ -1,6 +0,0 @@
-# /etc/cron.d/anacron: crontab entries for the anacron package
-
-SHELL=/bin/sh
-PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
-
-30 7    * * *   root	test -x /etc/init.d/anacron && /usr/sbin/invoke-rc.d anacron start >/dev/null
diff -Nru anacron-2.3/debian/init.d anacron-2.3/debian/init.d
--- anacron-2.3/debian/init.d	2012-05-21 20:48:57.000000000 +0200
+++ anacron-2.3/debian/init.d	1970-01-01 01:00:00.000000000 +0100
@@ -1,69 +0,0 @@
-#! /bin/sh
-### BEGIN INIT INFO
-# Provides:          anacron
-# Required-Start:    $remote_fs $syslog $time
-# Required-Stop:     $remote_fs $syslog $time
-# Default-Start:     2 3 4 5
-# Default-Stop:
-# Short-Description: Run anacron jobs
-# Description: The first purpose of this script is to run anacron at
-#              boot so that it can catch up with missed jobs.  Note
-#              that anacron is not a daemon.  It is run here just once
-#              and is later started by the real cron.  The second
-#              purpose of this script is that said cron job invokes
-#              this script to start anacron at those subsequent times,
-#              to keep the logic in one place.
-### END INIT INFO
-
-PATH=/bin:/usr/bin:/sbin:/usr/sbin
-
-test -x /usr/sbin/anacron || exit 0
-test -r /etc/default/anacron && . /etc/default/anacron
-
-. /lib/lsb/init-functions
-
-case "$1" in
-  start)
-    if init_is_upstart 2>/dev/null; then
-        exit 1
-    fi
-    log_daemon_msg "Starting anac(h)ronistic cron" "anacron"
-    if test x"$ANACRON_RUN_ON_BATTERY_POWER" != x"yes" && test -x /usr/bin/on_ac_power
-    then
-        /usr/bin/on_ac_power >/dev/null
-        if test $? -eq 1
-        then
-          log_progress_msg "deferred while on battery power"
-	  log_end_msg 0
-	  exit 0
-        fi
-    fi
-
-    # on_ac_power doesn't exist, on_ac_power returns 0 (ac power being used)
-    # or on_ac_power returns 255 (undefined, desktop machine without APM)
-    start-stop-daemon --start --exec /usr/sbin/anacron -- -s
-    log_end_msg 0
-    ;;
-  restart|force-reload|reload)
-	# nothing to do
-    :
-    ;;
-  stop)
-    if init_is_upstart 2>/dev/null && status anacron 2>/dev/null | grep -q start
-    then
-        exit 0
-    fi
-    log_daemon_msg "Stopping anac(h)ronistic cron" "anacron"
-    start-stop-daemon --stop --exec /usr/sbin/anacron --oknodo --quiet
-    log_end_msg 0
-    ;;
-  status)
-    exit 4
-    ;;
-  *)
-    echo "Usage: /etc/init.d/anacron {start|stop|restart|force-reload|reload}"
-    exit 2
-    ;;
-esac
-
-exit 0
diff -Nru anacron-2.3/debian/maintscript anacron-2.3/debian/maintscript
--- anacron-2.3/debian/maintscript	1970-01-01 01:00:00.000000000 +0100
+++ anacron-2.3/debian/maintscript	2014-11-16 19:34:45.000000000 +0100
@@ -0,0 +1,7 @@
+rm_conffile /etc/apm/event.d/anacron 2.3-22.1~
+rm_conffile /etc/cron.d/anacron 2.3-22.1~
+rm_conffile /etc/cron.daily/0anacron 2.3-22.1~
+rm_conffile /etc/cron.monthly/0anacron 2.3-22.1~
+rm_conffile /etc/cron.weekly/0anacron 2.3-22.1~
+rm_conffile /etc/init/anacron.conf 2.3-22.1~
+rm_conffile /etc/init.d/anacron 2.3-22.1~
diff -Nru anacron-2.3/debian/pm-utils.power.d anacron-2.3/debian/pm-utils.power.d
--- anacron-2.3/debian/pm-utils.power.d	2012-03-10 23:19:03.000000000 +0100
+++ anacron-2.3/debian/pm-utils.power.d	1970-01-01 01:00:00.000000000 +0100
@@ -1,13 +0,0 @@
-#!/bin/sh
-
-# This script makes anacron jobs start/stop when a machine gets or loses AC
-# power.
-
-case $1 in
-    false)
-	/usr/sbin/invoke-rc.d anacron start >/dev/null   
-	;;
-    true)
-	/usr/sbin/invoke-rc.d anacron stop >/dev/null   
-	;;
-esac
diff -Nru anacron-2.3/debian/pm-utils.sleep.d anacron-2.3/debian/pm-utils.sleep.d
--- anacron-2.3/debian/pm-utils.sleep.d	2012-03-10 23:19:21.000000000 +0100
+++ anacron-2.3/debian/pm-utils.sleep.d	1970-01-01 01:00:00.000000000 +0100
@@ -1,13 +0,0 @@
-#!/bin/sh
-
-# This script makes anacron jobs start to run when the machine is woken up.
-# For a laptop, these are the closest parallels to turning on a desktop.
-
-case $1 in
-    resume|thaw)
-	/usr/sbin/invoke-rc.d anacron start >/dev/null   
-	;;
-    suspend|hibernate)
-	/usr/sbin/invoke-rc.d anacron stop >/dev/null   
-	;;
-esac
diff -Nru anacron-2.3/debian/README.debian anacron-2.3/debian/README.debian
--- anacron-2.3/debian/README.debian	2013-12-01 14:57:42.000000000 +0100
+++ anacron-2.3/debian/README.debian	2014-11-16 20:07:08.000000000 +0100
@@ -5,19 +5,11 @@
 never be aware that anacron and not cron is actually running
 cron.{daily,weekly,monthly}.
 
-Anacron itself however is not a daemon, so it will either be called at
-startup, on APM power status change, or by cron.  Disabling those will
-result in some jobs not being executed on time.
+Anacron itself however is not a daemon, it is triggered every hours by cron.
+Disabling it will result in some jobs not being executed on time.
 
 Anacron leaves messages in /var/log/syslog and /var/log/messages by
 default.
 
-By default, anacron does not run while on battery power.
-If you are using SysVinit, see /etc/default/anacron to change that.
-
-If you are using systemd and want to run anacron even when running on battery,
-you should create the following file with the specified content and then call
-"systemctl daemon-reload":
-    /etc/systemd/system/anacron.service.d/on-ac.conf:
-        [Unit]
-        ConditionACPower=
+By default, anacron does not run while on battery power, see
+/etc/default/anacron to change this behaviour.
diff -Nru anacron-2.3/debian/rules anacron-2.3/debian/rules
--- anacron-2.3/debian/rules	2014-06-13 04:41:50.000000000 +0200
+++ anacron-2.3/debian/rules	2014-11-16 18:15:56.000000000 +0100
@@ -10,18 +10,12 @@
 endif
 
 %:
-	dh $@ --with=systemd
+	dh $@
 
 override_dh_auto_install:
 	$(MAKE) install PREFIX=debian/anacron MANDIR=debian/anacron/usr/share/man
 	install -D -m 644 debian/anacrontab debian/anacron/etc/anacrontab
-	install -D -m 755 debian/apm.d debian/anacron/etc/apm/event.d/anacron
-	install -D -m 755 debian/pm-utils.power.d debian/anacron/usr/lib/pm-utils/power.d/anacron
-	install -D -m 755 debian/pm-utils.sleep.d debian/anacron/usr/lib/pm-utils/sleep.d/95anacron
 
 override_dh_installcron:
 	dh_installcron
 	dh_installcron --name=0anacron
-
-override_dh_installinit:
-	dh_installinit --no-start
diff -Nru anacron-2.3/debian/upstart anacron-2.3/debian/upstart
--- anacron-2.3/debian/upstart	2012-05-21 20:48:57.000000000 +0200
+++ anacron-2.3/debian/upstart	1970-01-01 01:00:00.000000000 +0100
@@ -1,14 +0,0 @@
-# anacron - anac(h)ronistic cron
-#
-# anacron executes commands at specific periods, but does not assume that
-# the machine is running continuously
-
-description	"anac(h)ronistic cron"
-
-start on runlevel [2345]
-stop on runlevel [!2345]
-
-expect fork
-normal exit 0
-
-exec anacron -s

Reply via email to