WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: ⚡➔❌ Press Power Button to Shutdown  (Read 12454 times)

Offline evertvaningen

  • Jr. Member
  • **
  • Posts: 60
⚡➔❌ Press Power Button to Shutdown
« on: June 15, 2017, 07:22:18 AM »
PRESS POWER BUTTON TO SHUTDOWN

The idea is that a independent (no screen, keyboard or mouse) Internet radio can be started with a press of the power button and everything boots automatically. When you're done with listening you press the power button and Tiny Core Linux shuts down to be used another day.

Tiny Core Linux does not do this by default and I tried following the tutorial: http://wiki.tinycorelinux.net/wiki:using_acpid_to_control_your_pc_buttons

This is all Chinese to me...
Can one explain to me how it's done?

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14812
Re: ⚡➔❌ Press Power Button to Shutdown
« Reply #1 on: June 15, 2017, 07:59:10 AM »
google is your friend...

Offline evertvaningen

  • Jr. Member
  • **
  • Posts: 60
Re: ⚡➔❌ Press Power Button to Shutdown
« Reply #2 on: June 15, 2017, 08:01:45 AM »
Please...

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14812
Re: ⚡➔❌ Press Power Button to Shutdown
« Reply #3 on: June 15, 2017, 08:07:10 AM »
I'm sure with even a cursory search you will find several acpi scripts to suspend or shut-down when the power button is (briefly) pressed.

Offline evertvaningen

  • Jr. Member
  • **
  • Posts: 60
Re: ⚡➔❌ Press Power Button to Shutdown
« Reply #4 on: June 15, 2017, 08:13:09 AM »
Like...

Quote
That's simple enough. When you press the power button a ACPI event triggers the script at /etc/acpi/powerbtn.sh.

You can edit that to just run shutdown -h now as the first thing so it looks like:

Quote
#!/bin/sh
# /etc/acpi/powerbtn.sh
# Initiates a shutdown when the power putton has been
# pressed.

/sbin/shutdown -h now "Power button pressed"
exit 0

# leave the old code below (in case you want to revert!)

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14812
Re: ⚡➔❌ Press Power Button to Shutdown
« Reply #5 on: June 15, 2017, 08:49:39 AM »
as per the acpid extension info file:
Quote
to add acpid event handling:
                1. Add event capture file to /usr/local/etc/acpi/events
                2. Add script to /usr/local/etc/acpi/actions
                ----------
                to control acpid:
                $ sudo /usr/local/etc/init.d/acpid [start|stop|restart|status]
                ----------
                to trouble-shoot
                $ sudo acpid -dfl

..so you'd need something like:
Code: [Select]
#!/bin/sh
# /usr/local/etc/acpi/actions/powerbtn.sh
# Initiates a shutdown when the power putton has been
# pressed.

exitcheck.sh

..and something like this:
Code: [Select]
$ cat /usr/local/etc/acpi/events/power-button
event=button/power
action=/usr/local/etc/acpi/actions/power-btn.sh
« Last Edit: June 15, 2017, 08:57:53 AM by Juanito »

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14812
Re: ⚡➔❌ Press Power Button to Shutdown
« Reply #6 on: June 15, 2017, 09:03:30 AM »
To test:
Code: [Select]
$ tce-load -i acpid
$ cat /usr/local/etc/acpi/events/power-button
event=button/power
action=/usr/local/etc/acpi/actions/powerbtn.sh

$ cat /usr/local/etc/acpi/actions/powerbtn.sh
#!/bin/sh
echo "hello"

$ sudo acpid -dfl
...
netlink opened successfully
acpid: starting up with netlink and the input layer
parsing conf file /usr/local/etc/acpi/events/power-button
acpid: 1 rule loaded
acpid: waiting for events: event logging is on

[press power button briefly]

acpid: received input layer event "button/power PBTN 00000080 00000000"
acpid: rule from /usr/local/etc/acpi/events/power-button matched
acpid: executing action "/usr/local/etc/acpi/actions/powerbtn.sh"
BEGIN HANDLER MESSAGES
hello
END HANDLER MESSAGES
acpid: action exited with status 0
acpid: 1 total rule matched
acpid: completed input layer event "button/power PBTN 00000080 00000000"

Offline evertvaningen

  • Jr. Member
  • **
  • Posts: 60
