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

    Emulationstation Shutdown Script

    Scheduled Pinned Locked Moved Help and Support
    shutdown
    19 Posts 7 Posters 17.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.
    • GaM3r2XtremeG
      GaM3r2Xtreme
      last edited by

      Would anyone happen to know where I can find the script that is called when shutdown is selected within emulationstation? I figured it might be somewhere in the emulationstation install directory, but I'm not quite sure where that might be on the Raspberry Pi. Any help would be greatly appreciated.

      herb_fargusH P 2 Replies Last reply Reply Quote 0
      • herb_fargusH
        herb_fargus administrators @GaM3r2Xtreme
        last edited by herb_fargus

        @GaM3r2Xtreme i think it's called natively through the emulationstation binary (I may be wrong). You can use sudo killall emulationstation in a bash script to kill it though.

        If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

        Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

        1 Reply Last reply Reply Quote 0
        • P
          PaulCheffus @GaM3r2Xtreme
          last edited by

          @GaM3r2Xtreme

          Hi

          The script is called EmulationStation.sh on mine V3.8.1 as I modified it to allow me to shut the Pi down from the menu using the ATXRasPi PCB. Off hand though I can't remember which directory its in and I'm not near my Picade at the moment.

          Cheers

          Paul

          1 Reply Last reply Reply Quote 1
          • GaM3r2XtremeG
            GaM3r2Xtreme
            last edited by GaM3r2Xtreme

            Thanks for the quick replay @herb_fargus and @PaulCheffus. I'm actually talking about trying to turn the system off from the Quit menu of emulationstation.

            One the Quit menu are the following selecitons:
            Restart Emulationstation
            Restart System
            Shutdown System
            Quit Emulationstation

            Quit Emulationstation works fine to close the program, but the other three do not. They all close out emulationstation, but restart will not work and the over all system will not shutdown or restart. I'm curious to see what script is being called when each is picked so I might be able to edit it and correct the issue.

            Hopefully its not in built directly in the program binary, otherwise it might be harder to edit.

            Also, the emulationstation.sh seems to be located in /usr/bin/. I believe your talking about the command executed within the bash window. If so, I currently have this as the script:

            #!/bin/bash
            
            if [[ $(id -u) -eq 0 ]]; then
                echo "emulationstation should not be run as root. If you used 'sudo emulationstation' please run without sudo."
                exit 1
            fi
            
            if [[ "$(uname --machine)" != *86* ]]; then
                if [[ -n "$(pidof X)" ]]; then
                    echo "X is running. Please shut down X in order to mitigate problems with losing keyboard input. For example, logout from LXDE."
                    exit 1
                fi
            fi
            
            clear
            tput civis
            "/opt/retropie/supplementary/emulationstation/emulationstation.sh" "$@"
            reset
            

            The script in /opt/retropie/supplementary/emulationstation/emulationstation.sh looks like the following:

            #!/bin/sh
            
            esdir="$(dirname $0)"
            while true; do
                rm -f /tmp/es-restart /tmp/es-sysrestart /tmp/es-shutdown
                "$esdir/emulationstation" "$@"
                [ -f /tmp/es-restart ] && continue
                if [ -f /tmp/es-sysrestart ]; then
                    rm -f /tmp/es-sysrestart
                    sudo reboot
                    break
                fi
                if [ -f /tmp/es-shutdown ]; then
                    rm -f /tmp/es-shutdown
                    sudo poweroff
                    break
                fi
                break
            done
            

            I wonder if the shutdown has something to do with the second script. Any ideas?

            meleuM P 2 Replies Last reply Reply Quote 0
            • meleuM
              meleu @GaM3r2Xtreme
              last edited by

              @GaM3r2Xtreme The script makes me believe that ES creates these files at some poin of its lifetime: /tmp/es-restart, /tmp/es-sysrestart and /tmp/es-shutdown.

              Translating the script to english:
              If es-restart exists, it restarts ES only. If doesn't exists...
              ...If es-sysrestart exists, it restart the system. If doesn't exists...
              ...If es-shutdown exists, it turn off the system, If doesn't exists...
              finish the script.

              So, I think that your emulationstation is failing in creating those files at /tmp. Check if those files exist while ES is running.

              • Useful topics
              • joystick-selection tool
              • rpie-art tool
              • achievements I made
              1 Reply Last reply Reply Quote 0
              • P
                PaulCheffus @GaM3r2Xtreme
                last edited by PaulCheffus

                @GaM3r2Xtreme
                Hi

                The second script is the one I was meaning. The shutdown and restart commands from the quit menu are processed by that script. If you want to test it remove the sudo reboot from the above script then select restart from the menu. Nothing should happen.

                Cheers

                Paul

                1 Reply Last reply Reply Quote 0
                • GaM3r2XtremeG
                  GaM3r2Xtreme
                  last edited by GaM3r2Xtreme

                  Hey @meleu and @PaulCheffus,

                  So I was able to figure out when /tmp/es-restart, /tmp/es-sysrestart, and /tmp/es-shutdown are created.

                  Right after bootup, these files are nonexistent. I ran an SSH connection and started up emulationstation, after which checking the /tmp/ directory and concluding that the files still have not been created. Instead, the moment I choose a quit option from the Quit menu, a corresponding temp file is created.

                  Each selection creates the following:
                  "Restart Emulationstation" creates /tmp/es-restart
                  "Restart System" creates /tmp/es-sysrestart
                  "Shutdown System" creates /tmp/es-shutdown
                  "Quit Emulationstation" creates nothing

                  I'm curious to see if those if statements are correctly written within the above scripts, as it appears that the /usr/bin/emulationstation.sh will call /opt/retropie/supplementary/emulationstation/emulationstation.sh near the end right after the tput civis line. If they are incorrect, then the default will always be to break out of the while loop and end everything, ignoring anything selected in the Quit menu.

                  Although, the second script may not be executing at all. I've noticed that all the temp files stay around after every restart of emulationstation. rm -f /tmp/es-restart /tmp/es-sysrestart /tmp/es-shutdown is called right before the emulationstation binary is called, which should delete anything that exists in the /tmp/ folder before emulationstation starts. Maybe there is some sort of write protection going on that prevents this command from executing. This is all so confusing...

                  May I ask, does anyone else have this shutdown/restart issue as well? Do these Quit commands work ok for others? If so, are you using one of the pre-made RetroPie images or was retropie build via the github page?

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

                    @GaM3r2Xtreme
                    May I ask if you are using one of the pre-made RetroPie images or build it via the github page?

                    Try to describe your environment in details.

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

                      I should have added this to the end of my last post.

                      I'm currently using the DietPi v136 OS, which is a bare-bone Raspbian distribution. I'm using this in order to limit background processes and maximize processing towards emulating. Plus, I can fit all that I need on a 2GB card.

                      Right after flashing the OS onto a card, I followed the manual installation from the wiki in order to install Retropie from the github repository. I've gone through the setup and installed all the core packages, along with a limited amount from the main packages. Everything works great, and games run fine. It's just the shutdown causing issues I'd like to understand.

                      There might be some write protections going on within the OS. If that's the case, I'll contact the forum group over there and see if they might have some insight.

                      But first, I'll see about modifying the scripts and throw a few echos around to see what might be happening. I will also try one of the pre-made images and also building from github onto a Raspbian image.

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

                        @GaM3r2Xtreme my first shoot would be in /etc/sudoers.

                        Like detailed here: https://github.com/retropie/retropie-setup/wiki/RetroPie-Ubuntu-16.04-LTS-x86-Flavor#section-31-emulationstation-hangs-if-shutdownrestart-was-selected

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

                          Oh, I just found something @meleu. Apparently when I type just emulationstation within the terminal and hit enter, /usr/bin/emulationstation is NOT called, but something else is.

                          Now if I force the terminal to execute /usr/bin/emulationstaiton and then select one of the Quit options, it works. I successfully rebooted the system.

                          Let me check and see what is in the /etc/sudoers. I should note that DietPi normally runs under the root user (there is no pi user setup by default).

                          1 Reply Last reply Reply Quote 0
                          • BuZzB
                            BuZz administrators
                            last edited by BuZz

                            Type which emulationstation. Note you won't benefit from any better performance running dietpi. Just more likely to have compatibility issues.

                            Please check the link in my signature when asking for help as it saves time if we have all the information about your setup.

                            To help us help you - please make sure you read the sticky topics before posting - https://retropie.org.uk/forum/topic/3/read-this-first

                            1 Reply Last reply Reply Quote 0
                            • GaM3r2XtremeG
                              GaM3r2Xtreme
                              last edited by

                              Adding the extra line of code within /etc/sudoers didn't seem to do the trick, but thanks for the suggestion to check it out.

                              I did use which emulationstation which returned /usr/bin/emulationstation. The funny thing is that /opt/retropie/supplementary/emulationstation/emulationstation is executed directly instead via the emulationstation command, but not the /user/bin/emulationstation. This is all based on what I see in the resource monitor htop.

                              Would it be possible to change what file is executed with the emulationstation command? If so, I would think this would be the solution I'm after.

                              On a side note, I'll make sure to post system information if I have any other issues and open another thread.

                              1 Reply Last reply Reply Quote 0
                              • BuZzB
                                BuZz administrators
                                last edited by BuZz

                                Yes, if you find out why that is being launched directly - the which command shows which is being launched if you just type in emulationstation unless there is a system alias in place - type alias.

                                also check:
                                /usr/bin/emulationstation should just be a script which launches /opt/retropie/supplementary/emulationstation/emulationstation.sh which in turn launches /opt/retropie/supplementary/emulationstation/emulationstation

                                If there is an alias - it must be added by dietpi and you should report the issue there - dietpi is not officially supported by retropie.

                                To help us help you - please make sure you read the sticky topics before posting - https://retropie.org.uk/forum/topic/3/read-this-first

                                1 Reply Last reply Reply Quote 0
                                • BuZzB
                                  BuZz administrators
                                  last edited by

                                  I just saw the thread you have over at the dietpi forums. I see from their code, they are launching is incorrectly at startup. They also do set an alias

                                  https://github.com/Fourdee/DietPi/blob/dad12d7ef381a5b346975b1dac1f5c4771f77b2b/PREP_SYSTEM_FOR_DIETPI.sh#L388

                                  You will need to ask them to change this. I can't really help if they are not using our launch scripts.

                                  To help us help you - please make sure you read the sticky topics before posting - https://retropie.org.uk/forum/topic/3/read-this-first

                                  1 Reply Last reply Reply Quote 0
                                  • GaM3r2XtremeG
                                    GaM3r2Xtreme
                                    last edited by

                                    I think you found the issue @BuZz. And yeah, I started a thread with dietpi awhile back and revived it to point out what was found here. I suggested a solution to their auto start script, but never noticed the system alias you found. Both might need a little tweaking, but that's up to those guys if they want to do this.

                                    As far as I'm concerned, a solution was found for the issue I was having. Thanks again for all the help everyone.

                                    1 Reply Last reply Reply Quote 0
                                    • B
                                      backstander
                                      last edited by

                                      @PaulCheffus
                                      I am curious about your custom EmulationStation.sh script to shutdown using your ATXRasPi PCB. I have some old power/reset switches that came out of some old PCs and I currently have 1 switch to turn on & off my Pi (gracefully) and I have a 2nd switch I want to use to restart ES (and maybe a 3rd one to exit the currently running emulator). Could you post your script because I'm not sure exactly how I was going to do the ES restart code.

                                      P 1 Reply Last reply Reply Quote 0
                                      • P
                                        PaulCheffus @backstander
                                        last edited by PaulCheffus

                                        @backstander
                                        Hi

                                        The script doesn't use extra buttons as it is for shutting down from the emulationstation menu. It requires a bc337 transistor and a 1k resistor with the emitter and collector of the transistor connected across the existing switch. The 1k resistor goes between one of the GPIO pins and the base of the transistor.

                                        When I have the laptop out next I'll post the scripts.

                                        EmulationStation.sh
                                        0_1478523061478_es_sh.jpg

                                        ES_Reboot.sh
                                        0_1478523218990_es_reboot_sh.jpg

                                        ES_Shutdown.sh
                                        0_1478523251790_es_shutdown_sh.jpg

                                        Cheers

                                        Paul

                                        1 Reply Last reply Reply Quote 1
                                        • M
                                          makaveeti
                                          last edited by

                                          Has anyone figured out how to get the shutdown system option working from windows version of ES?

                                          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.