openwrt 應用程序 開機自啓動

這幾介紹一下openwrt 應用程序包開機自啓動的兩種方法 使用的平臺是MTK7688開發板

首先寫一個以及可以跑起來的工程,這裏對工程就不做展開,以helloworld工程爲例:

helloworld工程寫在:openwrt/package/helloworld 下

自啓動腳本文件都是要的 文件爲helloworld

#!/bin/sh /etc/rc.common

START=48
STOP=10

start()
{
	service_start  /bin/helloworld &
}

stop()
{
	service_stop  /bin/helloworld
}

restart() 
{
    stop
    start
}

第一種方法:
可以參考如下方法:我是參考這個的過程實現的,但是有點出入
https://blog.csdn.net/sessos/article/details/78451007
https://blog.csdn.net/qq_15391889/article/details/97799474

概括的步驟就是:
1.1、在 openwrt/package/base-files/files/etc/init.d/下添加自啓動腳本,就是上面那個文件
1.2、該目錄下給腳本賦予可執行權限,運行命令 chmod +x helloworld
1.3、編譯 make V=99
1.4、查看openwrt/build_dir/target-mipsel_24kc_musl/root-ramips/etc/init.d目錄下是否生成helloworld文件
1.5、查看openwrt/build_dir/target-mipsel_24kc_musl/root-ramips/etc/rc.d目錄下是否生成S48helloworld文件
S48就是腳本文件的 START=48 的這個值。

有這兩個文件的生成,基本上編譯後下載,運用之後,輸入ps命令,就可以看到helloworld的是運行的了。

親測可行。

第二種方法:

2.1、在openwrt/package/helloworld/ 下建立新文件夾files
2.2、在openwrt/package/helloworld/files添加自啓動腳本
2.3、修改openwrt/package/helloworld/下的Makefile

include $(TOPDIR)/rules.mk

PKG_NAME:=helloworld
PKG_RELEASE:=1

PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk

define Package/helloworld
	SECTION:=utils
	CATEGORY:=Utilities
	TITLE:=ROCO---Helloworld -- prints a snarky message
endef

define Package/helloworld/description
	If you can't figure out what this program does, you're probably
	brain-dead and need immediate medical attention.
endef

define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) ./src/* $(PKG_BUILD_DIR)/
endef

define Package/helloworld/install
	$(INSTALL_DIR) $(1)/bin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/

	$(INSTALL_DIR) $(1)/etc/init.d  
	$(INSTALL_BIN) ./files/helloworld $(1)/etc/init.d/helloworld
endef

$(eval $(call BuildPackage,helloworld))

這個Makefile很多地方都能一樣
主要就是

define Package/helloworld/install
	$(INSTALL_DIR) $(1)/bin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/

	# 這裏不一樣,增加這個
	$(INSTALL_DIR) $(1)/etc/init.d  
	$(INSTALL_BIN) ./files/helloworld $(1)/etc/init.d/helloworld
endef

這個鏈接裏面有Makefile的與非說明,想知道的更清楚的可以點開看一下:
https://oldwiki.archive.openwrt.org/zh-cn/doc/devel/packages

2.3、編譯 make V=99
2.4、查看openwrt/build_dir/target-mipsel_24kc_musl/root-ramips/etc/init.d目錄下是否生成helloworld文件
2.5、查看openwrt/build_dir/target-mipsel_24kc_musl/root-ramips/etc/rc.d目錄下是否生成S48helloworld文件
S48就是腳本文件的 START=48 的這個值。

同樣 親測可行

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章