RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    Help with systemd service to save mame 2003 plus metadata at shutdown

    Scheduled Pinned Locked Moved Help and Support
    shutdown scriptsystemdmetadata issuesmame 2003 plus
    4 Posts 3 Posters 314 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      james.milroy
      last edited by

      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!!

      WeirdHW 1 Reply Last reply Reply Quote 0
      • mituM
        mitu Global Moderator
        last edited by mitu

        @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 the systemd service - when a shutdown is issued, the running programs will be stopped before your service is even started.

        1 Reply Last reply Reply Quote 1
        • WeirdHW
          WeirdH @james.milroy
          last edited by WeirdH

          @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.

          1 Reply Last reply Reply Quote 0
          • J
            james.milroy
            last edited by james.milroy

            @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 of autostart.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?

            1 Reply Last reply Reply Quote 0
            • First post
              Last post

            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.