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

    ensuring ES gracefully finish and save metadata in every system shutdown

    Scheduled Pinned Locked Moved Help and Support
    shutdown scriptemulationstatiofavoriteslast playedmetadata issues
    96 Posts 26 Posters 41.6k 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.
    • caver01C
      caver01 @cyperghost
      last edited by

      @cyperghost This looks like a solution that would survive RetroPie updates and is very similar to how I am triggering the transistor on my system. Question, do you know if these gets called during a reboot too, or just during a shutdown/poweroff?

      Also, now that I have a Nespi case, I will be using its built-in switch for power (hardware modded of course). The Mausberry circuit can apparently be used with either a true ON/OFF switch, or with a momentary switch. Up until now, I have used a momentary, and our transistor/mosfet/diode trick has been a requirement to "poke" the circuit during a software shutdown. I wonder how this behavior will change with the Nespi switch? I will have to do some tests to see if a regular on/off switch is immune to the stuck power issue.

      I will be using my reset switch to trigger exiting like @lostless.

      My 4-player cocktail style cabinet built as a custom "roadcase"

      cyperghostC 1 Reply Last reply Reply Quote 0
      • cyperghostC
        cyperghost @caver01
        last edited by cyperghost

        @caver01 said in ensuring ES gracefully finish and save metadata in every system shutdown:

        I wonder how this behavior will change with the Nespi switch?

        Sorry, the NESPi Power Switch is a non momentary switch - I removed this with a momentary in my build. If you have a latching (= non momentary) switch then a software shutdown does not work in general!

        these gets called during a reboot too, or just during a shutdown/poweroff?

        if [ "$1" = "poweroff" ]; then

        The GPIO action is called only on shutdown caused by the if clause in the bash script
        The systemd process triggers all scripts stored in the folders /lib/systemd.../ and calls the current shutdown level via command call and furthermore systemd waits that all scripts get regular closed. So if you reboot the command call $1 would be reboot, a shutdown is called poweroff

        So you can extend the script by a reboot case and let a LED blink for example.

        As I already mentioned .... This is a general solution

        caver01C 1 Reply Last reply Reply Quote 0
        • caver01C
          caver01 @cyperghost
          last edited by

          @cyperghost That's fantastic! So, you found the definitive answer to the shutdown vs. reboot problem. Way to go!

          My 4-player cocktail style cabinet built as a custom "roadcase"

          cyperghostC 1 Reply Last reply Reply Quote 0
          • cyperghostC
            cyperghost @caver01
            last edited by

            @caver01 Yes, that's the solution for this problem so far. But don't thank me (directly), it were the people from PIMORONI and theirclean SHIM shutdown daemon here that give me hints how this work. The solution is nested into the setup script ;)

            1 Reply Last reply Reply Quote 1
            • meleuM
              meleu @cyperghost
              last edited by

              @cyperghost said in ensuring ES gracefully finish and save metadata in every system shutdown:

              Can you link this posting in your first posting please?

              Done!

              Thanks for sharing. ;)

              • Useful topics
              • joystick-selection tool
              • rpie-art tool
              • achievements I made
              1 Reply Last reply Reply Quote 1
              • S
                Semper 5
                last edited by Semper 5

                this script had been working great until about 2 days ago. I noticed it stopped saving my favorites.

                i add a game to favorites, power down, then on, and no changes to my list.

                I completely wiped the whole card and I'm back to the same nonsense:

                metadata save results:
                MENU shutdown - will save
                MENU reboot system - will save
                MENU restart ES - will save

                soft shutdown button on NESpi - will NOT save

                could somebody help, or explain please?

                meleuM 1 Reply Last reply Reply Quote 0
                • G
                  G30FF
                  last edited by G30FF

                  I just modded my NESPi case with the safe shutdown hack by Yahmez (https://retropie.org.uk/forum/topic/12424/retroflag-nespi-case-soft-power-reset-hack). I used the version of his script that turns the Reset button into a "quit emulator" button. I also set up this script exactly as described in the OP, same paths, same files, everything. But ES metadata is not being saved on shutdown or reboot.

                  The killes script is working fine. If I run killes directly, everything behaves as it should. The problem is something to do with the killes.service systemd unit. Systemctl status reports that the service is loaded, and the Active status is "active (exited)". The killes.service file is exactly as it appears in the OP, and is in the same location. I don't think it has anything to do with the NESPi script mentioned above, as it doesn't save the metadata if I call "sudo shutdown now" from SSH or the terminal either. Any help would be greatly appreciated.

                  1 Reply Last reply Reply Quote 0
                  • meleuM
                    meleu @Semper 5
                    last edited by

                    @semper-5 @G30FF hey guys. I'll try to take a look at it soon. Thanks for the reports.

                    • Useful topics
                    • joystick-selection tool
                    • rpie-art tool
                    • achievements I made
                    cyperghostC 1 Reply Last reply Reply Quote 0
                    • cyperghostC
                      cyperghost @meleu
                      last edited by

                      @meleu Is the line touch /tmp/es-shutdown && chown pi:pi /tmp/es-shutdown still relevant?

                      meleuM 1 Reply Last reply Reply Quote 0
                      • meleuM
                        meleu @cyperghost
                        last edited by

                        @cyperghost forgive my memory, but where are we using that line?

                        • Useful topics
                        • joystick-selection tool
                        • rpie-art tool
                        • achievements I made
                        cyperghostC 1 Reply Last reply Reply Quote 0
                        • cyperghostC
                          cyperghost @meleu
                          last edited by cyperghost

                          @meleu https://retropie.org.uk/forum/topic/11750/mausberry-shutdown-script-doesn-t-save-metadata

                          It was the base code developed in this thread.
                          But I really don't know if you need this in your script.

                          It is a fact that if you kill the binary the emulationstation.sh is still active and it waits for a file es-shutdown, es-sysrestart.... whatever ... to do action and to finish ES properly. But I really don't know if it's needed here and if it's the culprit.
                          I don't think so... I really doubt it.

                          Maybe the two guys are using an older version of the killes script?
                          And then updated the runcommand.sh?

                          S 1 Reply Last reply Reply Quote 0
                          • S
                            Semper 5 @cyperghost
                            last edited by

                            @cyperghost I would like to add that, like G30FF mentioned, this is exactly where I got the script from and how I went about putting it into my system with the NESpi. Maybe that's a clue to what you were mentioning we might be running the same old script? Anyways just a thought.

                            1 Reply Last reply Reply Quote 1
                            • stooS
                              stoo
                              last edited by

                              Does ES only save metadata on shutdown?

                              Wouldn't it make sense to just flush metadata to storage every X minutes if there are changes? At least then you only lose very recent changes if ES goes down "unclean".

                              dankcushionsD 1 Reply Last reply Reply Quote 0
                              • F
                                Fitz2380
                                last edited by

                                I too am having the issue of saving Metadata. In particular the favorites and last game played. I have defined a 'system' called Power which appears on my ribbon menu and when I select it, I can do a restart or powerdown. They perform either a shutdown or a shutdown -r command. I implemented the service as defined above and can see that the killes service get started, but neither of my shutdown commands results in the meta data being saved.

                                1 Reply Last reply Reply Quote 1
                                • YahmezY
                                  Yahmez
                                  last edited by

                                  For what it's worth, I just made a fresh retropie install for another modded nespi. Installed the scripts for safe shutdown exactly as outlined in the PDF and then installed @meleu killes script as explained in the OP. Everything works fine, metadata is saving.

                                  meleuM B 2 Replies Last reply Reply Quote 1
                                  • meleuM
                                    meleu @Yahmez
                                    last edited by meleu

                                    @yahmez phew!
                                    phew

                                    • Useful topics
                                    • joystick-selection tool
                                    • rpie-art tool
                                    • achievements I made
                                    YahmezY 1 Reply Last reply Reply Quote 2
                                    • YahmezY
                                      Yahmez @meleu
                                      last edited by

                                      @meleu God, I miss that guy.

                                      1 Reply Last reply Reply Quote 0
                                      • dankcushionsD
                                        dankcushions Global Moderator @stoo
                                        last edited by

                                        @stoo said in ensuring ES gracefully finish and save metadata in every system shutdown:

                                        Does ES only save metadata on shutdown?

                                        Wouldn't it make sense to just flush metadata to storage every X minutes if there are changes? At least then you only lose very recent changes if ES goes down "unclean".

                                        most stuff in retropie only saves on exit - game saves will only save to disk on exit of a game. retroarch settings only save on exit of retroarch, etc.

                                        when you're dealing with SD card storage, you generally don't want to do multiple writes; it will kill your card quicker, especially with something as intense as an ES xml write.

                                        meleuM stooS 2 Replies Last reply Reply Quote 0
                                        • S
                                          stet
                                          last edited by

                                          I just wanted to put in my thanks for putting this together. I use a RemotePi board to power down my RetroPie setup and this solved the problem of ES not saving the favorites list. :)

                                          1 Reply Last reply Reply Quote 0
                                          • meleuM
                                            meleu @dankcushions
                                            last edited by

                                            @dankcushions You just gave me an idea for a feature request: an option on the ES menu to Save Current Metadata (something like the "Save Current Configuration" on RetroArch) Then a careful user can do it to prevent loss of data.

                                            My suggestion for such option: in the OPTIONS menu (the one that appears when the users press Select).

                                            @Zigurana @Hex @pjft @jdrassa and other ES hackers, do you guys think it's feasible?

                                            • Useful topics
                                            • joystick-selection tool
                                            • rpie-art tool
                                            • achievements I made
                                            dankcushionsD 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.