I'm running a couple scripts to drive a dot matrix display on boot of a Pi 3 B. A nodejs script just writes an image file to a path. The python script calls Adafruit_RGBmatrix to send the image to the display. The nodejs runs fine at boot. The python script can crash the entire pi when run at boot, but it runs fine when started manually with systemctl.
import Image import time from rgbmatrix import Adafruit_RGBmatrix # Rows and chain length are both required parameters: matrix = Adafruit_RGBmatrix(32, 2) matrix.SetWriteCycles(16) while True: try: image = Image.open("/home/pi/dashboard.png") image.load() matrix.SetImage(image.im.id, 0, 0) time.sleep(10) matrix.Clear() except: print("Dashboard image could not be opened!") time.sleep(5)
[Unit] Description=Dashboard Display Driver #Requires=dashboard_png.service? After=multi-user.target [Service] Type=simple ExecStart=/usr/bin/python /home/pi/src/drive-display/dashboard.py Restart=on-failure RestartSec=10 [Install] WantedBy=multi-user.target
When I run the dashboard_display.service using
systemctl start dashboard_display.service it runs for days. Running it at boot after enable, it crashes the pi somewhow.
I've tried to set up some delays on reboot and have tried various After and Require values. Also wrapped the python script in a try/except to allow it to sleep and retry.
I don't get logs but it seems like it's failing extremely fast too many times and the pi crashes.
Is there a better way to ensure these services get started when everything is available? And the python service won't start until the nodejs service is done?