Acpid can't execute scripts
Mia Lopez
I have an old laptop and I installed Ubuntu 20.04 LTS Server edition (no GUI, just CLI). It managed via SSH so its display is unnecessary. I would like to turn off the display when I close the lid, and turn on again if I open it.
I've successfully configured acpid to manage the display.
In /etc/acpi/events I created a file:
event=button/lid.*
action=/etc/acpi/lid.shThe script:
#!/bin/sh
grep -q closed /proc/acpi/button/lid/LID/state
if [ $? = 0 ]
then # close action setterm --blank force
else # open action setterm --blank poke
fiIf I run this script manually, it works perfectly, however it seems that acpi can't run the script:
$ sudo journalctl -u acpid -f
...
Jul 04 20:03:01 server acpid[1179]: received input layer event "button/lid LID close"
Jul 04 20:03:01 server acpid[1179]: rule from /etc/acpi/events/lid matched
Jul 04 20:03:01 server acpid[1353]: executing action "/etc/acpi/lid.sh"
Jul 04 20:03:01 server acpid[1179]: action exited with status 1
Jul 04 20:03:01 server acpid[1179]: 1 total rule matched
Jul 04 20:03:01 server acpid[1179]: completed input layer event "button/lid LID close"
...Error: action exited with status 1 (not 0)
If i know right, exit code 1 is a permission issue (operation not permitted). I don't know why is it "not permitted", because I don't need to use sudo to run this script.
1 Answer
So finally I figured out what was the problem.
As steeldriver mentioned, setterm needs to be run inside a terminal (in front of the laptop), and in my script it wasn't connected to a real terminal and setterm could change nothing.
According to this post, we need to redirect the output or input to/from the console.
So I modified my script:
#!/bin/sh
grep -q closed /proc/acpi/button/lid/LID/state
if [ $? = 0 ]
then # close action setterm -term linux --blank force </dev/tty1
else # open action setterm -term linux --blank poke </dev/tty1
fiI tested this script and it's work like a charm ;)