Post

openwrt开机启动

openwrt开机启动

/etc/init.d目录下面就是系统加载的开机配置,文件夹中的每个文件都代表一个service。 每个配置可以设置START优先级,数字越大启动越靠后,如果有很多需要依赖网络或者USB之类的启动程序最好设置靠后一些,等其他程序启动了再启动。 系统读取etc/init.d/下的启动配置文件后,系统会根据start优先级,按照顺序执行每个文件的start()函数中的命令。

假如启动teststart,编辑内容如下

vim /etc/init.d/teststart

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/sh /etc/rc.common
START=99
start(){
       nohup /opt/teststart -c /home/teststart/config >> /home/teststart/start.log 2>&1 &
}
stop(){
        # kill your pid
        kill -9 `ps | grep '/opt/teststart' | grep -v 'grep' | awk '{print $1}'`
}
restart(){
        kill -9 `ps | grep '/opt/teststart' | grep -v 'grep' | awk '{print $1}'`
        nohup /opt/teststart -c /home/teststart/config >> /home/teststart/start.log 2>&1 &
}

下一步

1
2
3
chmod +x /etc/init.d/teststart
/etc/init.d/teststart enable
/etc/init.d/teststart start

参考内容:https://sparkydogx.github.io/2019/01/09/openwrt-service-startup/

This post is licensed under CC BY 4.0 by the author.