繁体   English   中英

在Raspbian上自动启动程序-Raspberry Pi 3

[英]Automatically start a program at Raspbian - Raspberry Pi 3

我正在使用带有Raspbian发行版的Raspberry Pi 3。

我已经用Python 3编写了一个脚本,并且需要在系统启动时自动启动它,而无需登录。

Raspberry PI具有很好的支持。 可以使用“ crontab”命令来安排任务。

您可以在以下位置找到文档: 文档

在本文档中,您有在Raspberry Pi重新启动时运行“ python”脚本的示例。

希望能帮助到你!

我建议使用systemd实现此目的。 例如,您的python脚本称为hello.py。

  1. /lib/systemd/system/hello.service创建一个systemd服务文件:

     [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 

可以在此处找到systemd服务文件的命令和功能的完整列表。

  1. 向.service文件添加适当的权限: sudo chmod 644 /lib/systemd/system/hello.service

  2. 重新加载systemd守护程序: sudo systemctl daemon-reload

  3. 启用hello systemd服务: sudo systemctl enable hello.service

您可以使用以下命令检查服务是否正在运行: sudo systemctl status hello.service并使用sudo journalctl检查是否有任何错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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