2015-10-26 45 views
4

我创建了一个外壳,必要的功能,如 的start() 停止() 重新启动()如何在openwrt中自动启动应用程序?

但我的文件中,无法在开机时启动。

我已经使用update-rc.d命令在“ubuntu”中将此文件添加到自启动应用程序列表中。它在启动时成功启动。

但是在“openwrt”中我看到启用函数。任何人都知道如何使用此功能启用或有任何类似的命令一样更新的rc.d在“OpenWrt的”

我在这里有一定的参考:http://wiki.openwrt.org/doc/techref/initscripts

+0

这个问题是不是C语言,删除'C'标签。 – chqrlie

+0

我的错误...它的删除.. – runner

回答

4

/etc/init.d/中 - 目录将自动搜索并搜索启动功能或START STOP。 从开机时开始。然后

boot() { 
     echo boot 
     # commands to run on boot 
} 

开始位置开始

停止位置,然后停止

START=10 
STOP=15 

start() {   
     echo start 
     # commands to launch application 
}     

stop() {   
     echo stop 
     # commands to kill application 
} 

编辑:

在/etc/rc.common目录中的文件进行编译whoes将在启动时开始。

使您的功能:/etc/init.d/your_script.sh使

在这里你会找到有关引导http://wiki.openwrt.org/doc/techref/process.boot

+0

感谢您的回应, 但链接中的问题提供的内容说同样的事情。 我试过了..但没有工作 – runner

6
  1. 赚更多的信息,确保您的脚本的第一行写着:

    #!/bin/sh /etc/rc.common 
    
  2. 脚本复制到/etc/init.d/目录

  3. 确保执行位是

    chmod +x /etc/init.d/<your script> 
    
  4. 使你的脚本

    /etc/init.d/<your script> enable 
    

    你的脚本现在应该有一个符号链接/etc/rc.d/

    ls -lh /etc/rc.d | grep <your script> 
    
  5. 确认您的初始化脚本启用:

    /etc/init.d/<your script> enabled && echo on 
    

    如果这个命令返回on,那么你都设置了。如果这个命令没有返回任何东西,那么你的脚本没有启用。下面是启用了某个脚本的例子:

    [email protected]:~# /etc/init.d/system enabled && echo on 
    on 
    

我测试过的OpenWrt的混沌较平静15.05这些步骤,但它应该在更早版本。祝你好运!

1

如果您只需要在系统启动时(刚启动后)运行命令: 编辑/etc/rc.local这是您的文件。

默认情况下,它仅包含注释(指定的驱动程序,但是这是在一些早期版本的情况下也可以):

# Put your custom commands here that should be executed once 
# the system init finished. By default this file does nothing. 

你可以在这里添加命令。

我的例子:

# Put your custom commands here that should be executed once 
# the system init finished. By default this file does nothing. 

if grep -q '/dev/sdb2' /proc/swaps ; then swapoff /dev/sda2 ; fi 
comgt -s /etc/config/init-script.comgt 
相关问题