Tiny Core Linux
Tiny Core Base => CorePlus => Topic started by: evertvaningen 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?
-
google is your friend...
-
Please...
-
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.
-
Like...
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:
#!/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!)
-
as per the acpid extension info file:
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: #!/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: $ cat /usr/local/etc/acpi/events/power-button
event=button/power
action=/usr/local/etc/acpi/actions/power-btn.sh
-
To test:
$ 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"
-
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
$ 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
#!/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
-
You need to create two files:
/usr/local/etc/acpi/actions/powerbtn.sh
containing: #!/bin/sh
exitcheck.sh
/usr/local/etc/acpi/events/power-button
containing: event=button/power
action=/usr/local/etc/acpi/actions/powerbtn.sh
-
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"
-
Is powerbtn.sh set as executable?
$ sudo chmod +x /usr/local/etc/acpi/actions/powerbtn.sh
-
Is powerbtn.sh set as executable?
$ sudo chmod +x /usr/local/etc/acpi/actions/powerbtn.sh
It is now, it works thanks to you :D
-
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?
-
You need to add usr/local/etc/acpi to /opt/.filetool.lst before you do the backup.
-
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.
-
You don't need to run it every time, that was just to test things.
Start the acpi daemon via the init.d script for normal use.
-
What I did with my own understanding. :) it works :P
nano /home/tc/.X.d/run.sh
Containing
#!/bin/sh
sudo acpid -dfl
Make it runnable...
sudo chmod +x /home/tc/.X.d/run.sh
Start the acpi daemon via the init.d script for normal use.
So edit the init.d file and add sudo acpi start
-
Add "/usr/local/etc/init.d/ acpid start" to /opt/bootlocal.sh
Do NOT edit the init.d file, and don't put anything in ~/.X.d.
-
Add "/usr/local/etc/init.d/ acpid start" to /opt/bootlocal.sh
Do NOT edit the init.d file, and don't put anything in ~/.X.d.
Got it...
Do NOT edit the init.d file, and don't put anything in ~/.X.d.
Why Gerald?
-
The init.d file works as distributed.
Don't break it.
-
don't put anything in ~/.X.d.
The scripts under ~/.X.d only execute whenever the X server starts.
Some users do not need X server on their machine.
/opt/bootlocal.sh is for system maintenance.
-
Add "/usr/local/etc/init.d/ acpid start" to /opt/bootlocal.sh
After boot button does nothing, still have to do sudo acpid start to get it to work.
-
It seems a space accidentally slipped in.
/usr/local/etc/init.d/ acpid start
should be
/usr/local/etc/init.d/acpid start
-
It seems a space accidentally slipped in.
/usr/local/etc/init.d/ acpid start
should be
/usr/local/etc/init.d/acpid start
It can happen, thank you... now my tutorial is complete.
You'll see ;)