创建启动脚本
使用任何文本编辑器,在/etc/init.d目录下创建一个新的启动脚本,假设命名为your_script_name,以下是示例脚本的参考内容:
xxxxxxxxxx### BEGIN INIT INFO# Provides: your_service_name# Required-Start: $all# Required-Stop: # Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: Start your_service_name at boot time# Description: Enable service provided by your_service_name### END INIT INFO/path/to/your/program &exit 0设置启动脚本具有可执行权限
xxxxxxxxxxsudo chmod +x /etc/init.d/your_script_name使用update-rc.d命令将脚本添加到系统的启动项中
xxxxxxxxxxsudo update-rc.d your_script_name defaults使用systemctl命令启用自启动
xxxxxxxxxxsudo systemctl enable your_script_name重启开发板验证自启动服务程序是否运行正常
xxxxxxxxxx systemctl status your_script_name.servicerc.local是一个系统服务,用于在系统启动时自动执行一些脚本或命令。这个服务在系统启动时会被自动调用,并在系统启动完成后执行一些用户指定的脚本或命令,以便在系统启动时进行自定义配置或操作。
在早期的Linux发行版中,rc.local是系统启动过程中默认运行的最后一个服务。随着systemd的普及,rc.local被视为遗留的系统服务。
通过在sudo vim /etc/rc.local文件末尾添加启动命令的方式实现,例如:
x## rc.local#re# 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.# Insert what you needexit 0