<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Allen Brooker (AllenJB) &#187; bug</title>
	<atom:link href="http://allenjb.me.uk/?feed=rss2&#038;tag=bug" rel="self" type="application/rss+xml" />
	<link>http://allenjb.me.uk</link>
	<description>Programming yesterday was about developers vs idiots. Now the developers are the idiots.</description>
	<lastBuildDate>Tue, 31 Aug 2010 12:45:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Attack of the 5 year old DST / run-crons bug!</title>
		<link>http://allenjb.me.uk/?p=167</link>
		<comments>http://allenjb.me.uk/?p=167#comments</comments>
		<pubDate>Tue, 27 Oct 2009 23:42:39 +0000</pubDate>
		<dc:creator>AllenJB</dc:creator>
				<category><![CDATA[Gentoo]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://allenjb.me.uk/?p=167</guid>
		<description><![CDATA[So I noticed that when we switched off the abomination that is daylight savings this weekend just gone, my systems which run on &#8220;GB&#8221; time rather than &#8220;UTC&#8221; executed their cron scripts twice. This despite the fact that, at a glance, they should execute at (or shortly after) 03:01, which should be safe.
Turns out this [...]]]></description>
			<content:encoded><![CDATA[<p>So I noticed that when we switched off the abomination that is daylight savings this weekend just gone, my systems which run on &#8220;GB&#8221; time rather than &#8220;UTC&#8221; executed their cron scripts twice. This despite the fact that, at a glance, they should execute at (or shortly after) 03:01, which should be safe.</p>
<p>Turns out this isn&#8217;t quite the case. There&#8217;s a <a href="http://bugs.gentoo.org/show_bug.cgi?id=69777">5 year old bug in Gentoo&#8217;s Bugzilla</a> about this known issue and it appears to be down to the way run-crons manages its lock / last run files. I&#8217;m already running a run-crons <a href="http://bugs.gentoo.org/show_bug.cgi?id=261000">patched for recursive directory scanning</a> on some of my systems, so it wasn&#8217;t that big a step to basically do away with Gentoo&#8217;s supplied script altogether.</p>
<p>Now I&#8217;m running &#8220;run-crons-in&#8221; &#8211; a much simplified script that simply relies on the cron daemon itself for timing (which is how it should be, in my opinion). Here&#8217;s my script:</p>
<pre>
#!/bin/bash
# 2009-10-27 Complete rewrite of run-crons
# This version is designed to be called using @hourly @daily @weekly or @monthly
# With, for example: run-crons-in daily
#
# This version assumes:
# - We don't care if a previous script is still running
# - The cron daemon handles all timing in a sensible manner
# - Therefore no locking is necessary

AJB_DEBUG=0
AJB_TIMES=1
AJB_PTIMES=1
AJB_TIMEFORMAT='%Y-%m-%d %T'
BASE=$1

AJB_STARTTIME="`date +\"${AJB_TIMEFORMAT}\"`"
[ $AJB_TIMES -eq 1 ] &#038;&#038; echo "Start time: ${AJB_STARTTIME}"

run_recursive() {
        CRONDIR="$1"
        [ $AJB_DEBUG -eq 1 ] &#038;&#038; echo "Executing cron scripts in directory: $CRONDIR"
        for SCRIPT in $CRONDIR/* ; do
                if [[ -x $SCRIPT &#038;&#038; ! -d $SCRIPT ]]; then
                        [ $AJB_DEBUG -eq 1 ] &#038;&#038; echo "Executing cron script: $SCRIPT"
                        AJB_PSTARTTIME="`date +\"${AJB_TIMEFORMAT}\"`"
                        [ $AJB_PTIMES -eq 1 ] &#038;&#038; echo "Script start time: ${AJB_PSTARTTIME}"
                        $SCRIPT
                        AJB_PSTOPTIME="`date +\"${AJB_TIMEFORMAT}\"`"
                        [ $AJB_PTIMES -eq 1 ] &#038;&#038; echo "Script stop time: ${AJB_PSTOPTIME}"
                fi

                if [[ -d $SCRIPT ]]; then
                        run_recursive $SCRIPT
                fi
        done
}

CRONDIR="/etc/cron.${BASE}"

test -d "$CRONDIR" || echo "Directory does not exist or is not a directory: ${CRONDIR}"
set +e
test -d "$CRONDIR" &#038;&#038; run_recursive "$CRONDIR"

AJB_STOPTIME="`date +\"${AJB_TIMEFORMAT}\"`"
[ $AJB_TIMES -eq 1 ] &#038;&#038; echo "End time: ${AJB_STOPTIME}"
</pre>
<p>As you can see, it&#8217;s fairly basic &#8211; altho I&#8217;ve added some extra output for timing and debugging, simply because I felt like it. I&#8217;m currently testing this long term to ensure it works as expected, but hopefully I&#8217;ll adopt this for all my systems within a couple of months.</p>
<p>The full /etc/crontab entries are now:</p>
<pre>
@hourly   root    /usr/local/sbin/run-crons-in hourly
@daily    root    /usr/local/sbin/run-crons-in daily
@weekly   root    /usr/local/sbin/run-crons-in weekly
@monthly  root    /usr/local/sbin/run-crons-in monthly
</pre>
<p>(Yes, I realize that, at least by the man page, those are all going to run at midnight, but daily is the only set of scripts that ever does anything really stressful on the system I&#8217;m currently testing on, and it&#8217;s a quad core, and I really don&#8217;t care otherwise I wouldn&#8217;t be testing cron daemons on it)</p>
<p>I&#8217;m also taking the opportunity to use <a href="https://fedorahosted.org/cronie/">cronie</a> in place of vixie-cron. There&#8217;s little documentation for this project, but as far as I can see it&#8217;s a drop-in replacement for / fork of vixie-cron from redhat that&#8217;s actively maintained.</p>
<p>I did take a quick look at the other cron daemons in the portage tree, but cronie appears to be the only one that&#8217;s actively maintained.</p>
]]></content:encoded>
			<wfw:commentRss>http://allenjb.me.uk/?feed=rss2&amp;p=167</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
