rtcidle
rtcidle is a daemon that monitors the user activity and
place the computer in a suspended (sleep) state after a
period of inactivity. At the moment, only PS/2 keyboards and
mice and serial mice are monitored, USB input devices are
missing.
The features of rtcidle are:
- program the real time clock (RTC) to wake the computer
up two minutes before the next scheduled job in the at or
cron spool;
- do not sleep if some programs are running; this includes
for example cdrecord, as cd-writing should not be
interrupted by suspension.
Installation
- get the sources from the download page and compile;
- copy rtcidle.conf to /etc; add every
program you don't want to be interrupted by suspension
there;
- if something is to be done before suspension or after
wakeup, add to /etc/rtcidle.before and
/etc/rtcidle.after (this is something you will
probably find out after the first test run, see below)
- update the crontables: if a scheduled program is
expected to take more than a few seconds, launch it using
the enclosed program waiting; that is, convert:
* * * * * /path/to/program arguments
to:
* * * * * /path/to/waiting /path/to/program arguments
- remember to do the same for at jobs
- run rtcidle
Customization
Some customization of the /etc files may be
required to make everything run fine through a suspension.
For testing, you can use rtcidle -i, which makes
the system going into suspended mode immediately, without
waiting for user inactivity. This way, you can then
immediately wake the computer up to check whether it is
fully operational after the sleep. Note that the -i
flag only changes the behaviour at the beginning: when the
system wakes up, it again waits for user inactivity before
sleeping again.
rtcidle reads /etc/rtcidle.conf before suspending.
This is a list of program names. If any of these programs is
running, suspension is not entered. At a minimum,
waiting and CD-writing programs should be there.
Other programs you may not want to be interrupted are
backup scripts, etc.
Some kernel modules and/or userspace daemons do not behave
correctly through a suspension. You may want to stop them in
/etc/rtcidle.before and restart them in
/etc/rtcidle.after. If the problem only occur
occasionally (or after a long suspension), you may
alternatively check whether these services still work in
/etc/rtcidle.after and restart them otherwise. For
example, my computer sometimes looses control of the network
interface during a sleep, ending up with a "Disabling IRQ
#12" message. I solved the problem by adding the following
to /etc/rtcidle.after:
ping -c 3 another_local_computer
if [ "$?" != 0 ];
then
echo "Restarting network"
/etc/init.d/network stop
# remove and reload modules on irq 12
rmmod ...
sleep 1
modprobe ...
/etc/init.d/network start
fi
Finding out what to stop and restart (or check and restart)
may require some tries.
Notes
- not all computers support suspension; not all that do
are able to wake up at a programmed time; before running
rtcidle I suggest to check whether your computer supports
both features: use apmsleep (if you use APM with
the old RTC framework; it is part of the apmd
package) or rtcwake (ACPI with the new RTC
framework, included in util-linux-ng)
to check this.
- If your computer enters the sleep state but then does
not wake up at the programmed time, a last resort is to
program the bios wakeup time using nvram-wakeup;
this is probably the least likely to work, as the wake-up
feature is designed for a different aim; if it works, it has
to be explicitely called in /etc/rtcidle.before;
this script is passed as argument the wakeup time, expressed
as number of seconds since 1/1/1970.
- rtcidle uses the system time, but the program you use
for sleeping may use the hardware clock instead; keep these
two synchronized
- Some kernel versions allow both acpi and apm to be
active at the same time (this is disabled in recent
versions); this configuration didn't work for me: computer
entered suspension but then did not wake up no matter what I
did (pressing a key, pressing the power-on button, etc.)
- If a suspended computer does not wake up upon key press, try
with the power-on button; generally, which events cause
suspension to end are specified in the BIOS configuration.
- The rtc module and the rtc-core/rtc-cmos ones appear to
be incompatible with each other: if they are both present,
the computer may enter sleep state but not wake up at the
right time; note that the rtc module may be included in the
kernel, in which case it does not show up in the result of
lsmod.
- Some computers may enter sleep state but then come out
immediately; this may be due to a keyboard interrupt (try
sleep 1; apm -s or similar) or to some other event
waking up the computer, such as a network packet (check with
tcpdump -p); which events wake the computer can
usually be configured in the BIOS
- Currently, rtcidle wakes up for every cron or at job,
but do not wait for its completion unless the program is
launched via waiting. This may or may not the
expected behaviour.
sourceforge page