Multi Switch Shutdown Script!
-
@cloudlink Yes! Remove old version before and just download the newest. So first use point 3.1 and then do point 3.0 from instructions ;) But there are just a small things improved. It's just better documented now and some calls are much much cleaner. The biggest point is the possibility to setup GPIOs via commandline now and I differ between kill -15 and kill -9 signal now. I try to use kill -15 in first instance. If after 2 seconds the process is still active... kill level 9 is used. kill -9 can make some problems and it should only be used as last resort.
So I use this only for emulators.... you can test for example withpifba
. This isn't closed with kill -15 so after 2 seconds the emulator will close caused by kill -9 signal.@caver01 I tried to use a kind of systemd-like call. But I wasn't able to integrate this into the shutdown service. The call to should be
ExecStop=path/to/multi_switch.sh --es-systemd
but It didn't work. Even a call to killes.sh that calls the multi_switch.sh and waits several seconds.... Did not work! I hope the service can be done to rework again! -
@cyperghost said in Multi Switch Shutdown Script!:
@caver01 I tried to use a kind of systemd-like call. But I wasn't able to integrate this into the shutdown service. The call to should be ExecStop=path/to/multi_switch.sh --es-systemd but It didn't work. Even a call to killes.sh that calls the multi_switch.sh and waits several seconds.... Did not work!
Bummer. This was exactly what I wanted to do. I wonder if needed subsystems are closing before the call.
-
-
@cyperghost I see what you were doing. . . you were actually trying to define the service using
multi_switch.sh --es-systemd
. I guess I was simply going to call themulti_switch.sh
from meleu's service instead. I need to look at it and see how it is setup now. I wonder if the problem is what others are seeing--that even meleu's service is not working correctly now. -
@caver01 Yes...
My first try was the
ExecStop=
then later I used the
killes.sh
script and wrote just#!/bin/bash /path/to/multi_switch.sh --es-systemd sleep 10
Made it executable with chmod a+x .... Did not work. So I think the service isn't working anymore. Maybe I've done something wrong?
I think there is no difference to call a bash file with parameters or to call it without ;) But I'm not sure if these systemd services can parse commandlines.... I think yes! But that's the difference of a hobby user like me and someone who really digs deep into unix systems ;) -
@cyperghost Ok, so on my main arcade build (custom case, Mausberry Switch, dedicated momentary power button, GPIO-->transistor trigger), I dropped in your
multi_switch
. I updating my Python script that watches the GPIO triggered by the switch on the Mausberry. Now, instead of doing the traditional kill PIDs and killES, I simply callmulti_switch --es-poweroff
. Fast and done. The Pi shuts down, Mausberry detects the drop on the other GPIO and cuts the power.For soft shutdown, I updated Meleu's service. My version of the service has been doing two things: First, it triggers the Mausberry via GPIO to the transistor which in turn closes the power switch. Second, it did the old emulator PID lookup and kill, plus killES. These commands got replaced with the
multi_switch --es-poweroff
call again.This works great, although I should say that my system is still running the previous RetroPie image (4.3, Jessie).
We know that using the switch works great. We also know that soft shutdown also leads to the Mausberry cutting power correctly. So, I am certain that the service is triggering the transistor. What I don't know is if the trigger is getting picked up by the python script FIRST which calls
multi_switch
or if the call is being made by the service. Either way, my metadata is getting saved.I could try removing the call to multi_switch from meleu's service. That way, the only thing the service is doing is triggering the switch. I may just leave it alone.
-
@caver01 Yes the scripts are called by the service but somehow the sleep commands are ignored.
You can place the transistor call to
/lib/systemd/system-shutdown/
as script.
Then make the script executable.... Be aware to place the shebang#!/bin/sh
in first line!You can use the same technique like I've done in Exposed Shim ON OFF
With the script you can differ between reboots, shutdowns.... so the trigger can be called only by shutdown (=poweroff) and reboots.
-
@caver01 said in Multi Switch Shutdown Script!:
We know that using the switch works great. We also know that soft shutdown also leads to the Mausberry cutting power correctly. So, I am certain that the service is triggering the transistor. What I don't know is if the trigger is getting picked up by the python script FIRST which calls multi_switch or if the call is being made by the service. Either way, my metadata is getting saved.
So with this setup following happens.
The script is first triggered by your python script. It calls in first instance the multi_switch. The multi_switch closes all emulators and wait for ES to finish (so all metadata is saved!) then multi_switch is quit and gives control back to ES-script. The ES-script checks for apperance of files in /tmp-folder, this files trigger the further actions. It can be a restart of ES, a reboot of the system or a system shutdown!After that the service of meleu is initiated. So the service takes action AFTER all metadata is saved. I wasn't able to run the service in a proper way... so I can't say if it works proper in general :(
-
@cyperghost said in Multi Switch Shutdown Script!:
The script is first triggered by your python script
Not during a soft shutdown. For software-initiated, my python is not seeing anything until it detects the button "pressed" by the transistor. So, for soft shutdown, Meleu's service is triggering that. It is then a race between python calling multi_switch and the service calling multi_switch.
-
@caver01 Oh yes ;) Even on a soft shutdown it is clear what happens.
ES writes a metadta and file into /TMP folder and the binary quits. After that, shutdown is initiated and then meleus service takes action. Then if multi_switch is called indeed a seconds shutdown is initiated ...But I don't understand what you mean with "race" of the scripts. If you use the
--es-systemd
parameter I don't initiate annother shutdown. -
@cyperghost It is a race because before the script in Meleu's service calls multi_switch, it first triggers my GPIO transistor. When that happens, my python script calls multi_switch. So, one or the other call is going to make sure everything closes. I don't know which one finishes first.
-
@caver01 Ahhh........!
Yes!That makes it clear. But the solution for this is very easy. If you place a script to
/lib/systemd/system-shutdown
you call from there the trigger to your transisitor then the filesystem is already set to read only. Read more about here: Linux Stack Exchange and in this (late) state the system is miliseconds away for going to powerdown. That is the right moment to send signal to GPIO to "push" the button. The service also pushes arguments to callers. So the script can decide between shutdowns, reboots and so you call the trigger just inpoweroff
state.I did it here.... Exposed Shim ON OFF and also here in my Yet annother NESPi case mod also with a Mausberry build in and so there is no race against two shutdowns ;)
So in your case remove the "GPIO trigger"-part from meleus service right to annother script that is placed to
/lib/systemd/system-shutdown/
-folder. You need sudo command for this as this files are property of root. -
@cyperghost are you saying I can just put a bash script into
/lib/systemd/system-shutdown/
and it will execute during shutdown? Why do we need meleu's service? -
@caver01 said in Multi Switch Shutdown Script!:
@cyperghost are you saying I can just put a bash script into
/lib/systemd/system-shutdown/
and it will execute during shutdown?Yes! The systemd service automatically parses shutdown status to any scripts in this folder. So $1 can be poweroff, halt, reboot and you can initiate actions by this.
Why do we need meleu's service?
Well.... I don't know if the service is still useable. Some people report is does not work proper anymore. I tried, too - but also failed for proper shutdown. So the service is sadly out of service. And imho the service is usefull not to push triggers like you (ab)use it ... more to just prober shutdown ES ;)
BUT if it will work you would never have to modify button scripts. They just initiate a shutdown and the service automatically shuts down emulators and ES. That's the great advantage.
I modified the original NESPi+ python script for example and added an if/then clause. If butto nis pressed and if ES-PID is active then use multi_switch with es-poweroff switch, else use regular shutdown.
If the service would work again the python script would be just. If button is pressed then use regular shutdown.But imho it's still a flavour what you want to do and how far you understand what you do.
-
@cyperghost I guess we have several options, but I do like your script—one script for several uses. It just makes sense.
-
@caver01 The intention to write this script is a bit more.
- It should provide an easy all in one solution for people who use several switch devices (A simple Button connected to GPIO and ground, both NESPi case types, or the Pimonori ONOFF Shim or the Mausberry switch)
- It provides a solution if people use several button to make "reset" actions. So the script can be written to just finish any emulators if they are active, or to restart ES, or to reboot the whole system if button is held down for more than 5 seconds. This is all possible if you use the regular switches.
- Personally! I'm owner of 4 of the 5 devices the script supports I have a Mausberry in a NESPi case, I've a NESPi+ case, I've a Pimonori Switch and on my old B1 I've a some single push buttons only. And the setup to perform shutdown with this script was never easier to do now. Exactly as you said...
3.1 Use the script and make calls likemulti_switch.sh --es-poweroff
from any button script.
3.2 Personally I use it several time likemulti_switch.sh --generic powerbtn=23
3.3 Sometimes I do some coding on the mashine via SSH and the TV is not powerd on so just amulti_switch.sh --es-poweroff
shutdown the system cleanly with proper quitted ES.
3.4 I setted up a Pimonori Switch on my OwnCloudSystem so there is also just a proper call tomulti_switch.sh --onoffshimm
Nevertheless I hope @meleu reactivates the shutdown service again.
-
I'd love to see this working for the Kintaro 9000 case. They've been working on the meta data issue for a while now.
-
hello, i have a question.. i have a nespi case.. but my mod made it have two buttons.. made power button work as intended.. my plan first was to solder the reset button on RUN header to have a hard reset in case of crashes and use power to soft reset..
i found your script.. and im here to ask if there is any change of using the reset button as generic too?
tldr: can i use this scrip with two generic buttons?
edit:
this solved for me
/home/pi/RetroPie/scripts/multi_switch.sh --nespicase powerbtn=3 resetbtn=4 & -
@quackwalks Well you modify the python script and integrate the arguments
multi_switch.sh
offers to get it full working with your kintaro. A way how it can be done I offered here for the NESPi+ case.. You can use the return values of--ES-PID
(= ask if EmulationStation is running) and--RC-PID
(= ask if there is a emulator running in background) to decide to do actions.As long as I don't have this case I don't do anything to integrate this in the script. It can be done, I know ... but it took several days to get the NESPi+ working ... at last I bought one then the settings were done in less then a few hours.
-
Thx to @fastpop72 he gave positive answer in getting this invoked into python script
Tired on bash scripts? Get a functional shutdown for your NESPi+ on python
Took a journey on python scripting (really easy, and the script could be improved!) but it works best.... it shows same behaviour as multi_switch as bash call.
1. If you press restart if emulator is currently running, then you will be kicked back to ES main menu 2. If you press restart in ES main screen, ES will be restartet (no reboot!), good for quick saving metadata or internal saves. 3. If you press power-off then Raspberry will shutdown All metadata is always saved Best -> cyperghost
You can install the script with
wget -O - "https://raw.githubusercontent.com/crcerror/retroflag-picase/master/install.sh" | sudo bash
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.