树莓派开机自启动

这个视频讲得很到位
下面是视频中的代码,方便大家复制

sudo nano /etc/systemd/system/rcLocal.service		

然后键入以下内容:

[Unit]
Description=/etc/rc.local Compatibility
After=createap.service												#服务启动的顺序在createap.service服务的后面(可填写其他你需要的,也可以不写这一行)
ConditionPathExists=/etc/rc.local								

[Service]
Type=forking																
ExecStart=/etc/rc.local												#这是开机自启程序的位置,我是在这个文件里面添加了我想启动的程序
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target

复制以上代码后,执行以下命令:

sudo systemctl enable rclocal.service
sudo chmod +x /etc/rc.local

下面可以在/etc/rc.local文件中加入自启的程序了:

sudo nano /etc/rc.local

在exit 0前面写入你的程序,例如:

#!/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
/home/pi/ship/RaspberrryPi-Project-for-PiCar/MainProgram.py&
/home/pi/ship/RaspberrryPi-Project-for-PiCar/FramesSendProgram.py&
exit 0

·····························································································································································································································································································································
经过测试后发现在rc.local中添加的程序会开机自启,即便你使用sudo systemctl disable rcLocal关掉rcLocal服务,里面的程序还是会自启。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值