首页 > 解决方案 > 为什么我的进程没有在启动时启动?(OpenWrt)

问题描述

我定义了以下脚本(称为 pcap):

#!/bin/sh /etc/rc.common
# Example script
# Copyright (C) 2007 OpenWrt.org
 
START=10
STOP=15
 
start() {        
        echo start
        ./delete_pcap
        # commands to launch application
}                 
 
stop() {          
        echo stop
        # commands to kill application 
}

我将此脚本放在 /etc/init.d 文件夹中。当我这样做时/etc/init.d/pcap start,将执行启动函数并正确执行 delete_pcap(C 语言,位于同一/etc/init.d文件夹中)程序。无论如何,如果我这样做/etc/init.d/pcap enable了,那应该在每次重新启动时执行 delete_pcap 程序,系统启动时程序不会启动。我签入了文件夹/etc/rc.d并且我有S10pcap文件(在我启用时创建)。那么,问题出在哪里?

delete_pcap为什么在系统启动时不执行?

标签: clinuxopenwrtinit.d

解决方案


尝试使用新的服务管理工具,例如 procd:

https://openwrt.org/docs/guide-developer/procd-init-scripts

您的应用的示例

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

APP=/usr/bin/pcap # specify the full path this is example

USE_PROCD=1
START=98 # indicates that process should start last
STOP=99

start_service() { # Override this to start your app
    procd_open_instance
    procd_set_param command "$APP"
    procd_close_instance
}

无需覆盖其他功能,如停止启动重启


推荐阅读