I have a small script that uses flask to listen to API requests and forwards them to Home Assistant and InfluxDB. It currently has a dummy name, "script.py" and is placed in /usr/local/bin. When I run it standalone, by using python3 script.py
, it works fine.
Since I want this script to be always running, I'd like it as a service. I created the following service in /usr/local/etc/rc.d/
#!/bin/sh
# PROVIDE: rest
# REQUIRE: DAEMON NETWORKING
# BEFORE: LOGIN
# KEYWORD: shutdown
. "/etc/rc.subr"
location="/usr/local/bin"
name="script"
rcvar=rest_enable
: ${rest_enable:="YES"}
logfile="/var/log/rest/${name}.log"
command="$location/$name.py"
command_args="$1"
command_interpreter="/usr/local/bin/python3"
load_rc_config $name
run_rc_command "$1"
The output is
Starting script.
Traceback (most recent call last):
File /usr/local/bin/script.py", line 4, in <module>
from flask import Flask, request, Response
ModuleNotFoundError: No module named 'flask'
/usr/local/etc/rc.d/rest: WARNING: failed to start script
Running a whereis on python3 produces the following:
root@grafana:/usr/local/etc/rc.d # whereis python3
python3: /usr/local/bin/python3
So from my understanding this should be fine. What am I missing?