Re: ⚡➔❌ Press Power Button to Shutdown
« Reply #7 on: June 15, 2017, 09:26:42 AM »
oww man  :-[
My brain locks up while seeing this.


Event file is     /usr/local/etc/acpi/events/power-button
Action file is    /usr/local/etc/acpi/actions/powerbtn.sh

Inside the event file is
Code: [Select]
$ cat /usr/local/etc/acpi/events/power-button
event=button/power
action=/usr/local/etc/acpi/actions/power-btn.sh

Inside the powerbtn.sh file is
Code: [Select]
#!/bin/sh
# /usr/local/etc/acpi/actions/powerbtn.sh
# Initiates a shutdown when the power putton has been
# pressed.

exitcheck.sh


I have no Idea
« Last Edit: June 15, 2017, 09:42:22 AM by evertvaningen »

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14812
Re: ⚡➔❌ Press Power Button to Shutdown
« Reply #8 on: June 15, 2017, 11:05:04 AM »
You need to create two files:

/usr/local/etc/acpi/actions/powerbtn.sh

containing:
Code: [Select]
#!/bin/sh
exitcheck.sh

/usr/local/etc/acpi/events/power-button

containing:
Code: [Select]
event=button/power
action=/usr/local/etc/acpi/actions/powerbtn.sh
« Last Edit: June 15, 2017, 11:06:36 AM by Juanito »

Offline evertvaningen

  • Jr. Member
  • **
  • Posts: 60
Re: ⚡➔❌ Press Power Button to Shutdown
« Reply #9 on: June 15, 2017, 02:14:08 PM »
Quote
tc@box:~$ sudo acpid -dfl
Deprecated /proc/acpi/event was not found.  Trying netlink and the input layer...
input layer /dev/input/event0 opened successfully
input layer /dev/input/event1 opened successfully
input layer /dev/input/event2 opened successfully
input layer /dev/input/event3 opened successfully
input layer /dev/input/event4 opened successfully
inotify fd: 8
inotify wd: 1
netlink opened successfully
acpid: starting up with netlink and the input layer
parsing conf file /usr/local/etc/acpi/events/power-button
acpid: 1 rule loaded
acpid: waiting for events: event logging is on
acpid: received input layer event "button/power PBTN 00000080 00000000"
acpid: rule from /usr/local/etc/acpi/events/power-button matched
acpid: executing action "/usr/local/etc/acpi/actions/powerbtn.sh"
BEGIN HANDLER MESSAGES
/bin/sh: /usr/local/etc/acpi/actions/powerbtn.sh: Permission denied
END HANDLER MESSAGES
acpid: action exited with status 126
acpid: 1 total rule matched
acpid: completed input layer event "button/power PBTN 00000080 00000000"
acpid: received netlink event "button/power LNXPWRBN:00 00000080 00000002"
acpid: rule from /usr/local/etc/acpi/events/power-button matched
acpid: executing action "/usr/local/etc/acpi/actions/powerbtn.sh"
BEGIN HANDLER MESSAGES
/bin/sh: /usr/local/etc/acpi/actions/powerbtn.sh: Permission denied
END HANDLER MESSAGES
acpid: action exited with status 126
acpid: 1 total rule matched
acpid: completed netlink event "button/power LNXPWRBN:00 00000080 00000002"

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14812
Re: ⚡➔❌ Press Power Button to Shutdown
« Reply #10 on: June 15, 2017, 02:19:43 PM »
Is powerbtn.sh set as executable?

Code: [Select]
$ sudo chmod +x /usr/local/etc/acpi/actions/powerbtn.sh

Offline evertvaningen

  • Jr. Member
  • **
  • Posts: 60
Re: ⚡➔❌ Press Power Button to Shutdown
« Reply #11 on: June 15, 2017, 02:25:17 PM »
Is powerbtn.sh set as executable?

Code: [Select]
$ sudo chmod +x /usr/local/etc/acpi/actions/powerbtn.sh

It is now, it works thanks to you :D

Offline evertvaningen

  • Jr. Member
  • **
  • Posts: 60
Re: ⚡➔❌ Press Power Button to Shutdown
« Reply #12 on: June 15, 2017, 02:47:35 PM »
So it worked but it shut down without making a backup so I needed to do it again. No problem but when I make the directories and the files and reboot with backup... the directories are gone again.

Lets try again then.


Even with $sudo backup it still puts everything back.


To test:
cd /usr/local/etc/acpi/
ls
(events/)
mkdir actions
sudo backup
sudo reboot

... actions directory is gone.


Juanito?
« Last Edit: June 15, 2017, 03:17:47 PM by evertvaningen »

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: ⚡➔❌ Press Power Button to Shutdown
« Reply #13 on: June 15, 2017, 03:51:12 PM »
You need to add usr/local/etc/acpi to /opt/.filetool.lst before you do the backup.

Offline evertvaningen

  • Jr. Member
  • **
  • Posts: 60
Re: ⚡➔❌ Press Power Button to Shutdown
« Reply #14 on: June 15, 2017, 03:57:15 PM »
You need to add usr/local/etc/acpi to /opt/.filetool.lst before you do the backup.

Omg... I thought of that but wasn't sure if that was the right thing to do.
I'm one step closer understanding Tiny Core Linux.

Why do I need to run $sudo acpid -dfl every time?
Without that command the "Press Power Button to Shutdown" won't work.
« Last Edit: June 15, 2017, 04:21:29 PM by evertvaningen »