Python daemon with systemd
With systemd this became trivially easy, as the .service
unit files in /etc/systemd/system/
offer an easy way. Here is a minimal example without watchdog- or soft-fail-capabilities:
[Unit]
Description=An GPIO interrupt listener for a debounced button press to trigger an action.
After=local-fs.target
[Service]
Type=simple
ExecStartPre=/bin/bash -c 'source /opt/helotism/powersupply-env/bin/activate;'
ExecStart=/bin/bash -c 'cd /opt/helotism/powersupply-env; source bin/activate; python ./mraa_interrupt.py'
[Install]
WantedBy=multi-user.target
The above unit file enters a Python virtual environment that was previously deployed there. It is executed the multi-user.target has been reached. The script runs continously in a while True:
loop, reflected by Type=simple
.
The blog post or the man page explain all the features that are available by setting just one option.