I’m building a Caravan Movement detector which applies the caravan electric brakes, flashes the lights and blows the horn when it detects movement of the caravan. I’m using a ‘PiicoDev OLED Display Module (128x64) SSD1306’ to display status. When I run the python program from the command line, everything works fine. If I run the program as a service the program fails being unable to find the ‘font-pet-me-128.dat’ file for SSSD1306.
As a workaround I amended the font file line in the ‘PiicoDev_SSD1306.py’ module in ‘/home/pi/.local/lib/python3.9/site-packages’ to the full path to the font file. ie ‘/home/pi/Apps/font-pet-me-128.dat’. Was this the correct way?
Hi @Robert129207,
I would consider changing anything in site-packages as only a temporary fix, as OS updates or pip functions may overwrite these files at their own will in the future.
Sounds like when run as a service the OS is running it as a different user and/or the python environment setup is slightly different than when run as the pi
user.
Which method are you using to run your script as a service?
It’s run as the pi user.
Hi Robert,
I’ve tried reading up on your issue and it may depend on exactly how you’ve set the program to run as a service upon startup. Like everything in linux it seems there are 5 different ways to do anything and each has their own pitfalls
The article I’ve linked below covers some of the methods you can use to run a program as a service on startup.
Thanks Trent. I’m using Method4 SYSTEMD and the service file looks like
[Unit]
Description=Caravan Tracker
After=network-online.target
[Service]
Type=idle
ExecStart=/usr/bin/python3 /home/pi/Apps/vanmove04.py
Restart=always
User=pi
[Install]
WantedBy=multi-user.target