zoukankan      html  css  js  c++  java
  • 如何使一个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

    这样权限就有了

  • 相关阅读:
    理解 Javascript 执行上下文和执行栈
    CSS中选择器优先级的权重计算
    一年内经验前端面试题记录
    ie8兼容问题
    css文本两端对齐
    前端 SPA 单页应用数据统计解决方案 (ReactJS / VueJS)
    我在SharePoint行业的从业经历(一)
    android中的AlertDialog具体概述
    Android 最火的高速开发框架xUtils
    Project Euler:Problem 93 Arithmetic expressions
  • 原文地址:https://www.cnblogs.com/dakewei/p/10197748.html
Copyright © 2011-2022 走看看