树莓派设置开机启动
前言
树莓派设置开机自启,看了好多教程都没有成功.
我是要设置树莓派开机运行一个 fastapi 或者 flask 的服务,要求该程序在后台运行
创建一个 bash 脚本运行 python 程序
- 很关键,一定要使用 bash 脚本去运行 python 程序,然后关键一步要给你的 bash 脚本
sudo chmod 777 <你的脚本>
设置 /etc/rc.local
文件
直接放上文件
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # Print the IP address _IP=$(hostname -I) || true if [ "$_IP" ]; then printf "My IP address is %s\n" "$_IP" fi # 所有要执行的脚本,都放在这里,一行一个 su pi -c "exec /home/pi/Desktop/pushrod/backend/1.sh &" exit 0
几点说明
- 末尾的 & ,用来表示程序在后台运行
- 前面都是固定的格式
su pi -c "exec <你的脚本的位置.sh> &"
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?