如何使一个openwrt下的软件开机自启动

条件有三:

1.需要在软件包的Makefile中添加宏定义Package/$(package-name)/preinst和Package/$(package-name)/prerm

define Package/hello/postinst
#!/bin/sh
# check if we are on real system
if [ -z "$${IPKG_INSTROOT}" ]; then
        echo "Enabling rc.d symlink for hello"
        /etc/init.d/hello enable
fi
exit 0
endef

define Package/hello/prerm
#!/bin/sh
# check if we are on real system
if [ -z "$${IPKG_INSTROOT}" ]; then
        echo "Removing rc.d symlink for hello"
        /etc/init.d/hello disable
fi
exit 0
endef

2.需要一个启动脚本,并且需要有执行权限(曾尝试过直接将脚本放置在target/linux/$(chip-series)/base-files/etc/init.d目录下,但是openwrt启动后不会执行这个脚本,为什么,因为没有执行权限,那么直接修改此脚本的权限呢?不可行)
如何实施?

将启动脚本制作成一个此软件包的补丁,放到软件包的patches目录下,脚本内容如下:

#!/bin/sh /etc/rc.common
# "new(er)" style init script
# Look at /lib/functions/service.sh on a running system for explanations of what other SERVICE_
# options you can use, and when you might want them.
 
START=200
APP=hello
SERVICE_WRITE_PID=1
SERVICE_DAEMONIZE=1
 
start() {
        service_start /usr/bin/$APP
}
 
stop() {
        service_stop /usr/bin/$APP
}

3.脚本准备好了,那么此时需要安装脚本到要制作的根文件系统中

在软件包的Makefile中的宏定义Package/$(package-name)/install里加入以下类似代码:

$(INSTALL_DIR) $(1)/etc/init.d

$(INSTALL_BIN) $(script-path) $(1)/etc/init.d

这样权限就有了

猜你喜欢

转载自www.cnblogs.com/dakewei/p/10197748.html