Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autostart at reboot #56

Open
DivineJimmi opened this issue Feb 5, 2021 · 3 comments
Open

Autostart at reboot #56

DivineJimmi opened this issue Feb 5, 2021 · 3 comments

Comments

@DivineJimmi
Copy link

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.

@rainripples
Copy link

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

@DivineJimmi
Copy link
Author

@rainripples This isnt working for me. Its still not starting at boot.

@Notnagel
Copy link

Notnagel commented Dec 15, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants