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

    Modify a safe shutdown script.

    Scheduled Pinned Locked Moved Help and Support
    shutdown scriptshutdownmenu
    20 Posts 5 Posters 5.4k 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.
    • mediamogulM
      mediamogul Global Moderator @cyperghost
      last edited by

      @cyperghost

      Very good to know. I'll add it to my own. Thanks.

      RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

      1 Reply Last reply Reply Quote 1
      • SixSpeedDeathS
        SixSpeedDeath @cyperghost
        last edited by

        @cyperghost I'll apologize in advance because I'm just starting to learn Linux, so I feel like a middle school kit at Harvard.

        Does that disable the Reboot and shutdown menu's in Emulation station itself?

        Is it possible to run es-shutdown from an external script, in essence shutting down emulation station in the same way that emulation station shuts down the pi?

        My guess would be to replace the "sudo shutdown -h now" with "./path-to/es-shutdown"?

        If I understand, and removing es-shutdown prevents someone from exiting emulationstation from the menu, that may come in handy for my arcade, but I wasn't planning on disabling it for now.

        My goal is to dissect their script so I understand it better, and possibly modify it to shut down the RetroPie more safely.

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

          @sixspeeddeath said in Modify a safe shutdown script.:

          Does that disable the Reboot and shutdown menu's in Emulation station itself?

          No ... it doesn't touch anything on the Graphic-Shutdown-menu

          Is it possible to run es-shutdown from an external script, in essence shutting down emulation station in the same way that emulation station shuts down the pi?

          Yes you can run the script from a external script. You can also modify the script and can path parameters to it.... like ./es_action.sh shutdown to shutdown the Pie
          or ./es_action reboot to Reboot the Pie or just ./es_action quites to terminate ES and go back to terminal.

          My guess would be to replace the "sudo shutdown -h now" with "./path-to/es-shutdown"?

          No just erase that line. ES itself gots a little script that watches for action according to files placed in temp-folder. With touch you set a access date to a file. If the file is not available it will be created. It's better then to redirect like echo > /tmp/es_shutdown

          If you start the script with /path/to/es_shutdown.sh the Pie will shutdown with sudo poweroffcommand hence to the explaination here

          My goal is to dissect their script so I understand it better, and possibly modify it to shut down the RetroPie more safely.

          You can play arround with the script and learn some bash scripting. It isn't so difficult. Don't worry! And welcome to RetroPie

          SixSpeedDeathS 1 Reply Last reply Reply Quote 1
          • SixSpeedDeathS
            SixSpeedDeath @cyperghost
            last edited by

            @cyperghost @mediamogul, I REALLY want to thank you for all your help.

            I'm trying to change careers to Linux admin, and the RetroPie has been my "Carrot" for learning the OS.

            Gradually, I'm picking the stuff up, but responses with information like what is supplied here do more than help me get a toy working, it's something I plan to use for the rest of my life.

            I can only Bury my nose in a CompTIA book for so long before I need some hands on, and this is exactly what I needed.

            Thank you.

            mediamogulM 1 Reply Last reply Reply Quote 1
            • mediamogulM
              mediamogul Global Moderator @SixSpeedDeath
              last edited by

              @sixspeeddeath

              Glad it worked out for you.

              RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

              Drakaen391D 1 Reply Last reply Reply Quote 1
              • Drakaen391D
                Drakaen391
                last edited by

                So, I love Python over Bash...

                but I cant convert one over the other....

                Any Ideas how to convert this to python?

                RPi B & RPi 3B OC (Now Raspberry pi 4b 8gb)
                Retropie (Latest Stable)
                PiBox with Wind Tunnel Cooling System

                1 Reply Last reply Reply Quote 0
                • Drakaen391D
                  Drakaen391 @mediamogul
                  last edited by

                  @mediamogul I am using the original safe shutdown part...

                  import RPi.GPIO as GPIO
                  import os
                  import time
                  
                  
                  ###look at the GPIO for the Button Switch to be depressed
                  
                  GPIO.setmode(GPIO.BCM)
                  GPIO.setup(3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
                  GPIO.wait_for_edge(3, GPIO.FALLING)
                  
                  def main():
                      while True:
                          es-close()
                  
                  def es-close():
                      os.system("/etc/killes.sh")
                  
                  while True:
                      print((es-close))
                      time.sleep(1)
                      os.system("shutdown now")
                  

                  and a very slightly modded es shutdown code

                  #!/bin/bash
                  
                  ##############################
                  #This Script was created by  #
                  #meleu on the retropieforums.#
                  ##############################
                  
                  
                  # Check if EmulationStation is running. Finish the script if doesn't.
                  espid="$(pgrep -f "/opt/retropie/supplementary/.*/emulationstation([^.]|$)")" || exit 0
                  
                  # the "sed" command below isn't a crypted message :), it's just a trick to
                  # make $emucall regex-safe to use in the "pgrep -f" below.
                  emucall="$(sed '4!d; s/\([\\"]\|[[:alnum:]_]\+=[^ ]* \)//g; s/[][(){}^$*.|+? ]/\\&/g' /dev/shm/runcommand.info)"
                  
                  # If there's an emulator running, we need to kill it and go back to ES
                  if [[ -n "$emucall" ]]; then
                      emupid="$(pgrep -f "$emucall" | tr '\n' ' ')"
                      pkill -P "$(echo $emupid | tr ' ' ',')"
                      kill "$emupid"
                      wait "$emupid"
                      sleep 0.5
                  fi
                  
                  kill "$espid"
                  wait "$espid"
                  sleep 0.5
                  

                  RPi B & RPi 3B OC (Now Raspberry pi 4b 8gb)
                  Retropie (Latest Stable)
                  PiBox with Wind Tunnel Cooling System

                  cyperghostC 1 Reply Last reply Reply Quote 0
                  • QuackwalksQ
                    Quackwalks
                    last edited by

                    I'm not understanding how or where to fix the problem of the kintaro 9000 case not saving metadata.

                    Pi Model or other hardware: Pi 3b
                    Power Supply used: 5.1v 2.5a
                    RetroPie Version Used: 4.3.17
                    Built From: Pre made SD Image on RetroPie website, updated to 4.3.17
                    USB Devices connected: dongle for wireless keyboard
                    Controller used: Official PS3 Controller

                    Drakaen391D 1 Reply Last reply Reply Quote 0
                    • Drakaen391D
                      Drakaen391 @Quackwalks
                      last edited by

                      @quackwalks Do you by chance have a large number of roms scraped?

                      RPi B & RPi 3B OC (Now Raspberry pi 4b 8gb)
                      Retropie (Latest Stable)
                      PiBox with Wind Tunnel Cooling System

                      QuackwalksQ 1 Reply Last reply Reply Quote 0
                      • QuackwalksQ
                        Quackwalks @Drakaen391
                        last edited by

                        @drakaen391 I do have a large number of roms scraped.

                        Drakaen391D 1 Reply Last reply Reply Quote 0
                        • Drakaen391D
                          Drakaen391 @Quackwalks
                          last edited by

                          @quackwalks that could be the issue, increase the wait time a few seconds because emulationstation takes more time to save the meta data if there are alot of scrapped roms

                          RPi B & RPi 3B OC (Now Raspberry pi 4b 8gb)
                          Retropie (Latest Stable)
                          PiBox with Wind Tunnel Cooling System

                          mediamogulM 1 Reply Last reply Reply Quote 0
                          • mediamogulM
                            mediamogul Global Moderator @Drakaen391
                            last edited by

                            @drakaen391 said in Modify a safe shutdown script.:

                            increase the wait time a few seconds

                            A static wait time really isn't a good idea for something like this. If you use something similar to the while statement in my example above, it will always take as as much time as it needs, no matter what the circumstances.

                            RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

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

                              @drakaen391 About your posted codings.... Does the wait command works in your case? @mediamogul and his while-loop by monitoring PID status is imho better ...

                              wait can only be used on child processes out of the own subshell

                              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.