怪物奇妙物语

宇宙无敌超级美少男的怪物奇妙物语

首页 新随笔 联系 管理
  821 随笔 :: 0 文章 :: 2 评论 :: 16万 阅读

树莓派设置开机启动

前言

树莓派设置开机自启,看了好多教程都没有成功.
我是要设置树莓派开机运行一个 fastapi 或者 flask 的服务,要求该程序在后台运行

创建一个 bash 脚本运行 python 程序

  1. 很关键,一定要使用 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

几点说明

  1. 末尾的 & ,用来表示程序在后台运行
  2. 前面都是固定的格式
su pi -c "exec <你的脚本的位置.sh> &"
posted on   超级无敌美少男战士  阅读(166)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示