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 97.0k 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.
    • hansolo77H
      hansolo77
      last edited by

      Now testing v1.5b (with the loop fix):

      • Shutdown from ES normally (play game, return to ES, verify "Last Played" updated, then button)
        PASS - Last Played saved prior to successful shutdown
      • Shutdown from ES during video screensaver (play game, return to ES, verify "Last Played" updated, wait for screensaver to start, then button)
        PASS - Last Played saved prior to successful shutdown (although there was a delay after pushing the button before the video stopped...)
      • Shutdown system while playing a game (RetroArch) (play game, return to ES, verify "Last Played" updated, play a different game, then button while still in game)
        PASS - Last Played saved prior to successful shutdown (the previous game as well as the one I was playing when I shut down both saved to the list. Sleep delay still needs tweaked, takes a long time to start shutting down ES after exiting a game)
      • Shutdown system while playing a game (non-RetroArch) (play game, return to ES, verify "Last Played" updated, play a different game, then button while still in game)
        PASS - Last Played saved prior to successful shutdown (previous game and active game both saved metadata)

      COMPLETE SUCCESS!

      I'm very happy you guys! You came forth and solved my problem! I'm going to try tweaking the sleep command a little, but for the most part.. yay!! I don't have the ScummVM system installed on my Pi, so I can't test any further if you guys try to come up with a solution for that. Thank you so much!!! Should I mark as resolved or are you guys still going to try tackling this further?

      Who's Scruffy Looking?

      lostlessL 1 Reply Last reply Reply Quote 1
      • lostlessL
        lostless @hansolo77
        last edited by lostless

        @hansolo77 If its solved for you, then by all means. @meleu is just trying to make a script that is more efficient on the cpu

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

          I think the delay I found with the video screensaver comes from it waiting to start shutting down until AFTER the current playing video finishes. I just went to shutdown the system to make a backup of the working SD card, and a new video had just started, so I watched and waited until the current video stopped, then it shut down. Not a big deal, just something I noticed.

          Who's Scruffy Looking?

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

            @hansolo77 when you are on IRC and see me (meleu) there, feel free to contact me and we will make more tests to "fix" that infinite loop checking the button pressing every single second.

            Feel free to mark it as solved if it works for you. I am (was?) just trying to find a strong solution, for every scenario.

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

              By all means. If a prettier solution can be had, it's for the better of everybody. Maybe we can even send a message over to the folks at Mausberry: "Hey, you guys should update your 'setup' webpage to include a blurb about our new script working if your goal is to use the circuit in a RetroPie setup". Of course, you're not their yet if you still wanna tinker.

              And yeah, so long as my seedbox is online, I'm always in that chat forum (along with a dozen or so others). I do a lot of idlerpg for some of my private torrent trackers, and like to keep chatrooms open that I go to for help. Most of the time it's @Rookervik chatting up in there, but every now and then I see names I recognize like @cyperghost , @herb_fargus , @lilbud :)

              Who's Scruffy Looking?

              lilbudL 1 Reply Last reply Reply Quote 0
              • lilbudL
                lilbud @hansolo77
                last edited by

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

                Most of the time it's @Rookervik chatting up in there, but every now and then I see names I recognize like @cyperghost , @herb_fargus , @lilbud :)

                It's only ever a few people chatting even though 70+ people could be in the room. It's usually quiet the rest of the time

                Creator of the Radiocade: https://retropie.org.uk/forum/topic/6077/radiocade

                Backlog: http://backloggery.com/lilbud

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

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

                  Feel free to mark it as solved if it works for you. I am (was?) just trying to find a strong solution, for every scenario.

                  I think so, but I'm pretty sure that your solution (ScummVM fix) is already in usage by @hansolo77 - I asked you (yesterday is wrong!) for a few hours of using the sniplet. I'm just reading that more and more people rip out parts of these scripts for different other usecases.

                  @meleu About giving the user the best experience: Add the latest version(s) posted in this topic to the "Usefull topic index". I think most (mausberry) people find it usefull. There are still other selling products (Powerblock PetRetBlock or some selfmade things). Maybe the Pi4 (maybe 2018 but rather 2019) will contain a power switch.

                  Out of this is code pieces I created a PID detector for ES and all emulators Garbage: PID Detector. It gives report of an running emulator and detects running ES and output both PID numbers. Out of this it is pretty easy to perform a simple escpae keypress just kill $espid. So we have full control over ES ... we can restart ES, quit ES, system reboot and system shutdown now :)

                  @hansolo77 might you recheck if your script contains this line? If yes then it's a working version equal to @meleus upcoming, without the optimzing in sleep timer.
                  emupid="$(sed -n 4p /dev/shm/runcommand.info | tr -d '\\"' | tr '^$[]*.()|+?{}' '.')"
                  Otherwise there might be issues with some emulators like ScummVM.

                  About the telling mausberry to optimzie their bash script. Well no.... RetroPie and ES is just a special usecase. The mausberry script is working 100% in all usecases without installing an extra tool. So to follow unix philosopie - keep it simple and working and one tool for one usecase.
                  As me and @meleu (afaik) do not even possess a mausberry switch it's a bit difficult to test such scripts. We could run them and give an echo 1 > /sys... but then we still do not have insights about user permission... and I think we are the latest man on earth who say. "Do what I say...", we just make suggestions.

                  At last I have to say thank you to meleu for his constant help in caveeats and making suggestions. This is really a nice guy.

                  Download of latest version 1.56 is here

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

                    @cyperghost - Yes I am using the version with that line:

                    emupid="$(sed -n 4p /dev/shm/runcommand.info | tr -d '\\"' | tr '^$[]*.()|+?{}' '.')"
                    

                    Who's Scruffy Looking?

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

                      @hansolo77 Yes - I made finally some cleanups to code you may look into v1.56 @meleu discovered there also a small pitfall and as I already made some changes I established a precheck if file exists (runcommand.info) to just trap errormessage while sed-command is reading the file :)
                      So it's better to recheck again - don't fear - the code is working.
                      I think it's also in the mind of @meleu and definatly my last work on this piece. I learned a lot from this. The error accourd as I used the PID detector and no emulator was started before. So sed-command gives out error ... This is just cosmetical but now it's perfect.

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

                        I see you added:

                        if [[ -e "/dev/shm/runcommand.info" ]]; then
                        

                        I'm on my way out the door right now, but I will try to test this latest version tonight!

                        Who's Scruffy Looking?

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

                          @hansolo77 Yes and a bit more but this has been impossible without the help from @meleu

                          if [[ -e "/dev/shm/runcommand.info" ]]; then
                              emupid="$(sed -n 4p /dev/shm/runcommand.info | tr -d '\\"' | tr '^$[]*.()|+?{}' '.')"
                              emupid="$(pgrep -f "$emupid")" 
                          fi
                          
                          1 Reply Last reply Reply Quote 0
                          • hansolo77H
                            hansolo77
                            last edited by hansolo77

                            Results from testing 1.56 (with @meleu fix)

                            • Shutdown from inside ES (normal)
                              PASS
                            • Shutdown from inside ES (during screensaver)
                              PASS
                            • Shutdown from inside a game (RetroArch)
                              PASS
                            • Shutdown from inside a game (non-RetroArch (SuperMarioWar))
                              PASS (although I still think sleep is too long)

                            Cha-Ching! At least for me. I still don't have ScummVM installed to verify @meleu's fix, but at least I can confirm the additions don't break anything else. :)

                            EDIT
                            Did some further experimenting on my own.. Dropped sleep down to 7, then 5, then 4, then 3, then 2, then 1. All testing verified proper shutdown and metadata saving. Doesn't take NEAR as long to start shutting down after closing out of an emulator now! With 2 seconds, ES barely has enough time to load back up before shutdown. The video snap runs about 2-3 frames before the menu starts rendering, then the system powers off. With 1 second, all you get is a brief little glimpse of the menu starting to load then power off (before the video starts). I then tried to #comment out the entire && sleep 1 bit. The results are that I get the RunCommand screen and the word "Terminated" at the bottom. ES never loads back up at all, and the metadata does NOT save. So we definitely need that sleep 1 at least. I also tested with sleep .5 but that didn't work either, same results as being #commented out. So now I'm using this:

                            #!/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.56)
                            # 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.5 07/27/17 - Great step to exit ES even if emulators is running by runcommand.sh are started
                            # v1.55 07/29/17 - all kudos go to @meleu for his alltime genious RegEx hack!
                            # v1.56 07/30/17 - All emulators will be detected. This is a full functional code equal to developing v1.7
                            # v1.7 is in work flow - This will be cleaner and better coded and is better to maintain
                            # I just checked with SSH command - it saved my metadata! Maybe you need to extend sleeptimer!
                            # greetings @pjft for his famous favorits and @meleu for his RegEx sniplets and his constant help! 
                            
                            espid="$(pgrep -f "/opt/retropie/supplementary/.*/emulationstation([^.]|$)")"
                            if [[ -e "/dev/shm/runcommand.info" ]]; then
                                emupid="$(sed -n 4p /dev/shm/runcommand.info | tr -d '\\"' | tr '^$[]*.()|+?{}' '.')"
                                emupid="$(pgrep -f "$emupid")" 
                            fi
                            
                            if [ "$emupid" ]; then
                                kill $emupid && sleep 1
                            fi    
                            
                            if [ "$espid" ]; then
                               touch /tmp/es-shutdown && chown pi:pi /tmp/es-shutdown
                               kill $espid
                               exit
                            fi
                            # End Emulationstation if condition of running binary is true (v1.56)
                            
                            sudo poweroff
                            fi
                            done
                            

                            I did, however, notice that if I press the power button while the game has a few moments to actually load up (like in the in-game demo, rather than opening credits) it didn't load ES on 1 second.. it just did the RunCommand with "Terminated". So maybe the 1 second only works "right away"? Then again.. I just tested again with the same game while waiting longer and it worked, then it worked again with a different game while waiting. So maybe that was just a onetime glitch. Still, 1 time is enough to lose all your metadata... Has this come up before? I can't imagine it having been, since this is the first exposure to this script. But does it sound like something that could happen.. pressing the button after a longer period has a different out come than pressing it right after starting a game? In any case, I just tested with a 3rd game, and this time a non-RetroArch one. It still works great at 1 second.

                            I dunno, you think I should just use 2 and play it safe?

                            Who's Scruffy Looking?

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

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

                              I dunno, you think I should just use 2 and play it safe?

                              IMHO yes.

                              • Useful topics
                              • joystick-selection tool
                              • rpie-art tool
                              • achievements I made
                              1 Reply Last reply Reply Quote 0
                              • B
                                barrymossel
                                last edited by

                                Really nice work guys. Will try later this as well!

                                Is v1.7 still under development? Willing to test of course!

                                lostlessL meleuM 2 Replies Last reply Reply Quote 0
                                • lostlessL
                                  lostless @barrymossel
                                  last edited by

                                  @barrymossel I'm using 1.7 and it working fine.

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

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

                                    @barrymossel I'm using 1.7 and it working fine.

                                    Can you post a link to the script you're naming as 1.7?

                                    Or maybe paste it in ghostbin...

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

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

                                      Is v1.7 still under development?

                                      This "development" is more about testing than writing code. I would love to have this device to make more tests. I tried some experimentations with @lostless via IRC but it was late night... If you find me at IRC some day feel free to contact me.

                                      If I find some time I'll write what tests I would like to do...

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

                                        @meleu I assumed i was using 1.7. It's what ever the last one @cyperghost posted.

                                        1 Reply Last reply Reply Quote 0
                                        • B
                                          barrymossel @meleu
                                          last edited by

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

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

                                          Is v1.7 still under development?

                                          This "development" is more about testing than writing code. I would love to have this device to make more tests. I tried some experimentations with @lostless via IRC but it was late night... If you find me at IRC some day feel free to contact me.

                                          If I find some time I'll write what tests I would like to do...

                                          Ah, I thought you didn't figure out how to work around the loop yet. I will check in IRC later!

                                          lostlessL 1 Reply Last reply Reply Quote 0
                                          • lostlessL
                                            lostless @barrymossel
                                            last edited by

                                            @barrymossel we didn't. For some reason the inotify was not reading the change on the gpio. So something is up. What's weird though, is when we manually told the pi there was a change to the gpio, the script worked.

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