On the bottom of this answer are instructions for installing sleepd if you really insist. However that package is pretty much outdated for modern hardware.
If you are going to write a program, you can consider the following sources:
Instead of using sleep(3)
in the code (like sleepd does), it is more battery-friendly if you use poll(3)
or select(3)
which have a timeout parameter. (This assumes that the /dev/input/*
devices are poll-able, I don't know if that is the case but you should look up the documentation)
Upstream (git repo) has already removed the default hal dependency (commit), so you can try building from sources. The following commands were tested in a Kubuntu 13.10 Live environment. It installs the build dependencies, fixes a bug in the Makefile that prevented HAL from getting disabled and finally creates a deb package.
sudo apt-get install build-essential git debhelper libapm-dev
git clone git://git.kitenet.net/sleepd.git
cd sleepd
sed 's/ifdef USE_HAL/ifeq ($(USE_HAL), 1)/' -i Makefile
dpkg-buildpackage -b -us -uc
This produces a sleepd_2.05_amd64.deb
package in the parent directory which you can then install on machines. This package requires a battery or AC interface to be present (e.g. /sys/class/power_supply/*
), otherwise it will try APM. Since modern machines do not use APM, but ACPI, it will exit silently.
So while the package builds and install fine, you are better off with writing a new daemon if something like this is not already implemented.