Autostart at reboot
Opened this issue · 3 comments
Hey guys,
is there an easy way to autostart the script at reboot? already tried the crontab.
@reboot python3 /home/pi/pistreaming/server.py
but this is not working.
Try
@reboot /usr/bin/python3 /home/pi/pistreaming/server.py
crontab is very touchy about paths
also make sure you “sudo crontab -e” to edit
@rainripples This isnt working for me. Its still not starting at boot.
There are always multiple ways to start scripts on the raspberry pi. Maybe check general sources on how to start python scripts on startup.
Check this link which uses systemd. This seems to be the best option (in 2022). Older approaches using rc.local are deprecated
https://medium.com/codex/setup-a-python-script-as-a-service-through-systemctl-systemd-f0cc55a42267
Below is my file mycamera.service which sits in /etc/systemd/system.
Go to:
cd /etc/systemd/system
Open the editor
sudo nano mycamera.service
Pase the code, only change required is YOURUSERNAME, which is the username of your raspberrypi.
[Unit]
Description=MY CAMERA
After=multi-user.target
[Service]
WorkingDirectory=/home/YOURUSERNAME/pistreaming
Type=simple
Restart=always
ExecStart=/usr/bin/python3 server.py
[Install]
WantedBy=multi-user.target
Ctrl + x to exist the editor. Confirm Y you want to save
Now enable this to boot up on restart
sudo systemctl enable mycamera.service
You can also start the service right away by
sudo systemctl start mycamera.service