如何使一個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

這樣權限就有了

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM