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:

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

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


sourceforge page