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.2k 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.
    • meleuM
      meleu
      last edited by

      @cyperghost @TMNTturtlguy
      Some background I would like to share with you guys:

      • when you type emulationstation in the shell, it executes /usr/bin/emulationstation

      • the /usr/bin/emulationstation is a shell script that calls /opt/retropie/supplementary/emulationstation/emulationstation.sh.

      • the /opt/retropie/supplementary/emulationstation/emulationstation.sh calls the /opt/retropie/supplementary/emulationstation/emulationstation and this is the real emulationstation binary.

      • the /opt/retropie/supplementary/emulationstation/emulationstation.sh has a logic to restart ES, restart system and shutdown system based on the existence of some specific files in /tmp. The code of this script can be seen here.

      • in my failed attempt to restart ES from commandline, I was trying create the /tmp/es-restart and kill only the ES binary. According to the emulationstation.sh it's enough to restart ES. But as we saw, my approach is killing the emulationstation.sh too, and that is what is "crashing".

      I'll try something more concise this evening, but if @cyperghost has some free time now and would like to investigate more, my suggestion is to find a way to kill only that very specific binary: /opt/retropie/supplementary/emulationstation/emulationstation.

      I used those metacharacters on my pkill regex to try to match some edge cases (like running a custom branch ES or launching ES with some parameter).

      P.S.: now that I see @BuZz is aboard, I'm sure that the elegant solution is coming. :)

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

        @cyperghost I think the problem is just the emulationstation.sh is being killed (which handles the restarting). Should be simple enough to avoid killing that. eg specifying the process name exactly rather than pattern matching.

        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

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

          @BuZz Please go on.... I think it is not as easy
          Because I manually lauched /opt.../ emulationstation.sh and that did not workd.
          @TMNTturtlguy discovered the /tmp thing today +1 for him

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

            @cyperghost It should be. I would guess at something like

            touch /tmp/es-restart; killall -e "/opt/retropie/supplementary/emulationstation/emulationstation"
            

            should be fine.

            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 1
            • cyperghostC
              cyperghost
              last edited by

              let me test...

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

                or to work with emulationstation running from any path. (eg with emulationstation-kids etc).

                touch /tmp/es-restart; pkill -f "/emulationstation$"
                

                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

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

                  Works fine

                  touch /tmp/es-restart; killall -e "/opt/retropie/supplementary/emulationstation/emulationstation"
                  
                  1 Reply Last reply Reply Quote 0
                  • cyperghostC
                    cyperghost @BuZz
                    last edited by cyperghost

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

                    pkill -f "/emulationstation$"

                    That let's restart just 2 PIDs... Does not work!

                    touch /tmp/es-restart; killall -e "/opt/retropie/supplementary/emulationstation/emulationstation"
                    

                    runs fine all 3 PIDs are up to date


                    Man ... I even wrote use the tty1 outputs. So indeed the relauch script was killed

                    BuZzB TMNTturtlguyT 2 Replies Last reply Reply Quote 0
                    • BuZzB
                      BuZz administrators @cyperghost
                      last edited by

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

                      pkill -f "/emulationstation$"

                      Worked here when I just tested.

                      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

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

                        @BuZz Wait I post output in a few minutes...

                        pi@retropie:~ $ ls /tmp
                        es-restart  omxplayerdbus.root  omxplayerdbus.root.pid
                        pi@retropie:~ $ ps -a
                          PID TTY          TIME CMD
                          862 tty1     00:00:00 bash
                          867 tty1     00:00:00 bash
                          868 tty1     00:00:00 emulationstatio
                          874 tty1     00:00:00 emulationstatio
                          877 tty1     00:00:13 emulationstatio
                          990 pts/0    00:00:00 ps
                        

                        The command pkill

                        pi@retropie:~ $ pkill -f -e "/emulationstation$"
                        emulationstatio killed (pid 868)
                        emulationstatio killed (pid 877)
                        

                        check with ps -a

                        pi@retropie:~ $ ps -a
                          PID TTY          TIME CMD
                          862 tty1     00:00:00 bash
                          874 tty1     00:00:00 emulationstatio
                         1001 tty1     00:00:08 emulationstatio
                         1071 pts/0    00:00:00 ps
                        

                        worked now... sorry... but 2 PIDs alive
                        If PID 874 in my current setup will be killed than ES is wrecked.

                        Thank you

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

                          @cyperghost use ps -fa as you can't tell what they are from that. probably parent bash scripts (which is correct - they shouldn't be killed).

                          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 1
                          • TMNTturtlguyT
                            TMNTturtlguy @cyperghost
                            last edited by

                            @BuZz @cyperghost

                            touch /tmp/es-restart; killall -e "/opt/retropie/supplementary/emulationstation/emulationstation"

                            runs fine all 3 PIDs are up to date

                            When i use this in my script, it runs the first time. The second time i try to run it, the script crashes with error "cant remove /tmp/es-restart

                            cyperghostC BuZzB 2 Replies Last reply Reply Quote 0
                            • cyperghostC
                              cyperghost
                              last edited by

                              @BuZz
                              Thank you I will remember that command!
                              Very usefull :)

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

                                @TMNTturtlguy I will check....
                                I tested all scripts 2 two 3 times... all runing fine

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

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

                                  @BuZz @cyperghost

                                  touch /tmp/es-restart; killall -e "/opt/retropie/supplementary/emulationstation/emulationstation"

                                  When i use this in my script, it runs the first time. The second time i try to run it, the script crashes with error "cant remove /tmp/es-restart

                                  because custom retropie scripts are actually run as root - ill change that I think, but just make sure you create it owned by pi for now.

                                  sudo -u pi touch /tmp/es-restart
                                  pkill -f "/emulationstation$"
                                  

                                  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

                                  cyperghostC 2 Replies Last reply Reply Quote 0
                                  • cyperghostC
                                    cyperghost @BuZz
                                    last edited by

                                    @BuZz Solid work!
                                    Thank you

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

                                      @BuZz What is your prefered method?
                                      pkill or killall? I think pkill offers more room for changes.

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

                                        I have updated retropie-setup so user scripts will now be launched as a normal user without elevated permissions (can use sudo in a script if needed).

                                        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 1
                                        • BuZzB
                                          BuZz administrators @cyperghost
                                          last edited by

                                          @cyperghost pkill so it can kill emulationstation running from any path.

                                          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
                                          • cyperghostC
                                            cyperghost
                                            last edited by

                                            @BuZz
                                            Ufff... that was hard stuff!

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