Help with systemd service to save mame 2003 plus metadata at shutdown
-
I've been really struggling with this one, I have had help from @barbudreadmon and @meleu but I feel I'm missing something really simple here. I'm trying to manipulate the shutdown sequence so that mame2003plus can save hi-scores etc. If I quit out of the emulator manually, everything is saved ok, however if I press my power button (connected to a Picade X HAT) to shutdown whilst mame is running, nothing is saved/updated.
What I have at the moment is a really simple script which when run quits out of mame and saves the metadata. This works when called from the command line via PuTTY whilst mame is running, so I know that part is OK.#!/bin/bash killall -s SIGTERM retroarch sleep 5
I also have a systemd service written with help from posts by @barbudreadmon and @meleu which works when initiated from PuTTY but isn't working when I press my button to shutdown. Here is what I've got so far:
[Unit] Description=Save mame hiscores on shutdown DefaultDependencies=no After=unmount.target [Service] Type=oneshot RemainAfterExit=true ExecStart=/usr/lib/systemd/scripts/mamesave.sh TimeoutStartSec=0 [Install] WantedBy=unmount.target
The service needs to run before the shutdown sequence makes the file system read-only, preventing mame from saving its metadata. I figured, I'd need to get the service to execute before unmount.target made the filesystem read-only. I'm not really Linux savvy but I'm trying my best. This is the last thing I need working to perfect my setup. Help please!!
-
@cyperghost has a nifty shutdown script which can be used with various GPIO shutdown configurations, look it up at https://github.com/crcerror/ES-generic-shutdown.
You don't need thesystemd
service - when a shutdown is issued, the running programs will be stopped before your service is even started. -
@james-milroy Was about to post the same thing as mitu. This script is fantastic. At first, it might a bit of a chore to figure out what configuration you need for your specific case, but once you do, it's a case of 'set it and forget it'.
I just have a regular concave arcade button (NO - normal open) at the back of my cab, with its two wires going to relevant GPIO pins. Set it as a generic button in
autostart.sh
and everything works as expected, everytime, no hassle. Definitely try it out. -
@cyperghost , I have installed your
multi_switch.sh
script on my setup but it's not working. I've set it up for onoffshim as I'm using a Pimoroni PicadeX hat. If I run the script from the command line, it works as expected, but if I press the power button to shutdown, it doesn't save hi-scores etc. I have just double checked everything and now the Pi has went into a loop of shutting down straight after it executes the script in the first line ofautostart.sh
. I must be making a mistake somewhere, just darned if I know what I've done wrong!I've used another SD card to boot up and get access to my setup. Here is my
autostart.sh
file. I load the script, then use Runcommand to run my chosen emulator and ROM, then finally if I quit out of the emulator, it loads emulationstation.sudo /home/pi/RetroPie/scripts/multi_switch.sh --onoffshim & /opt/retropie/supplementary/runcommand/runcommand.sh 0 _SYS_ "arcade" "/home/pi/RetroPie/roms/arcade/starwars.zip" wait $1 emulationstation --no-splash #auto
I've removed the sudo command from the first line and I can get back in again. Any ideas on what's going wrong?
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.