I'm new to the Raspberry Pi, but have gotten mosquitto to work & a similar mosquitto service running on one pi, but when I try running it on another Pi I encounter an error. For context, the service runs a python3 script that acts as a subscriber for mosquitto running on the Pi. Messages are sent from an iOS app. All works fine if I run as: python3 control-baldwinbot.py # which is my subscriber python code and, as Ingo suggest below, this also works fine /usr/bin/python3 /home/pi/control-baldwinbot.py but I can't seem to get a script (working on another Pi) to work as written, below:
The .service file is saved as: /lib/systemd/system/baldwinbot-mqttclient.service
and it contains this script:
[Unit]
Description=Baldwinbot MQTT Script Service
After=mosquitto.service
[Service]
Type=idle
ExecStart=/usr/bin/python3 /home/pi/control-baldwinbot.py
Restart=always
[Install]
WantedBy=multi-user.target
When I run a sudo systemctl status baldwinbot-mqttclient.service I get this output:
● baldwinbot-mqttclient.service - Baldwinbot MQTT Script Service
Loaded: loaded (/lib/systemd/system/baldwinbot-mqttclient.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2019-02-26 21:49:12 GMT; 32s ago
Process: 763 ExecStart=/usr/bin/python3 /home/pi/control-baldwinbot.py (code=exited, status=1/FAILURE)
Main PID: 763 (code=exited, status=1/FAILURE)
Feb 26 21:49:12 baldwinbot systemd[1]: baldwinbot-mqttclient.service: Failed with result 'exit-code'.
Feb 26 21:49:12 baldwinbot systemd[1]: baldwinbot-mqttclient.service: Service hold-off time over, scheduling restart.
Feb 26 21:49:12 baldwinbot systemd[1]: Stopped Baldwinbot MQTT Script Service.
Feb 26 21:49:12 baldwinbot systemd[1]: baldwinbot-mqttclient.service: Start request repeated too quickly.
Feb 26 21:49:12 baldwinbot systemd[1]: Failed to start Baldwinbot MQTT Script Service.
Feb 26 21:49:12 baldwinbot systemd[1]: baldwinbot-mqttclient.service: Unit entered failed state.
Feb 26 21:49:12 baldwinbot systemd[1]: baldwinbot-mqttclient.service: Failed with result 'exit-code'.
mosquitto is running, checked via: sudo systemctl is-active mosquitto.service with the returned response: active
Thanks for your help!
/home/pi/control-baldwinbot.py
exits with a status 1/FAILURE - perhaps it needs to be run aspi
notroot