RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login

    Mausberry Shutdown Script Doesn't Save Metadata

    Scheduled Pinned Locked Moved ControlBlock, PowerBlock & Co.
    mausberry
    251 Posts 10 Posters 95.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.
    • pjftP
      pjft
      last edited by

      That shouldn't have any effect, to be honest.

      1 Reply Last reply Reply Quote 0
      • hansolo77H
        hansolo77
        last edited by

        LOL WTF...

        Now it's working. I tested a different system from my Favorites, exited back to ES then powered off. That most recent game is now at the top of the Last Played list. Go figure. Maybe it just need to go through a complete "reboot" cycle after editing the script? I've also noticed that the Terminated indicator on the screen has gone away.

        Who's Scruffy Looking?

        1 Reply Last reply Reply Quote 0
        • pjftP
          pjft
          last edited by

          I'm thinking that whatever solution you have going on there at the moment is not reliable enough. :)

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

            @pjft I think there was a problem with file permission.
            But that should be solved via chmod.

            @hansolo77 Can the topic marked as solved? Are there any issues? Can you please post your GPIO script?

            1 Reply Last reply Reply Quote 0
            • hansolo77H
              hansolo77
              last edited by hansolo77

              I don't want to mark it as solved until I've done further testing. I'd like to see if it still saves if I'm playing a game and shut it down before returning to ES (probably won't, so the script might need updated). I also want to test to see if it saves after I play a game then let the screensaver run for a bit and shutdown during the screensaver. For now, the testing via direct system menu and via the Favorites menu seems to be working. I'm running out for a few hours so I won't be able to test again for some time. But fingers are crossed.

              Here's the script as it is right now:

              /etc/switch.sh

              #!/bin/bash
              
              #this is the GPIO pin connected to the lead on switch labeled OUT
              GPIOpin1=23
              
              #this is the GPIO pin connected to the lead on switch labeled IN
              GPIOpin2=24
              
              echo "$GPIOpin1" > /sys/class/gpio/export
              echo "in" > /sys/class/gpio/gpio$GPIOpin1/direction
              echo "$GPIOpin2" > /sys/class/gpio/export
              echo "out" > /sys/class/gpio/gpio$GPIOpin2/direction
              echo "1" > /sys/class/gpio/gpio$GPIOpin2/value
              while [ 1 = 1 ]; do
              power=$(cat /sys/class/gpio/gpio$GPIOpin1/value)
              if [ $power = 0 ]; then
              sleep 1
              else
              
              # End Emulationstation if condition of running binary is true (not tested!)
              # v1 07/21/17 by cyperghost - Inital run 
              # v1.1 07/22/17 - Added chown command to set right user permission for creating es-shutdown
              espid=$( pgrep -f "/opt/retropie/supplementary/.*/emulationstation([^.]|$)" ) # PID of binary only
              if [ "$espid" ]; then                                                         # Condition: PID is not equal 0 or empty then use ES shutdown
                 echo "ES binary is running - I'm using ES internal shutdown"
                 touch /tmp/es-shutdown && chown pi:pi /tmp/es-shutdown                     #v1.1 Change file permission of es-shutdown to user:group pi:pi
                 pkill -f "/opt/retropie/supplementary/.*/emulationstation([^.]|$)"
                 exit
              else
                 echo "ES binary is closed - I proceed with usual shutdown"
              fi
              # End Emulationstation if condition of running binary is true (not tested!)
              
              sudo poweroff
              fi
              done
              

              Who's Scruffy Looking?

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

                @hansolo77 Do your testing:
                My ratings:

                • Shutdown between running gaming session - there is nothing that the script can do. If it works, fine if not then take it easy
                • Shutting down in screensavemode - should work
                • Shutting down in regular mode - should work (you've tested already)

                Have a nice weekend mate - I'm also out for a few hours.

                1 Reply Last reply Reply Quote 0
                • hansolo77H
                  hansolo77
                  last edited by

                  • Save metadata during game play:
                    1st Try, Nope. Loaded a game I never played and shutdown during playing. Upon reboot, Last Played had not been updated.
                    2nd Try, Nope. Added a game I never played to the Last Playedcollection, verified it was there, then started another. I turned off the system while that game was playing. Upon reboot, the collection had not saved.
                  • Shutting down during screensaver:
                    1st Try, Nope. I loaded a game, exited, confirmed it existed in the Last Played collection, then let the video screensaver load. When the video was playing, it locked up (video froze, and I was unable recover or access the system via SSH). Had to pull the plug and start over. The list had not saved at this point.
                    2nd Try, Yup. Same as before, loaded a game, then let the screensaver load. I let it play a few videos to make sure it wasn't locked up, then shut down. Upon rebooting, the Last Played collection had saved.
                  • Shutting down in regular mode:
                    1st Try, Yup. via System menu (random system). Loaded a game, verified it was in the Last Played, shut down, and it was still there upon reboot.
                    2nd Try, Yup. via Favorites menu. Loaded a game, verified Last Played updated, shut down, still there upon reboot.
                    3rd Try, Yup. via Last Played menu. Loaded a game, verified, shut down, rebooted, still there!

                  Take away - The new additions to the script are working. Thanks @cyperghost!! The only caveat is that you MUST be in ES when you shutdown if you want it to save your metadata. If you shutdown while playing a game, or if the system crashes, nothing is saved. Perhaps a future update to Retropie can get around this by having the gamelist.xml files be saved upon access (loading a game), rather than after returning from a gaming session.

                  Who's Scruffy Looking?

                  pjftP 1 Reply Last reply Reply Quote 0
                  • pjftP
                    pjft @hansolo77
                    last edited by

                    @hansolo77 The reason that that is not happening is because writing the gamelists is a time consuming process, with time increasing the more content it has. As such, the most effective way to do so is at exit (writing once only).

                    The metadata is only updated after the game exits and returns to ES, so maybe that's why it's not saving. Try loading a game, exiting from a game, and then loading a game and exiting from within the emulator. See if at least the first game is saved.

                    1 Reply Last reply Reply Quote 0
                    • hansolo77H
                      hansolo77
                      last edited by

                      Not sure what you mean. Do you mean load a game from RetroArch via the RetroPie menu?

                      Who's Scruffy Looking?

                      pjftP 1 Reply Last reply Reply Quote 0
                      • pjftP
                        pjft @hansolo77
                        last edited by

                        @hansolo77 no, just two games via EmulationStation. So: play game 1, back to es, play another game, shutdown. We'll see if game 1 is at least stored.

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

                          Good morning together, how are you?
                          img

                          @hansolo77 said in Mausberry Shutdown Script Doesn't Save Metadata:

                          Shutting down during screensaver:
                          1st Try, Nope. I loaded a game, exited, confirmed it existed in the Last Played collection, then let the video screensaver load. When the video was playing, it locked up (video froze, and I was unable recover or access the system via SSH). Had to pull the plug and start over. The list had not saved at this point.

                          Oh you use video screensavers -- never usem them so I can't try out. Why there was a lock up? Is that a thing sometimes happen at random or can you investigate? But this has nothing to do with ES status at all.

                          @pjft said in Mausberry Shutdown Script Doesn't Save Metadata:

                          @hansolo77 The reason that that is not happening is because writing the gamelists is a time consuming process, with time increasing the more content it has. As such, the most effective way to do so is at exit (writing once only).

                          That's clear, so it was my intention to provide for regular ES exit. If you search in internet for shutting down ES the killall method is prefered but you know what happens then.

                          The metadata is only updated after the game exits and returns to ES, so maybe that's why it's not saving. Try loading a game, exiting from a game, and then loading a game and exiting from within the emulator. See if at least the first game is saved.

                          As far as I understood you mean

                          • Load game X and press "START + SELECT" to return to ES
                          • Load game Y, press the GPIO shutdown

                          -> result: only game X is showing in Last Played list

                          Please correct me if I'm wrong :)
                          Mate? Do you want some coffee,too?

                          EDIT: Just should write shorter textes, you cleared out but I already understood :)

                          1 Reply Last reply Reply Quote 1
                          • cyperghostC
                            cyperghost
                            last edited by cyperghost

                            I rearranged the script a bit
                            It was written down just for testing purposes - so I made some small improvments that should be better for future maintainment. In v1 and v1.1 you have to change two lines in PID detection. Now I always use the detected PID. I removed echos and the useless else branch.

                            @hansolo77 version 1.2 is ready for you

                            #!/bin/bash
                            
                            #this is the GPIO pin connected to the lead on switch labeled OUT
                            GPIOpin1=23
                            
                            #this is the GPIO pin connected to the lead on switch labeled IN
                            GPIOpin2=24
                            
                            echo "$GPIOpin1" > /sys/class/gpio/export
                            echo "in" > /sys/class/gpio/gpio$GPIOpin1/direction
                            echo "$GPIOpin2" > /sys/class/gpio/export
                            echo "out" > /sys/class/gpio/gpio$GPIOpin2/direction
                            echo "1" > /sys/class/gpio/gpio$GPIOpin2/value
                            while [ 1 = 1 ]; do
                            power=$(cat /sys/class/gpio/gpio$GPIOpin1/value)
                            if [ $power = 0 ]; then
                            sleep 1
                            else
                            
                            # End Emulationstation if condition of running binary is true
                            # v1.0 07/21/17 by cyperghost - Inital run 
                            # v1.1 07/22/17 - Added chown command to set right user permission for creating es-shutdown
                            # v1.2 07/23/17 - Some small improvments, easier to maintain, removed echo, removed else branch 
                            # greetings @pjft for his famous favorits and @meleu for the RegEx sniplet 
                            espid=$( pgrep -f "/opt/retropie/supplementary/.*/emulationstation([^.]|$)" ) # detect PID of ES binary only
                            if [ "$espid" ]; then                                                         # Condition: PID is not equal 0 or empty then use ES shutdown
                               touch /tmp/es-shutdown && chown pi:pi /tmp/es-shutdown                     #v1.1 Change file permission of es-shutdown to user:group pi:pi
                               kill $espid                                                                #v1.2 use kill@detected PID - easier to maintain now!
                               exit
                            fi
                            # End Emulationstation if condition of running binary is true
                            
                            sudo poweroff
                            fi
                            done
                            
                            1 Reply Last reply Reply Quote 0
                            • hansolo77H
                              hansolo77
                              last edited by hansolo77

                              I will try version 1.2 in a little bit. I'm slowly getting familiar with reading scripts and understanding how they work. The various keys and commands I'm totally lost on so I'd need a lot more experience with them to be able to write my own. In the meanwhile, I noticed you changed from pkill to just kill. You sure that will work too? But like I said, will test.

                              As for testing the games... I've actually played a few games and seen the Last Played collection have them, only to have it not save that list. I think in all experience so far, the only time it's not saving is from a crash. I will try playing a game, exit to ES, verify the game is listed, then play something else and shut down while playing to see if the previous game remains.

                              Who's Scruffy Looking?

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

                                @hansolo77 My last posting for today! There goes my mind!
                                Yes I changed from pkill to kill because it's the standard application to terminate processes, but it's working only if you got the PID. The PID is an unique number for every process given bei the OS. I've extracted the PID already with the pgrepcommand so there is no need to use pkill and let it search for regualar expressions which hit ES's binary. KillPID is enough and leaves small footprint.

                                Some people would call it narrow-minded but I think when someone asks for help then do it at your best stage, this gives you the opportunity in development. The else branch was indeed waste of space - useless and I introduced it only for the quick falling distinctive between the if clause as I made first attempts with this.

                                If you are satisfied with this script you can mark it as solved.

                                1 Reply Last reply Reply Quote 0
                                • hansolo77H
                                  hansolo77
                                  last edited by

                                  v1.2 of the script is working just as well as the previous one was. Thanks!

                                  @pjft - I played a game, verified it recorded it in Last Played then started another game and shutdown with it still running. It did NOT save the Last Played at that point, and the 1st game was no longer on the list. I know where you were going with this, thinking it should have saved the gamelist.xml upon returning to ES, so I purposely loaded the 2nd game from a different system. It made no difference. Seems like it only saves the gamelists when completely exiting ES, and simply does a temporary save until then. So this problem will actually effect everybody, not just people using the Mausberry. Now that I know how it works, and can see what's happening, I'm happy with just using the new script. Will just have to wait until something new comes along, unless you have other testing you'd like me to try.

                                  Who's Scruffy Looking?

                                  pjftP 1 Reply Last reply Reply Quote 0
                                  • pjftP
                                    pjft @hansolo77
                                    last edited by

                                    @hansolo77 I assume, though, that what you're experiencing is that the gamelist file's date also isn't updated, though, could you confirm?

                                    It only saves the actual gamelists when completely exiting ES, that is correct, what I was hoping was that it was saving it, but just not recording the last game as it hadn't yet even updated it.

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

                                      @pjft @hansolo77
                                      There might be a way but please do it on your own. Because that are dirty tricks....

                                      And this should not the intention here in this forum nor will I write a script for this becasue it does not work 100% for all usecases. To make it work to 100% there will be much maintaining in and I think version 1.2 is the one that should be used ...

                                      Shotgun method:

                                      # End Emulationstation if condition of running binary is true (Shotgun-version - no support!)
                                      # v1.0 07/21/17 by cyperghost - Inital run 
                                      # v1.1 07/22/17 - Added chown command to set right user permission for creating es-shutdown
                                      # v1.2 07/23/17 - Some small improvments, easier to maintain, removed echo, removed else branch 
                                      # v1.3 07/24/17 - Shotgun method to terminate retroarch (not maintained, use v1.2 for support)
                                      # greetings @pjft for his famous favorits and @meleu for the RegEx sniplet 
                                      espid=$( pgrep -f "/opt/retropie/supplementary/.*/emulationstation([^.]|$)" ) # detect PID of ES binary only
                                      if [ "$espid" ]; then                                                         # Condition: PID is not equal 0 or empty then use ES shutdown
                                         pkill retroarch > /dev/null 2>&1                                           # v1.3 Shotgun method to kill running emulator (untested
                                         sleep 2                                                                    # v1.3 Sleeptimer to give ES chance to save XML filestate (untestested)
                                         touch /tmp/es-shutdown && chown pi:pi /tmp/es-shutdown                     # v1.1 Change file permission of es-shutdown to user:group pi:pi
                                         kill $espid                                                                # v1.2 use kill@detected PID - easier to maintain now!
                                         exit
                                      fi
                                      # End Emulationstation if condition of running binary is true (Shotgun-version - no support!)
                                      

                                      This will end any retroarch emulator (I think Ports, advMAME, fba... and other non librettro cores won't work). Therefore I will not maintain this. After retroarch is killed by default it waits 2 seconds for ES shutdown. Then it may happen that ES updates the XML files and you will see your alst played games. Maybe it won't work, maybe you must set sleeptime higher. I can not tell you if there are any other sideeffects.

                                      pjftP meleuM 2 Replies Last reply Reply Quote 1
                                      • pjftP
                                        pjft @cyperghost
                                        last edited by

                                        @cyperghost thanks.

                                        Just to confirm, I don't expect this to be in any way to be encouraged. I'm looking at this more as an angle on how to help @hansolo77 's use case.

                                        Best.

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

                                          @cyperghost @pjft
                                          Hey guys, I didn't read what you guys already tried, sorry. But I'm afraid it's not possible to get the results expected in the OP by killing ES. As far as I understood this part of ES code must be executed to update the gamelists: https://github.com/retropie/EmulationStation/blob/master/es-app/src/SystemData.cpp#L51

                                          I'm not used to ES code (maybe @pjft can help with this), but I think that that line won't be executed by killing ES while an emulator is running.

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

                                            @pjft I see it as encourgement that @hansolo77 got now his toolbox to write a script that is intented for his usecase. All commands are given in this sniplet. If this will work?? I don't know.

                                            From first version up to 1.2 - I was 100% sure that this works. And this works for every user here in the forum... Any other method is simply try and error.

                                            1 Reply Last reply Reply Quote 1
                                            • 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.