问题
需要在OpenWrt创建服务,但是OpenWrt使用的init.d方式进行服务设置的。
解决
init.d脚本
在文件夹/etc/init.d/中,创建对应的启动服务脚本,例如:/etc/init.d/example
#!/bin/sh /etc/rc.common
# Example script
# Copyright (C) 2007 OpenWrt.org
START=10
STOP=15
start() {
echo start
# commands to launch application
}
stop() {
echo stop
# commands to kill application
}
注意,这里/etc/rc.common
这里需要继承的父init.d脚本,这样我们自己的脚本只要实现start
和stop
即可,不用关心通用的enable
和disable
的实现,至于start
和stop
的具体实现,可以参考之前介绍的init.d脚本模板。
使用service
# 启动服务
service example start
# 停止服务
service example stop
# 启用开机自启动
service example enable