Shutdown Script
-
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
-
Hello
to put script in /etc/init.d/SXXNamescriptbut 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 :
- you need a S99 script which stop parameter would bring that gpio up
- you need a S01script which stop parameter would bring that gpio down (despite it would happen anyway by itself as it is shutting down
-
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 astop
argument.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 likeS99zled
so that you're sure it gets called first. The python part should be rather easy, but just say if you need some help. -
Thank you very much @subs. I will try this.
With python I do not have any problems thank you -
@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 ? -
@lackyluuk
Quelqu'un aurait vu notre ami suisse ? -
-
At the moment very busy. I hope he has more time soon.
-
@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 -
@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
-
@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
-
@Substring
Good idea, I will try this out tomorrow. Have nice dreams . -
@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. -
-
@Substring
Tu sais, parfois ces drôles de machines se fouttent tout simplement de notre gueule -
@dragu nan, c'est toujours du pebkac