#๐Ÿ”’ Running Python Program on Boot within Virtual Environment

4 messages ยท Page 1 of 1 (latest)

wicked zephyr
#

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?

GitHub

Send WiFi Drone RemoteID detections over serial via Meshtastic - colonelpanichacks/drone-mesh-mapper

fiery masonBOT
#

@wicked zephyr

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

fiery masonBOT
#

@wicked zephyr

Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.