简体   繁体   中英

Automatically start a program at Raspbian - Raspberry Pi 3

I'm using a Raspberry Pi 3 with Raspbian distribution.

I've written a script in Python 3 and I would need to start it up automatically just when system boots up, without logging in.

Raspberry PI has quite good support. Tasks can be schedualed with usage of "crontab" command.

You can find documentation on: Documentation

Within this documentation you have example for running "python" script on Raspberry Pi reboot.

Hope it helps!

I would recommend using systemd to achieve this. Take for example your python script is called hello.py.

  1. Create a systemd service file at /lib/systemd/system/hello.service :

     [Unit] Description=hello.py service file After=multi-user.target [Service] Type=simple ExecStart=/usr/bin/python /dir/to/your/hello.py Restart=always [Install] WantedBy=multi-user.target 

The full list of commands and functions for the systemd service file can be found here .

  1. Add appropriate permissions to the .service file: sudo chmod 644 /lib/systemd/system/hello.service

  2. Reload the systemd daemon: sudo systemctl daemon-reload

  3. Enable the hello systemd service: sudo systemctl enable hello.service

You can check that your service is running by using the command: sudo systemctl status hello.service and check for any errors using sudo journalctl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM