• Recent
  • Tags
  • Popular
  • Home
  • Docs
  • Register
  • Login
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 37.1k 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.
  • M
    Mafu
    last edited by Mafu 20 Dec 2017, 01:11

    That was an excellent idea carver01 (I facepalmed a little when I saw it for not thinking of it myself). It works partially but only on save states, not ingame save data (games that have their own dedicated save feature).

    Whats frustrating is when using the OP's solution and just shutting the system down with the power button it will

    1. Exit the game.
    2. pause at the game selection screen (I assume this is where the "sleep 5" comes into play).
    3. And then shut down.

    What I need is a way to get it to stop at step 2 and still save the game's data(save files, save states, etc) when pressing the reset button. As it is now it goes back to the game selection screen but does not save any data.

    S C 2 Replies Last reply 20 Dec 2017, 06:48 Reply Quote 0
    • Z
      zobilla
      last edited by 20 Dec 2017, 05:50

      Hey guys

      Anyone having problems with systemd refusing to load with no ExecStart line in the service?

      --
      pi@retropie:~ $ dmesg | grep killes
      [ 2.660196] systemd[1]: killes.service lacks ExecStart setting. Refusing.
      [ 2.679020] systemd[1]: Cannot add dependency job for unit killes.service, ignoring: Unit killes.service failed to load: Invalid argument. See system logs and 'systemctl status killes.service' for details.

      I pulled the logs from systemctl status killes.service but it just says invalid args.

      M 1 Reply Last reply 8 Jan 2018, 16:56 Reply Quote 0
      • S
        Sano @Mafu
        last edited by Sano 20 Dec 2017, 06:48

        @mafu Could you precise what you mean by "save the game data" ?
        Is it that .srm files are not correctly written to the sd when retroarch is exited with the script ?

        It seems to me very difficult to script game saves beyond the savestates as explained above, because each game is quite specific about it's own saves (different menu, number of save slots, use of savepoints...)

        1 Reply Last reply Reply Quote 0
        • C
          caver01 @Mafu
          last edited by 20 Dec 2017, 07:19

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

          That was an excellent idea carver01

          Glad I can help, marfu.

          If your script is still shutting down, why not remove the line from the script that does the shutdown? Seems easy enough.

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

          1 Reply Last reply Reply Quote 0
          • T
            TazgodX
            last edited by 6 Jan 2018, 17:17

            I am having the same issue as Zobilla

            dmesg | grep killes
            [ 1.936038] systemd[1]: killes.service lacks ExecStart setting. Refusing.
            [ 1.962910] systemd[1]: Cannot add dependency job for unit killes.service, ignoring: Unit killes.service failed to load: Invalid argument. See system logs and 'systemctl status killes.service' for details.

            systemctl status killes.service
            â killes.service - Kill EmulationStation
            Loaded: error (Reason: Invalid argument)
            Active: inactive (dead)

            won't run for me.

            1 Reply Last reply Reply Quote 0
            • M
              meleu @zobilla
              last edited by 8 Jan 2018, 16:56

              @zobilla @TazgodX could you guys paste here the output of systemd --version?

              • Useful topics
              • joystick-selection tool
              • rpie-art tool
              • achievements I made
              1 Reply Last reply Reply Quote 0
              • T
                TazgodX
                last edited by 9 Jan 2018, 00:13

                systemd --version
                systemd 215
                +PAM +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ -SECCOMP -APPARMOR

                1 Reply Last reply Reply Quote 0
                • C
                  cyperghost
                  last edited by cyperghost 1 Dec 2018, 22:32 9 Jan 2018, 18:43

                  @meleu Can you link this posting in your first posting please?
                  @caver01 This will solve the software shutdown issue with the mausberry, without modifications on meleu's script and editing /opt/retropie/supplementary/emulationstation/emulationstation.sh and reboots can also be performed now ;) This is a generic solution and works in every state!

                  How to perform a software shutdown with the Mausberry and the diode/transistor hack?

                  NOTE: This does only work on momentary switches!

                  1. Prerequisites
                  You need to solder a diode (1N400x type 1N4001 or 1N4002) or a transistor (NPN-Type, 2N3904, BC547 or BC337) to the Mausberry on/off switch.
                  For the diode: Connect it between a GPIO and the mausberry button ground.
                  The transistors needs to soldered between ground and positive to the switch and the base line is connected to the GPIO (maybe you need a resistor to control current flow)

                  Therefore I strongly recommand the DIODE hack!

                  Don't be afraid the Raspberry is in both ways protected against current backdraws! Use the diode or the right direction as shown in the box above....

                    GPIO                               MAUSBERRY
                  from Pie          DIODE            switch ground
                     O---------------->|----------------O
                                    1N4002
                  

                  More to read here

                  2. Software part

                  1. Create gpio-shutoff with sudo nano /lib/systemd/system-shutdown/gpio-shutoff
                  2. Enter code from box below
                  3. Make the script executable with sudo chmod +x /lib/systemd/system-shutdown/gpio-shutoff

                  GPIO16 (or PIN 36 ) is just an example here and is my real setup

                  #!/bin/sh
                  # Perform Software Shutdown with Mausberry switch
                  # cyperghost for retropie.org.uk
                  
                  # This is the GPIO pinconnected to the diode or transistor
                  GPIOpinDIODE=16
                  
                  if [ "$1" = "poweroff" ]; then
                  
                      echo $GPIOpinDIODE > /sys/class/gpio/export
                      echo out > /sys/class/gpio/gpio$GPIOpinDIODE/direction
                      echo 1 > /sys/class/gpio/gpio$GPIOpinDIODE/value
                      sleep 0.5
                      echo 0 > /sys/class/gpio/gpio$GPIOpinDIODE/value
                      sleep 0.5
                  
                  fi
                  

                  3. Why are you doing this?
                  The Mausberry gots a little design issue. If you performing a software shutdown (maybe via ES > Shutdown system or via SSH sudo poweroff) the PI will shut down but the Mausberry will stay active (LED is on). Furthermore it won't respond to a power button press anymore - it's stuck! So you have to switch it off completly by removing your wall plug or by resetting the Mausberry.

                  The diode or transistor just simulates a button press and the Mausberry will properly shutdown ;)

                  C M 2 Replies Last reply 9 Jan 2018, 19:30 Reply Quote 1
                  • C
                    caver01 @cyperghost
                    last edited by 9 Jan 2018, 19:30

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

                    C 1 Reply Last reply 9 Jan 2018, 20:04 Reply Quote 0
                    • C
                      cyperghost @caver01
                      last edited by cyperghost 1 Sept 2018, 21:24 9 Jan 2018, 20:04

                      @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

                      C 1 Reply Last reply 9 Jan 2018, 22:15 Reply Quote 0
                      • C
                        caver01 @cyperghost
                        last edited by 9 Jan 2018, 22:15

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

                        C 1 Reply Last reply 9 Jan 2018, 22:20 Reply Quote 0
                        • C
                          cyperghost @caver01
                          last edited by 9 Jan 2018, 22:20

                          @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
                          • M
                            meleu @cyperghost
                            last edited by 10 Jan 2018, 21:58

                            @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 2 Jan 2018, 21:43 31 Jan 2018, 21:45

                              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?

                              M 1 Reply Last reply 18 Feb 2018, 12:22 Reply Quote 0
                              • G
                                G30FF
                                last edited by G30FF 18 Feb 2018, 07:58

                                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
                                • M
                                  meleu @Semper 5
                                  last edited by 18 Feb 2018, 12:22

                                  @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
                                  C 1 Reply Last reply 21 Feb 2018, 19:58 Reply Quote 0
                                  • C
                                    cyperghost @meleu
                                    last edited by 21 Feb 2018, 19:58

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

                                    M 1 Reply Last reply 21 Feb 2018, 20:25 Reply Quote 0
                                    • M
                                      meleu @cyperghost
                                      last edited by 21 Feb 2018, 20:25

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

                                      • Useful topics
                                      • joystick-selection tool
                                      • rpie-art tool
                                      • achievements I made
                                      C 1 Reply Last reply 21 Feb 2018, 20:58 Reply Quote 0
                                      • C
                                        cyperghost @meleu
                                        last edited by cyperghost 21 Feb 2018, 20:58

                                        @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 22 Feb 2018, 14:36 Reply Quote 0
                                        • S
                                          Semper 5 @cyperghost
                                          last edited by 22 Feb 2018, 14:36

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

                                            This community forum collects and processes your personal information.
                                            consent.not_received