2. Escribir el script en python.
3. Crear el script de arranque a partir de /etc/init.d/skeleton.
Si el script a partir de skeleton se queda corto, consultar esto:
https://descubriendolaorangepi.wordpress.com/2017/02/16/instalar-y-configurar-servidor-vnc/
4. Hacer el script ejecutable.
5. Actualizar el arranque:
update-rc.d
6. Un ejemplo:
import os
import sys
import time
import daemon
import signal
from pyA20.gpio import gpio
from pyA20.gpio import port
PIN_READY = port.PA7
PIN_TURNOFF = port.PA6
class GracefulKiller:
kill_now = False
def __init__(self):
signal.signal(signal.SIGINT, self.exit_gracefully)
signal.signal(signal.SIGTERM, self.exit_gracefully)
def exit_gracefully(self, signum, frame):
self.kill_now = True
# Parte principal del programa
def mainLoop():
# Inicializa la finalización del programa
killer = GracefulKiller()
# Inicializa gpio
gpio.init()
gpio.setcfg (PIN_READY, gpio.OUTPUT)
gpio.setcfg (PIN_TURNOFF, gpio.INPUT)
gpio.pullup (PIN_TURNOFF, 0) # clear pullup
gpio.output (PIN_READY, 1)
# Bucle infinito
while True:
if gpio.input(PIN_TURNOFF) == gpio.LOW:
os.system("shutdown -h now")
time.sleep(0.1)
def run():
with daemon.DaemonContext():
mainLoop()
if __name__ == "__main__":
run()
Referencias:
https://wiki.debian.org/LSBInitScripts
https://stackoverflow.com/questions/18499497/how-to-process-sigterm-signal-gracefully
https://pypi.python.org/pypi/python-daemon/
https://stackoverflow.com/questions/4637420/efficient-python-daemon
https://enavas.blogspot.com.es/2008/12/update-rcd-actualizando-el.html