• 0 Votes
    15 Posts
    1k Views
    D

    I banged my head over this for some time before coming up with a solution.

    The problem is that when you hit that power button, an interrupt is sent to the login daemon, telling it to shutdown the system. You can't interrupt that in any way, or replace it with a different operation as far as I can see.

    You can create a service with killall -s SIGTERM retroarch in its shutdown operation - but by then it's too late. Systemctl has already killed all user processes - including retroarch.

    So what I had to do was actually run retroarch as a service itself. That was systemctl left it for its own shutdown procedure. I'm fairly new services, so I don't claim this is the perfect solution but it works for me.

    This is based on "retropie" on a Raspberry Pi. If you're running some other Linux system it may or may not be helpful.

    First, we need to prevent retroarch from starting in the normal way. I edited /opt/retropie/configs/all/autostart.sh, commenting out the existing lines and adding in a call to the shell bash:

    bash #/opt/retropie/supplementary/runcommand/runcommand.sh 0 _SYS_ mame-libretro ~/RetroPie/roms/mame-libretro/robotron.zip #emulationstation #auto

    Next I created a new service by adding a file /etc/systemd/system/killmame.service containing

    [Unit] Description=A service start and stop MAME cleanly After=console-setup network-online.target multi-user.target [Service] User=pi ExecStart=/home/pi/bin/start.sh ExecStop=/home/pi/bin/killmame.sh Type=simple StandardInput=tty-force TTYVHangup=yes TTYPath=/dev/tty20 TTYReset=yes SendSIGKILL=no KillMode=none [Install] WantedBy=multi-user.target

    Notes:

    You'll need to create that as root (eg. sudo nano killmame.service) killmame is a bad name for the service. It started off only intending to kill it, but morphed into a complete service - retroarch.service might be a better name All the tty stuff is needed or retroarch won't run The two scripts in ExecStart and ExecStop need to be created in the next step

    Now we create a directory /home/pi/bin and create the two scripts in the (can do this as the pi user):

    start.sh:

    #!/bin/bash cd /home/pi export TERM=linux export USER=pi chvt 20 /opt/retropie/supplementary/runcommand/runcommand.sh 0 _SYS_ mame-libretro ~/RetroPie/roms/mame-libretro/robotron.zip & bash

    The command starting /opt/retropie is what I previously had in my autostart.sh. Obviously it's specific to my game, you will need to change it to whatever you had in your autostart.sh file.

    You MUST have the & character at the end, putting the command into background. Otherwise systemctl will kill it in the early steps of shutdown. I'm not sure why.

    killmame.sh:

    #!/bin/bash # echo checking for mame running ... > /home/pi/bin/killmame.log # ps -deafww | grep libretro | grep robotron >> /home/pi/bin/killmame.log killall -s SIGTERM retroarch echo shutting down MAME at `date` >> /home/pi/bin/killmame.log

    The commented-out lines 'echo' and 'ps' were for debugging - to see if my game was actually running when it came to being shut down.

    Finally we need to register and enable our new service:

    sudo systemctl daemon-reload sudo systemctl start killmame sudo systemctl enable killmame

    All those should complete without output. If the 'start' fails, you'll need to figure out why before continuing.

    If they all work, you can reboot. Your machine should first drop into a shell prompt, but then very soon after retroarch should take over. Hitting the kill switch should now shutdown retroarch cleanly, saving high scores.

    The only glitch I've found is that if you use <ESCAPE> to exit retroarch, you'll find lots of key presses on the shell window from your game controls. Usually they're harmless but it's just possible you might accidently issue some fatal commands. Probably removing the invocation of bash from autostart.sh woud solve that, but you might then not be able to get back into a shell after exiting with escape. I generally log in remotely using ssh, so that wouldn't worry me.

    I hope this helps someone as I spent hours trawling for a solution without finding one. It was only while explaining to my wife why it was impossible, that it occurred to me to actually run retroarch as a service itself.

    If someone is able to tidy this up into a cleaner solution I'd be very grateful.

  • 0 Votes
    2 Posts
    514 Views
    K

    I've waited a week and aeverything just works fine again...

  • 0 Votes
    4 Posts
    1k Views
    C

    @mitu thanks for the codeblocks sugerence i never ear about it.
    In raspberry 3 retroflag cases if you use default script if you push power button it shutdown the pi and reset button reboot it.
    With this code the power button, shutdown the pi saving changes and the reset button restart only emulationstation if you are in main menu, or exit game if you are in a game.

    I checked pins and are the same but i dont know why in pi4 you push the button and the pi do nothing 😟

  • 0 Votes
    1 Posts
    277 Views
    No one has replied
  • 0 Votes
    11 Posts
    1k Views
    P

    @mitu @cyperghost

    I sent an e-mail to RetroFlag the other day describing the issue and from looking at the photo of the wires I sent, they said the colored wires were in the wrong position. They apologized then gave some directions on how to take the wires out and what the proper color order is.

    I tried taking them out of the black plug but it seemed a bit of a hassle. Fortunately a replacement case arrived from Amazon today and the colored wires in the replacement case are in the correct position. I rebuilt my RetroPie and the shutdown and reset worked right away :). Thanks again for the help.

    tldr: Original case wires were messed up, replacement worked.

  • 0 Votes
    12 Posts
    1k Views
    MisterMintsM

    @mitu said in Pi overheating and scripts not working:

    @MisterMints Most likely something hardware, try to return it and get another.

    Wish it was that simple! My Pi3 is over a year old and was a gift - I treated myself to a new 3B+ and was going to donate the broken one (obviously before it was broken!) to a retro gaming present for my little brother.

    At least now he gets the same present but with a brand new 3B+ instead

  • 0 Votes
    3 Posts
    748 Views
    B

    @sano Bingo!, just never saw the runtime error before. I went into raspi-config and set it to autologin to console and it boots normally into Retropie, thanks!

  • 4 Votes
    272 Posts
    99k Views
    P

    @cyperghost Hi, Thank you for your great work with this script, but I have the Issue with the Raspberry Pi Zero 2 W.
    I have installed you script and I have Connectet to Pin 5 (GPIO3) and GND a momentary switch. I also preformed the comamnd:

    raspi-gpio set PIN3 ip pu

    The shut down sequenze works fine but the zero dosn't power up again.
    Is this a zero related issue?

    raspi-gpio get

    returns:
    GPIO 3: level=1 fsel=0 func=INPUT

    Best Regards
    Predator2k4

  • Nespi Case help

    Help and Support
    6
    0 Votes
    6 Posts
    2k Views
    T

    @mitu True. I forgot they added the favorites/recents. I was referring to just the metadata. Good catch

  • 0 Votes
    1 Posts
    929 Views
    No one has replied
  • 2 Votes
    33 Posts
    7k Views
    lostlessL

    @diy_glenn said in Replacing Mausberry Script with a Python script:

    But I've connected the Reset button on my NESPi to GPIO instead, so it can be used for something more useful. F.ex. one click = reset ROM, double click = reboot etc.

    sorry all for the slight derailment, but this forum has no private message system. @DIY_glenn, im looking to do something similar with my reset button on my nespi but lost on how to hook up the gpio and how to wright a script. Many you can make a thread to explain how you did it and help us others out. I really want to learn this stuff.

  • 0 Votes
    4 Posts
    1k Views
    P

    I figured out the issue. Problem was I got an error when I followed MSL's instructions to the letter. First time I got an error saying something like "this can not be a service", second time it said "Failed to execute operation: Bad Message". I mistyped. The script:

    [Unit]
    Description=RemotePi Board Shutdown Service
    Before=multi-user.target
    Conflicts=shutdown.target
    [Service]
    ExecStart=/bin/true
    ExecStop=/etc/shutdown.sh
    Type=oneshot
    RemainAfterExit=yes
    [Install]
    WantedBy=multi-user.target

    I had "Service" on a line by itself. Doh! It's fixed now, powering on off works perfectly now. Hooray!

  • 0 Votes
    2 Posts
    1k Views
    meleuM

    @N-Game-Arts said in Retropie won't boot up anymore after installing Shutdown script:

    I've done all the updates a few days back (how to tell what update version, I haven't clue

    When you run retropie_setup, take a look at the top of that dialog box, as in the example below:
    rpsetup

  • 2 Votes
    2 Posts
    1k Views
    B

    @Stabbis awesome build with working buttons! Looks a lot cooler than mine!
    https://retropie.org.uk/forum/post/50945

  • 0 Votes
    6 Posts
    3k Views
    B

    @anasazi29

    never copy and paste the python script. HAND type it. its not that big and it wont take that long.

    Now that you said this, I noticed on your original post that you had something like “shutdown -h now” but those quotes aren't recognized as quote by the RPi. They need to be ASCII quotes like this "shutdown -h now" so when you retyped it by hand you actually fixed these quotes!

    We just talked about this the other day.

    I'm sure there are some ppl just <sighing> about this and think that its silly that I got these confused

    I wouldn't worry about that and most of the ppl on this forum are here to help and to learn. Hopefully someone else finds this and it helps them resolve their wrong use of quotation dilemmas lol.

  • 0 Votes
    3 Posts
    2k Views
    XD3lX

    Awesome, thank you much!