PINE64
Power LED Heartbeat script - Printable Version

+- PINE64 (https://forum.pine64.org)
+-- Forum: PINE A64(+) (https://forum.pine64.org/forumdisplay.php?fid=4)
+--- Forum: Pine A64 Hardware, Accessories and POT (https://forum.pine64.org/forumdisplay.php?fid=32)
+---- Forum: Pi2, Euler and Exp GPIO Ports (https://forum.pine64.org/forumdisplay.php?fid=34)
+---- Thread: Power LED Heartbeat script (/showthread.php?tid=2234)



Power LED Heartbeat script - pfeerick - 09-18-2016

Just thought I'd post the current version of the shell script I am using on my Pine64 to make the user controllable System LED (the one that you can attach near the headphones jack, or via the EXP header). I added it to /etc/rc.local (make sure you put an " & " at the end, so it doesn't block rc.local continuing / exiting), so now every time the pine64 starts up, I get a little heartbeat indicator going so I know it's running ok. Since it's a gist, you can also download it via wget or curl... just copy the URL you get from the 'raw' button up the top right. 

Next step will be working out how to intercept the power button... perhaps via udev, since that already responds to the power button interrupt, but doesn't know what to do with it out of the box. 

https://gist.github.com/pfeerick/00b04df3ce65979158b117b4e1f7c168


RE: Power LED Heartbeat script - tkaiser - 09-18-2016

Did you try out installation of acpid package? See here for example: http://forum.armbian.com/index.php/topic/872-beelink-x2-with-armbian-possible/?p=11137


RE: Power LED Heartbeat script - pfeerick - 09-18-2016

(09-18-2016, 06:25 AM)tkaiser Wrote: Did you try out installation of acpid package? See here for example: http://forum.armbian.com/index.php/topic/872-beelink-x2-with-armbian-possible/?p=11137

Hm... no I haven't. Looks much easier to implement than a udev rule also, so will definitely give that a try... I'm sure you'll say udev is easy, but I don't agree... its confusing... but then again... maybe I need to RTFM? :-D 

What I had done previously was this. Basically, one udev rule which connects the power button event to the shutdown event. As a result, pine64 would do a controlled shutdown in response to the power button being pressed.


RE: Power LED Heartbeat script - pfeerick - 09-20-2016

tkaiser Wrote:Did you try out installation of acpid package? See here for example: http://forum.armbian.com/index.php/topic/872-beelink-x2-with-armbian-possible/?p=11137

Had a look at the acpid package, and it worked beautifully. The acpi_listen command returned

Quote:button/power PBTN 00000080 00000000

just like in your example for the Beelink X2 when I pressed the pine64s power button, so I did a line similar to yours:

Quote:echo -e 'event=button/power\naction=/etc/acpi/trigger-shutdown.sh' >/etc/acpi/events/powerbtn

However my script is a little different as it kills the heart-beat script, kills the rapid flash script just in case the button is pressed multiple times,  runs a rapid flash system led flash script, and then does requests shutdown with 2 minutes grace. Could be a lot better still, at least it gives a little warning before the pine64s untimely demise.  Wink  I also need to work out how to handle the case where the shutdown is canceled, so it can resume the heartbeat (perhaps also making it one script that can switch modes?), but that is a problem for another day.

Quote:#!/bin/bash
ps aux | grep -ie pine64-SYSLED-heartbeat | grep -v grep | awk '{print $2}' | xargs kill -9
ps aux | grep -ie pine64-SYSLED-rapid | grep -v grep | awk '{print $2}' | xargs kill -9

/usr/local/sbin/pine64-SYSLED-rapid.sh &
shutdown -h +2
Obviously, if you just want the pine64 to basically drop dead gracefully initiate shutdown on the press of the power button... you could still do this instead:
Quote:echo -e '#!/bin/bash\nshutdown -h now' >/etc/acpi/trigger-shutdown.sh

And of course, don't forget to


Quote:chmod 755 /etc/acpi/trigger-shutdown.sh

Thanks for the examples and hint! Smile