I am trying to make a python program run on boot within a virtual environment. OS is Raspbian 11.
The specific program is "mesh-mapper.py" from this repo: https://github.com/colonelpanichacks/drone-mesh-mapper
If I start the program using this command, it works perfectly:
2>/dev/null 1>&2 /home/petro/drone-mesh-mapper/venv/bin/python3 /home/petro/drone-mesh-mapper/mesh-mapper.py &
The program starts and runs in the background just like I need it to. I need it to do that automatically on boot.
I wrote a bash script:
`#!/bin/bash
until 2>/dev/null 1>&2 /home/petro/drone-mesh-mapper/venv/bin/python3 /home/petro/drone-mesh-mapper/mesh-mapper.py; do
echo "Drone detector crashed with exit code $?. Respawning.." >> /home/petro/droneServerLog.log
sleep 1
done`
If I run that script and background it with ./droneDetect.sh &, everything still works as it should.
So I call the script with a one shot service on boot:
`[Unit]
Description=droneDetector
After=network.target
[Service]
ExecStart=/home/petro/droneDetect.sh
SyslogIdentifier=droneDetector
Type=oneshot
User=petro
[Install]
WantedBy=default.target`
The service runs sucessfully, but the python program is not running. From journalctl -xe
Nov 24 09:01:59 rpiDrones systemd[1]: droneDetect.service: Succeeded. โโ Subject: Unit succeeded โโ Defined-By: systemd โโ Support: https://www.debian.org/support โโ โโ The unit droneDetect.service has successfully entered the 'dead' state. Nov 24 09:01:59 rpiDrones systemd[1]: Finished droneDetector. โโ Subject: A start job for unit droneDetect.service has finished successfully
I know the python program starts, because I get a new "detections_<timestamp>.csv" file in the output folder at each boot. This file is created by mesh-mapper.py each time it starts.
Why won't it stay running when started this way? Is there a better way?