daemon for power button

Ethernet disk mini v2
Post Reply
petris
Posts: 8
Joined: Thu Jun 12, 2008 10:59 pm
Location: Kladno, Czech Republic
Contact:

daemon for power button

Post by petris » Mon Oct 27, 2008 11:12 pm

EDIT: I've updated the daemon. It now supports configuration file and has nice manual page. It's available on http://malat.biz/view/Projects/ButtonDaemon

OLD (now obsolete) POST FOLLOWS:
I've written simple daemon for handling powerbutton events. It's possible to define intervals and if button is pressed for the time from defined interval, the asociated command is executed.

Usage
1. Create buttom device

Code: Select all

mknod /dev/pwrbtn c 13 64
2. Edit buttond.c:
Customize this structure:

Code: Select all

const struct action_s actions[] = {
        {0., 1.5, "shutdown -h now"}, /* If the power button is pressed for any time from interval (0, 1.5) seconds, "shutdown -h now" will by executed */
        {4., 8.,  "ifconfig eth0 192.168.1.1 netmask 255.255.255.0"}
};
3. Compile

Code: Select all

gcc -Os -Wall -o buttond buttond.c
strip buttond
4. Run it

Code: Select all

./buttond -d /dev/pwrbtn
This is probably usefull only if you are running nonoriginal distribution like me. Tested with vanilla kenel-2.6.28-rc1 on debian lenny ;-)
Last edited by petris on Wed Oct 07, 2009 7:38 pm, edited 1 time in total.

kosmaty
Posts: 32
Joined: Sat May 17, 2008 2:57 pm

Re: daemon for power button

Post by kosmaty » Sat Nov 01, 2008 9:46 pm

Could you tell me, does your EDv2 turn off completely after "shutdown -h now" or "poweroff"? In my case, HDDs turn off, but FAN works and LED doesn't stop lighting.

I have the same configuration as you, except I have EBD.

rosbif
Posts: 112
Joined: Thu May 08, 2008 11:23 am
Location: near Toulouse, France

Re: daemon for power button

Post by rosbif » Sat Nov 01, 2008 11:18 pm

kosmaty wrote:Could you tell me, does your EDv2 turn off completely after "shutdown -h now" or "poweroff"? In my case, HDDs turn off, but FAN works and LED doesn't stop lighting.
I am afraid that I have not had time to try petris' daemon yet.
However I am pretty sure that these commands will cause the EDmini v2 (and the EBD) to reboot rather than to power-off :(
We spoke about this in this EBD topic: http://forums.nas-central.org/viewtopic ... rt=15#p951
The procedure described there works with the stock kernel but I don't think that it will work with the mainline kernel.
The actual power-off is done by U-Boot and to cause it a special flag has to be written in the I2C EEPROM.
Unfortunately I don't think that the I2C EEPROM is currently detected in the mainline kernel :(

Post Reply