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

    How to restart ES from a script?

    Scheduled Pinned Locked Moved Help and Support
    scriptessystems.cfgrestart
    111 Posts 5 Posters 40.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.
    • TMNTturtlguyT
      TMNTturtlguy
      last edited by

      I have created a custom script to allow me to change between multiple es_systems.cfg using my controller from the retropie menu. You might ask why, you can read up on it as well as get the script from this post: New Idea/Help Needed - es_systems.cfg Selector

      The script is pretty basic, it removes the current es_systems.cfg from ~./emulationstation/ and then copies a different es_systems.cfg from a sub-folder to the main folder, thus upon restart you have a new list of systems. What i want to do is add the restart of ES to the script. I have achieved successful restarts in 2 ways, but both lead to crashes/errors.

      Both methods, create /tmp/es-restart i did this by touch es-restart

      Method 1 - restart as part of script.

      • the script has a menu with 4 options to change to 4 different files. I added this final line to each operation: echo "" > /tmp/es-restart && killall emulationstation
      • the script runs and the it successfully kills and restarts ES. Everything runs great until I re-enter into the script menu. Then everything freezes up. Sometimes the script force closes, other times I have to sudo reboot through putty.

      Method 2 - add restart ES to the script menu

      • instead of having the reboot as part of the changing of the .cfg files i added an option to run a restart from the script menu. thus you run the change script and then choose to reboot.
      • i used the same command echo "" > /tmp/es-restart && killall emulationstation
      • Again, this works successfully. I again get the same results, however this time after i force a reboot, i get error messages that /tmp/es-restart is not valid, or cannot be run, after a few restarts of ES if i try to restart the system, it only runs the /tmp/es-restart command. Thus i am always restarting ES, i can't shutdown or reboot until I sudo rm /temp/es-restart

      So for the time being, i have removed the restart function from the script. I run the change script, exit the script. Press start and from the start menu I restart ES and everything works great. If anyone has any ideas of how to add an automated restart of ES to the script it would be great. Thank you!

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

        I think you have to quit SDL first for a prober restart.
        pkill emulationstatio (without n!!) works like a charm and I can see the bash screen but if I restart, the screen keeps black!

        from https://github.com/RetroPie/EmulationStation/blob/master/es-app/src/main.cpp

        case SDL_JOYHATMOTION:
        				case SDL_JOYBUTTONDOWN:
        				case SDL_JOYBUTTONUP:
        				case SDL_KEYDOWN:
        				case SDL_KEYUP:
        				case SDL_JOYAXISMOTION:
        				case SDL_TEXTINPUT:
        				case SDL_TEXTEDITING:
        				case SDL_JOYDEVICEADDED:
        				case SDL_JOYDEVICEREMOVED:
        					InputManager::getInstance()->parseEvent(event, &window);
        					break;
        				case SDL_QUIT:
        					running = false;
        					break;
        			}
        		}
        
        1 Reply Last reply Reply Quote 0
        • cyperghostC
          cyperghost
          last edited by

          For feature development of ES it would nice to be to have acess to some API. A emulationstation --restart command would be nice :)

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

            Issue solved click here!

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

              @TMNTturtlguy I've recently realized that pkill accepts regex. Then here is my suggestion:

              touch /tmp/es-restart && pkill -f "/opt/retropie/supplementary.*emulationstation([^.]|$)"
              

              OK, maybe Regular Expressions is a not-very-human-readable thing, but it's really worth learning. ;-)

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

                Attentention @meleu that kills 2 of 3 processes in my configuration!
                That's a nice one liner ... what happens if the creataed es-restart will reside?

                TMNTturtlguyT meleuM 2 Replies Last reply Reply Quote 0
                • TMNTturtlguyT
                  TMNTturtlguy @cyperghost
                  last edited by

                  @cyperghost @meleu So first off, @cyperghost script appeard to work a few times in my testing. Then i tried @meleu one liner. This did not work. It gave me weird lines of code across the screen and then It exited me to a black screen and i had to go into putty and sudo reboot.

                  I then went back to @cyperghost script. Now the first time I run my change script it changes my es_systems and successfully restarts. However, the second time i go into the script, the script goes crazy and auto runs a few things and then the weird code that came up with @meleu script ran reappears and i exit to a black screen again.

                  At first look it appears that @meleu script broke something and now whenever i run a touch /tmp/es-restart command it gets weird. I go into /temp/ folder and es-restart does not exist. @meleu, can i reverse this script somehow so i can go back to test @cyperghost script which appeared to work?

                  meleuM cyperghostC 2 Replies Last reply Reply Quote 0
                  • meleuM
                    meleu @TMNTturtlguy
                    last edited by

                    @TMNTturtlguy I'm away from my pi now, will try to post something more robust later. ;-)

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

                      @TMNTturtlguy Yes I wrote in my last post. @meleu call kills 2 PIDs - mine just one - the latest!

                      I think we should create a coding section - this can run sometimes into trouble. The configuration of RetroPie can differ much from user to user. In this case we use brutal weapons to terminate ES. That's not good .... and makes user support heavier!

                      @meleu
                      Please check if es-restart can be alive!
                      On every reboot the files are force removed! So I strongly suggest they can run into this habbit. And I just kill one PID - I think that's the SDL windows. But I'm not sure...

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

                        @cyperghost said in How to restart ES from a script?:

                        Attentention @meleu that kills 2 of 3 processes in my configuration!

                        could you please post here the output of these commands (in this order)?:

                        pgrep -lf emulationstat
                        
                        touch /tmp/es-restart && pkill -f "/opt/retropie/supplementary.*emulationstation([^.]|$)"
                        
                        pgrep -lf emulationstat
                        
                        • Useful topics
                        • joystick-selection tool
                        • rpie-art tool
                        • achievements I made
                        TMNTturtlguyT 1 Reply Last reply Reply Quote 0
                        • TMNTturtlguyT
                          TMNTturtlguy @meleu
                          last edited by

                          @meleu Sounds good, i have to do real work as well. I will be away from my pi all weekend, so we might have to resume this on sunday or monday.

                          @cyperghost I am 99% sure that your method worked, my only concern was your statement about what happens when we update ES. I want this to work for all users as you just suggested in your latest post. This is why i tried @meleu method as it appeared to more straight forward. Problem is that now i can't run either anymore because for some reason @meleu code might have done something in the background?

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

                            @TMNTturtlguy No there is no difference in mine or meleus method. Both methods can run into trouble!

                            1 Reply Last reply Reply Quote 1
                            • TMNTturtlguyT
                              TMNTturtlguy @meleu
                              last edited by

                              @meleu 0_1497623338774_c353ccf3-9085-4768-aa64-e82e799d2677-image.png

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

                                @TMNTturtlguy hey bro, Linux shell is very rigorous with typing! :)

                                • use emulationstat not emulastionstat
                                • use /tmp/ not /temp
                                • Useful topics
                                • joystick-selection tool
                                • rpie-art tool
                                • achievements I made
                                TMNTturtlguyT 2 Replies Last reply Reply Quote 1
                                • TMNTturtlguyT
                                  TMNTturtlguy @meleu
                                  last edited by

                                  @meleu sorry, i am trying to work on work and do this at the same time, i am failing! give me a second

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

                                    @TMNTturtlguy Please don't get me wrong he needed the PID.
                                    Edit: Sorry for that kind of work! I know you just want to help :)

                                    @meleu

                                    868 emulationstatio
                                    874 emulationstatio
                                    877 emulationstatio
                                    

                                    That are three PIDs
                                    I kill only 877

                                    output of mine
                                    via echo 
                                    echo $(pgrep -l -n emulationstatio | awk '!/grep/ {printf "%s ",$1}')
                                    
                                    results:
                                    877
                                    
                                    I kill 877 with
                                    kill 877
                                    
                                    after checking again I see 3 PIDs
                                    868
                                    874
                                    1026
                                    

                                    your command

                                    I use e param for listing:
                                    pkill -f -e "/opt/retropie/supplementary.*emulationstation([^.]|$)"
                                    emulationstatio killed (pid 874)
                                    emulationstatio killed (pid 877)
                                    

                                    after

                                    with:
                                    pgrep -lf emulationstat
                                    nothing
                                    

                                    So the whole system is killed!

                                    1 Reply Last reply Reply Quote 0
                                    • TMNTturtlguyT
                                      TMNTturtlguy @meleu
                                      last edited by

                                      @meleu

                                      0_1497623837305_527688ec-9eba-48c2-886e-2450b7154a13-image.png

                                      Here is the touch line - this is the same error i get when i run from my script and what happens now when i use @cyperghost script a 2nd time. First, this is what i typed in when retropie was running properly:
                                      0_1497624115417_37c5b6a5-f5de-465b-8d0e-b1b656449c04-image.png

                                      And here is the outcome on the pi - no output in putty command line

                                      0_1497624026016_error.png

                                      running pgerp -lf emulationstat now gives no output at all.
                                      when i touch a button on my controller i exit to a black screen on the pi, have to sudo reboot.

                                      cyperghostC meleuM 2 Replies Last reply Reply Quote 1
                                      • cyperghostC
                                        cyperghost @TMNTturtlguy
                                        last edited by cyperghost

                                        @TMNTturtlguy Please delete /tmp/es-restart manually
                                        What has OMX-Player to do with Emulationstation?

                                        pleas @TMNTturtlguy
                                        Try this in shell output of ps -a

                                        in shell

                                        echo $(pgrep -l -n emulationstatio | awk '!/grep/ {printf "%s ",$1}')
                                        

                                        No worries you can't make mistakes with that. That are all output commands.

                                        TMNTturtlguyT 1 Reply Last reply Reply Quote 0
                                        • TMNTturtlguyT
                                          TMNTturtlguy @cyperghost
                                          last edited by

                                          @cyperghost that is the thing, i don't have a /tmp/es-restart to delete, it isn't there! I am pretty confused, when i did my attempts running touch es-restart I always got a /tmp/ file. any issues, just sudo rm and it was fixed. Now i don't see a /tmp/es-restart file, however it is retaining the error screen from @meleu script.

                                          As you might be able to tell, i am not a coder, so i am really stretching here creating this stuff. It is fun, but there is a lot I don't understand. Can you provide more info on what you want me to do? Not sure what you mean by :

                                          Try this in shell output of ps -a
                                          in shell
                                          echo $(pgrep -l -n emulationstatio | awk '!/grep/ {printf "%s ",$1}')

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

                                            @TMNTturtlguy I'll sort it this evening, but when that happens with your terminal try to (maybe blindly) type reset and press enter.

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