Scheduling subsystems (crontab, at) and the desktop

Oswald Buddenhagen ossi at kde.org
Thu Jul 22 19:35:11 EEST 2004


On Thu, Jul 22, 2004 at 02:55:11PM +0200, Maciej Katafiasz wrote:
> Just to let you know, we're working on modern replacement for cron,
> but with much wider scope that just scheduling and fully DBUS based,
> and intended to come up with formal FD.o proposal in one of these
> days.
>
just for consideration ...
for non-server use, the "system powered off" state is relevant, let's
call it "demand booting".
for this purpose i have created a small script that intercepts
init-related commands and modifies them according to pending at jobs,
and it schedules auto-boots with nvram-wakeup. script is attached. i use
a patched nvram-wakeup with the internal shutdown and boot periods
zeroed out (as the script handles this), but it's no requirement.
one thing to add to this would obviously be cron awareness, but that'd
need some job priorization, i.e., a "it is worth booting the system at 4
am just to execute this job?" flag.
another thing would be automatically shutting down the system if no
activity is observed. that's a bit tricky, though - even the "user(s)
logged in or not" case sort of needs a crystal ball to automatize.
another consideration is integration with desktop/display managers
which offer shutdown frontends. for example, kdm will soon offer
shutdown switches of the type "wait at most x minutes for the last
session to exit, and after that timeout enforce or cancel shutdown".
this could be well integrated with a generic event scheduling system.

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!
--
Chaos, panic, and disorder - my work here is done.
-------------- next part --------------
#! /bin/bash
# -x
#exec </dev/null >>$(me).log 2>&1;echo;date

exe=${0##*/}
skip=false
doit=true
case $exe in
  init|telinit)
    doit=false
    for i in "$@"; do
      if $skip; then skip=false; continue; fi
      case $i in
        -t) skip=true;;
        -*) break;;
        *)
          for ((j=0;j<${#i};j++)); do
            case ${i:$j:1} in
              [06]) doit=true;;
              [12345sSqQuUabc]);;
              *) break 2;;
            esac
          done
      esac
    done
    ;;
  halt|reboot|poweroff)
    for i in `getopt -q "nwdfiph" "$@"`; do
      case $i in
        -[fw]) doit=false;;
        -[ndiph]);;
        *) break;;
      esac
    done
    ;;
  shutdown)
    for i in `getopt -q "t:arkhncfF" "$@"`; do
      if $skip; then skip=false; continue; fi
      case $i in
        -t) skip=true;;
        -[ck]) doit=false;;
        -[arhnfF]);;
        *) break;;
      esac
    done
    ;;
  *) echo "prepsd: What am i!?" >&2; exit 1;;
esac
if $doit; then
  now=`date "+%s"`
  wake=
  atq | (
    while read n d t q u; do
      if [ "$q" = "=" ]; then
        echo "at job(s) currently running; refusing shutdown." >&2; exit 5;
      fi
      tim=`date "+%s" -d "$d $t"`
      dif=$((tim-now))
      if ((dif > 28*24*60*60)); then
        echo "Warning: at job $n more than 28 days ahead." >&2
      elif [ -z "$wake" ] || ((tim < wake)); then
        if ((dif < 20*60)); then
          echo "Next at job(s) in less than 20 minutes; refusing shutdown." >&2; exit 5;
        fi
        wake=$tim
      fi
    done
    if [ -n "$wake" ]; then
      nvram-wakeup -s $((wake - 2*60)) > /dev/null
    fi
  ) || exit
fi
exec /sbin/$exe "$@"


More information about the xdg mailing list