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.
python: dashboard.py
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)
systemd dashboard_display.service
[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?
Some information is missing in your question, but I am assuming the commented-out
#Requires=dashboard_png.service
is the nodejs script that suppose to createdashboard.png
file. Also, missing the description of the "crash" I can only assume it is being caused by eitherdashpoard.png
not being there at all, or being written by the nodejs while pythin is trying to read from it.Having made those two assumptions, I would suggest trying to add
After=dashboard_png.service
to the[Unit]
part of thedashboard_display.service
, and uncommenting theRequires=dashboard_png.service
.According to the systemd.unit manual:
Although the quote is taken from the description of
Wants=
directive, the same applies to theRequires=
directive as well.