如何使一個openwrt下的軟體開機自啟動
阿新 • • 發佈:2018-12-29
條件有三:
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
這樣許可權就有了