1

I'm new to programming for Linux (lubuntu specifically) and I'm working on a project to get an old, discarded laptop up and running the way I want it. I have acpi and acpid installed, and when I run the acpi command, I]m informed of whether my laptop is plugged in (charging) or unplugged (discharging).

I would now like to have the laptop automatically hibernate when the laptop is discharging. My first thought was to write a script that would poll acpi every 30 seconds or so and then run a hibernate command whenever it responded with the word "discharging". However, I understand that acpid is the better tool to use, as it is more event-driven. I can't seem to find any material on making a laptop hibernate when unplugged - any advice?

1 Answer 1

1

The acpid daemon should receive battery events by ACPI subsystem. When you unplug/plug the laptop there should be related battery events. The events can be associated with actions like power off/suspend/hibernate the system and so on.

Firstly, try to verify it by watching /var/log/messages or related log files when you unplug the laptop. There should be something like

... ACPI action undefined: ...

If there is nothing you can try acpi_listen command which connects to acpid and listens for events.

Then, you can configure a generic event handler under the /etc/acpi/events directory for battery events. Create there a file e.g. battery.conf with the following content:

event=battery.*
action=/etc/acpi/actions/battery.sh

It says that any battery event should be processed by the script battery.sh. In this script, I would monitor the battery status available from the /proc/acpi/battery/*/state file. Especially, check the line "charging state" which should change to "discharging" when you unplug the laptop or "charging/charged" when you plug it back.

Based on this information, you can run the hibernate command from the event handler battery.sh. Furthermore, you can find some other useful examples e.g. on github.

3
  • I can confirm that acpid is running, but I don't think it's creating an event when I unplug the laptop. I set up the battery.conf and battery.sh files, and in battery.sh I just make a popup using xmessage. Running the .sh file manually works, but it is not executed when I unplug my laptop. Also, running acpi_listen doesn't show me anything when I unplug the laptop. The only difference I see is that if I run acpi, it says "charging" when plugged in, but "discharging" when I unplug. Any advice?
    – Jake
    Aug 23, 2013 at 3:42
  • Are there any files under /proc/acpi/battery/ ?
    – dsmsk80
    Aug 23, 2013 at 7:12
  • Sorry for the delay in answering. no, the only things in /proc/acpi are button (directory), event (file), and wakeup (file)
    – Jake
    Aug 27, 2013 at 13:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .