Recalbox 7.0

Shutdown Script


  • Translation Master

    Hello 🙂

    There is the init.d directory to add startup scripts to reclabox. Is there a similar directory where I can add a shutdown script? Because I need to set a GPIO pin to high when the shutdown process begins and then set it to low when the shutdown is finished.
    Is there a way to achieve this?

    Thanks for your help 🙂


  • Global moderator
    Team

    Hello
    to put script in /etc/init.d/SXXNamescript

    but in recalbox.conf look theses lines : https://github.com/recalbox/recalbox-os/wiki/recalbox.conf-(EN)

    ;system.power.switch=PIN56ONOFF          # https://github.com/recalbox/recalbox-os/wiki/Add-a-start-stop-button-to-your-recalbox-(EN)
    ;system.power.switch=PIN56PUSH           # https://github.com/recalbox/recalbox-os/wiki/Add-a-start-stop-button-to-your-recalbox-(EN)
    ;system.power.switch=PIN356ONOFFRESET    # https://github.com/recalbox/recalbox-os/wiki/Add-a-start-stop-button-to-your-recalbox-(EN)
    


  • hey @lackyluuk

    Do you mean you'd like a gpio to be set at UP when shutting down and off once the shutdown procedure is over ? Quite easy to do combining python and some well placed Sxx script :

    1. you need a S99 script which stop parameter would bring that gpio up
    2. you need a S01script which stop parameter would bring that gpio down (despite it would happen anyway by itself as it is shutting down

  • Translation Master

    Thank you very much for your answers @acris and @subs.

    Yes this is what I meant @subs. I want to set a GPIO pin to HIGH when the shutdown procedure begins. And as you said I do not need to set it to FALSE again 🙂

    I know where to set startup scripts (init.d), but not where to set shutdown scripts. Could you please help me out? 🙂



  • @lackyluuk here is a simple example : https://github.com/recalbox/recalbox-buildroot/blob/rb-4.1.X/board/recalbox/fsoverlay/etc/init.d/S25lircd

    All scripts are triggered at start with a start argument, as well as at shutdown with a stopargument.

    A init skeleton script would look like this :

    #!/bin/sh
    
    start() {
    
    }
    
    stop() {
    
    }
    
    case "$1" in
      start)
    	start
    	;;
      stop)
    	stop
    	;;
      restart|reload)
    	stop
    	start
    	;;
      *)
    	echo "Usage: $0 {start|stop|restart}"
    	exit 1
    esac
    
    exit $?
    

    You'd just need to populate the start and stop functions. In your case, the stop function only, and get rid of everything related to start or restart, so after all it would look like this :

    #!/bin/sh
    
    stop() {
    
    }
    
    case "$1" in
      stop)
    	stop
    	;;
    esac
    

    You could even code everything in your stop) case. Now you'd just need to call a python script to raise your gpio output to 1. Call your init.d script something like S99zled so that you're sure it gets called first. The python part should be rather easy, but just say if you need some help.


  • Translation Master

    Thank you very much @subs. I will try this.
    With python I do not have any problems 🙂 thank you


  • Banned

    @lackyluuk
    I know, is old, this means, you have resolved the case. I would also need such script. I can tell you why. My Nespi near his TV is in a closed case and I always anyway soft shutdown it in ES. After, I have further a remote socket (Is not the only one in this room) to switch it off totaly. So, as I cannot see a modified power led through the shelf door, I want to use a buzzer instead that sounds during the shutdown process. Weird, but are we not here to invent always new perversities ?


  • Banned

    @lackyluuk
    Quelqu'un aurait vu notre ami suisse ?



  • @dragu @abunille any news from lackyluuk ?



  • @substring

    At the moment very busy. I hope he has more time soon.


  • Translation Master

    @Dragu @Substring I am sorry that I didn't reply. I am still here 🙂 Currently I am quite busy with other things as @abunille said. I really hope that there is more time soon. There is still work to do for the wiki :))
    @Dragu I think your proposal is possible. Let me check my config (it's a while ago :D) and then I can give you more information 🙂


  • Banned

    @Substring
    I tried something out, probably full of errors.
    I put the stop case in custom.sh together with a call to my other script.

    #!/bin/bash
    
    python /recalbox/share/myscripts/run-fan.py &
    
    stop() {
    python /recalbox/share/myscripts/buzzer.py &
    }
    
    case "$1" in
      stop)
    	stop
    	;;
    

    and for the pin that should be high during shutdown (I use 23).

    #!/usr/bin/env python3
    import os
    import signal
    import sys
    import RPi.GPIO as GPIO
    def setup():
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(23, GPIO.OUT)
        GPIO.setwarnings(False)
        setPin(True)
        return()
    try:
        setup()
    except:
        GPIO.cleanup()
    


  • @dragu if should rather look like

    #!/bin/bash
    
    stop() {
    python /recalbox/share/myscripts/buzzer.py &
    }
    
    case "$1" in
      start)
        ;;
      stop)
    	stop
    	;;
    
    

    Or you're starting twice your script. I added a start "in case" you'd ever need one for later purpose


  • Banned

    @Substring
    Thanks, but the first line is my fan control, so they cannot be both in custom.sh ?



  • @dragu add the fan control in the start then


  • Banned

    @Substring
    Good idea, I will try this out tomorrow. 🙂 Have nice dreams . 😉


  • Banned

    @Substring
    J'ai testé, il semble que le script ventilo ne fonctionne pas dans le start().
    Quelque part aussi logique, je présume que c'est juste prévu comme runonce, donc scripts qui s'exécutent seulement une fois.



  • @dragu custom.sh reçoit start comme paramètre au boot, donc aucune raison que ca ne marche pas


  • Banned

    @Substring
    Tu sais, parfois ces drôles de machines se fouttent tout simplement de notre gueule 😉



  • @dragu nan, c'est toujours du pebkac 😛


Log in to reply
 

Want to support us ?

106
Online

79.1k
Users

20.3k
Topics

149.1k
Posts