From nobody@FreeBSD.org  Thu Jul 12 10:30:15 2001
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id D38C537B408
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 12 Jul 2001 10:30:14 -0700 (PDT)
	(envelope-from nobody@FreeBSD.org)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.4/8.11.4) id f6CHUEv78912;
	Thu, 12 Jul 2001 10:30:14 -0700 (PDT)
	(envelope-from nobody)
Message-Id: <200107121730.f6CHUEv78912@freefall.freebsd.org>
Date: Thu, 12 Jul 2001 10:30:14 -0700 (PDT)
From: Tim Kientzle <kientzle@acm.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: periodic scripts do not run on desktop systems that aren't always on
X-Send-Pr-Version: www-1.0

>Number:         28920
>Category:       misc
>Synopsis:       periodic scripts do not run on desktop systems that aren't always on
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jul 12 10:40:00 PDT 2001
>Closed-Date:    Thu Jul 12 12:38:17 PDT 2001
>Last-Modified:  Thu Jul 12 12:39:01 PDT 2001
>Originator:     Tim Kientzle
>Release:        4.3 Release
>Organization:
Independent Software Consultant
>Environment:
FreeBSD ugly.kientzle.com 4.3-RELEASE FreeBSD 4.3-RELEASE #0: Thu Jun 14 11:18:04 PDT 2001     root@ugly.kientzle.com:/usr/src/sys/compile/UGLY  i386
>Description:
System periodic scripts are run from crontab in the wee
hours of the morning.  If the system isn't on all the time,
those scripts never run.  This causes a variety of problems:
locate is useless, security checks are never performed,
/tmp cleanup never happens, etc.
>How-To-Repeat:
Turn off your computer at 5pm.  Turn it back on at 9am
and note that root has no email.  ;-)
>Fix:
The obvious workaround: leave the system on all
the time.  This is impossible for some (laptops),
and undesirable for many others (electricity is
getting more expensive).

A more involved solution is to rewrite the 'periodic'
program called by crontab so that:
  * It is run at frequent intervals.
  * It keeps a database recording when each periodic
    task was last run.
  * If the system is on at 2am (or some other preferred time),
    it will preferentially run periodic tasks at that time.
    Thus, servers and other always-on systems will have exactly
    the same behavior as before: all periodic tasks are
    run at a predictable time.
  * If a periodic task is significantly overdue (due to the
    system being off), then it will get run at other times
    at reduced priority.

I've written a replacement for 'periodic' that does
all of the above.  It's written in Perl and is very
nearly a drop-in replacement that provides the same
user-land behavior as the standard 'periodic'.
It would certainly make sense to have this
revised periodic installed separately, though, since it does
operate a bit differently.

Full source available on request.

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: keichii 
State-Changed-When: Thu Jul 12 12:38:17 PDT 2001 
State-Changed-Why:  
This is the user's administrative problem. 
The user can change his cron job time as root. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=28920 
>Unformatted:
