OpenWrt添加自启任务
HTML 2021-09-13 12:13 562
一些自己上传的二进制运行文件没有自启支持,因此手动创建
在/etc/init.d/目录下创建一个文件
#!/bin/sh /etc/rc.common
START=51
start() {
echo 'starting service'
# script here
}
stop(){
echo 'stop service'
ps | grep xxx | awk 'NR==1{print $1}' | xargs kill
}
文件头的shebang为#!/bin/sh /etc/rc.common
START=51代表此脚本将在START=50脚本执行后执行
start及stop函数为服务启动启动停止执行的内容
使用/etc/init.d/xxx start/stop/enable/disable分别为启动、停止、开启自启、禁止自启操作:
By this rc.common template, the available commands for an init scripts are as follows:
start Start the service
stop Stop the service
restart Restart the service
reload Reload configuration files (or restart if that fails)
enable Enable service autostart
disable Disable service autostart
注: 还有另一种注册服务方式 - procd init script,专注于运行在后台的服务,后续有机会了解一下:https://openwrt.org/docs/guide-developer/procd-init-scripts
发布于 2021-09-13 12:13, 最后修改于2021-09-13 12:13
© 2019 - ZXQ's Diary - zhangxiaoqiang.top