rtcidle

rtcidle is a Linux daemon that monitors the user activity and suspend the computer after a period of inactivity.

Features:

Requires:

Installation

  1. get the sources from the download page and compile;
  2. copy rtcidle.conf to /etc; add every program you don't want to be interrupted by suspension there;
  3. 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)
  4. 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
    
  5. remember to do the same for at jobs
  6. run rtcidle

The directories cron and at contain standalone programs to check if the at and cron queues are checked correctly. Change to these directory and run make to compile these programs. They are only needed for testing, not for normal operation.

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.

If rtcidle.before returns a value different from 0, suspension is canceled. This return value is the passed to /etc/rtcidle.after, which is still executed.

Options

The first options are mainly intended for testing. The first two do not run the rtcidle.before and rtcidle.after scripts, unless the third is given. The first script is passed the timestamp of the wakeup time, and if it returns a value different from zero then suspension is canceled. The second script is passed the return value of the first.

-a
test the alarm only: the program should wait ten seconds, then terminate
-s
test suspend: the computer should go in suspension, waking up in ten seconds
-e
include execution of /etc/rtcidle.before and /etc/rtcidle.after in the test
-t seconds
use this number of seconds instead of ten
-w time
wake up at this time, specified as number of seconds since the Epoch
-i
immediate: do not wait for user inactivity upon launch; at wakeup, run as usual
-d
do not run as a daemon;
without -i, just show the time of next cron or at job
-y
standby instead of suspend
-Y
first standby, then suspend (may be useful if the system wakes up immediately at the first attempt but not at the second)
-n
do not check /dev/input/event* for user activity (which requires kernel module evdev), only the interrupts

Note: rtcidle only tests activity of the input devices (keyboard, mouse, etc.) on the local machine. As a result, the activity of a user working from a remote host (e.g., with ssh) will be missed. Run "waiting -i" in background to avoid suspension, kill it before logging out.

Kernel

A power management module (either apm or acpi) is required, as well as a real-time clock module (either the old rtc module or the new rtc-cmos). In order to compile the old rtc module, a patch to drivers/char/Kconfig is required:
	- if RTC_LIB
	+ if RTC_CLASS
If the system appears to enter suspension but comes out of it immediately, the problem may be some component that wakes it up. This can be found out by:

Notes


sourceforge page