I made a run at starting the script on boot via systemd.
Before making any changes, I confirmed that my python script was working correctly with command prompt input:Everything A-OK, so I proceeded.
Here's the contents of my service file:
And here's the terminal output related to adding the service:
At this point I tried touching the sensor. Although the MQTT message was sent, there was no audio playback.
I rebooted. After reboot:
Testing gave the same result as previously: the MQTT message was sent, but there was no audio playback.
Journal:I'm all ears for your suggestions.
Before making any changes, I confirmed that my python script was working correctly with command prompt input:
Code:
python3 touch_play_random.py
Here's the contents of my service file:
Code:
[Unit]Description=Touch Sensor Audio Playback ServiceAfter=network.target[Service]ExecStart=/usr/bin/python3 /home/pi/touch_play_random.pyWorkingDirectory=/home/piStandardOutput=inheritStandardError=inheritRestart=alwaysUser=piGroup=pi[Install]WantedBy=multi-user.target
Code:
pi@hallicrafterss20r:~ $ sudo nano /etc/systemd/system/touch_play_random.servicepi@hallicrafterss20r:~ $ sudo systemctl daemon-reloadpi@hallicrafterss20r:~ $ sudo systemctl enable touch_play_random.serviceCreated symlink /etc/systemd/system/multi-user.target.wants/touch_play_random.service -> /etc/systemd/system/touch_play_random.service.pi@hallicrafterss20r:~ $ sudo systemctl start touch_play_random.servicepi@hallicrafterss20r:~ $ sudo systemctl status touch_play_random.service* touch_play_random.service - Touch Sensor Audio Playback Service Loaded: loaded (/etc/systemd/system/touch_play_random.service; enabled; pr> Active: active (running) since Wed 2024-07-24 11:13:08 EDT; 6s ago Main PID: 29217 (python3) Tasks: 2 (limit: 755) CPU: 409ms CGroup: /system.slice/touch_play_random.service `-29217 /usr/bin/python3 /home/pi/touch_play_random.pyJul 24 11:13:08 hallicrafterss20r systemd[1]: Started touch_play_random.service>
I rebooted. After reboot:
Code:
pi@hallicrafterss20r:~ $ sudo systemctl status touch_play_random.service* touch_play_random.service - Touch Sensor Audio Playback Service Loaded: loaded (/etc/systemd/system/touch_play_random.service; enabled; preset: enabled) Active: active (running) since Wed 2024-07-24 11:20:33 EDT; 1min 15s ago Main PID: 706 (python3) Tasks: 2 (limit: 755) CPU: 441ms CGroup: /system.slice/touch_play_random.service `-706 /usr/bin/python3 /home/pi/touch_play_random.pyJul 24 11:20:33 hallicrafterss20r systemd[1]: Started touch_play_random.service - Touch Sensor Audio Playback Service.
Journal:
Code:
pi@hallicrafterss20r:~ $ journalctl -u touch_play_random.service -p infoJul 20 14:13:49 hallicrafterss20r systemd[1]: Started touch_play_random.service - Run touch_play_random.py at boot.Jul 20 14:13:50 hallicrafterss20r python3[665]: Traceback (most recent call last):Jul 20 14:13:50 hallicrafterss20r python3[665]: File "/home/pi/touch_play_random.py", line 5, in <module>Jul 20 14:13:51 hallicrafterss20r python3[665]: import paho.mqtt.client as mqttJul 20 14:13:51 hallicrafterss20r python3[665]: ModuleNotFoundError: No module named 'paho'Jul 20 14:13:50 hallicrafterss20r systemd[1]: touch_play_random.service: Main process exited, code=exited, status=1/FAILU>Jul 20 14:13:50 hallicrafterss20r systemd[1]: touch_play_random.service: Failed with result 'exit-code'.Jul 20 14:13:51 hallicrafterss20r systemd[1]: touch_play_random.service: Scheduled restart job, restart counter is at 1.Jul 20 14:13:51 hallicrafterss20r systemd[1]: Stopped touch_play_random.service - Run touch_play_random.py at boot.Jul 20 14:13:51 hallicrafterss20r systemd[1]: Started touch_play_random.service - Run touch_play_random.py at boot.Jul 20 14:13:51 hallicrafterss20r python3[740]: Traceback (most recent call last):Jul 20 14:13:51 hallicrafterss20r python3[740]: File "/home/pi/touch_play_random.py", line 5, in <module>Jul 20 14:13:51 hallicrafterss20r python3[740]: import paho.mqtt.client as mqttJul 20 14:13:51 hallicrafterss20r python3[740]: ModuleNotFoundError: No module named 'paho'Jul 20 14:13:51 hallicrafterss20r systemd[1]: touch_play_random.service: Main process exited, code=exited, status=1/FAILU>Jul 20 14:13:51 hallicrafterss20r systemd[1]: touch_play_random.service: Failed with result 'exit-code'.Jul 20 14:13:51 hallicrafterss20r systemd[1]: touch_play_random.service: Scheduled restart job, restart counter is at 2.Jul 20 14:13:51 hallicrafterss20r systemd[1]: Stopped touch_play_random.service - Run touch_play_random.py at boot.Jul 20 14:13:51 hallicrafterss20r systemd[1]: Started touch_play_random.service - Run touch_play_random.py at boot.Jul 20 14:13:51 hallicrafterss20r python3[764]: Traceback (most recent call last):Jul 20 14:13:51 hallicrafterss20r python3[764]: File "/home/pi/touch_play_random.py", line 5, in <module>Jul 20 14:13:51 hallicrafterss20r python3[764]: import paho.mqtt.client as mqttJul 20 14:13:51 hallicrafterss20r python3[764]: ModuleNotFoundError: No module named 'paho'Jul 20 14:13:51 hallicrafterss20r systemd[1]: touch_play_random.service: Main process exited, code=exited, status=1/FAILU>Jul 20 14:13:51 hallicrafterss20r systemd[1]: touch_play_random.service: Failed with result 'exit-code'.
Statistics: Posted by grantalewis — Wed Jul 24, 2024 3:32 pm