Start an application at boot
Run a service automatically and inspect its logs.
Start an application automatically only after it runs reliably in a terminal and has a clear stop path. On an image with systemd user services, a user unit keeps the process separate from system services.
Create a user service
Create ~/.config/systemd/user/my-app.service with paths adjusted for your project:
[Unit]
Description=My robot application
After=network-online.target
[Service]
WorkingDirectory=%h/projects/my-app
ExecStart=%h/projects/my-app/.venv/bin/python %h/projects/my-app/src/main.py
Restart=on-failure
RestartSec=3
[Install]
WantedBy=default.target
Then load and start it:
systemctl --user daemon-reload
systemctl --user enable --now my-app.service
systemctl --user status my-app.service
Inspect and stop
journalctl --user -u my-app.service -f
systemctl --user stop my-app.service
User services may stop when the user logs out unless lingering is enabled by a system administrator. Confirm the image's init system before using this recipe. Keep motor-enable logic out of automatic startup until physical safety checks have been completed.