Openwrt /lib/functions/procd.sh脚本

Openwrt /lib/functions/procd.sh脚本是在/sbin/procd进程启动后,将会对hotplug实现进行监听,当有hotplug的event时,将会使用hotplug.json,执行/etc/hotplug.d/下与event对应的脚本文件

[root@PandoraBox:/lib/functions]#cat /lib/functions/procd.sh 
# procd API:
#
# procd_open_service(name, [script]):
#   Initialize a new procd command message containing a service with one or more instances
#
# procd_close_service()
#   Send the command message for the service
#
# procd_open_instance([name]):
#   Add an instance to the service described by the previous procd_open_service call
#
# procd_set_param(type, [value...])
#   Available types:
#     command: command line (array).
#     respawn info: array with 3 values $restart_timeout $fail_hreshold $max_fail
#     env: environment variable (passed to the process)
#     data: arbitrary name/value pairs for detecting config changes (table)
#     file: configuration files (array)
#     netdev: bound network device (detects ifindex changes)
#     limits: resource limits (passed to the process)
#     user info: array with 1 values $username
#
#   No space separation is done for arrays/tables - use one function argument per command line argument
#
# procd_close_instance():
#   Complete the instance being prepared
#
# procd_kill(service, [instance]):
#   Kill a service instance (or all instances)
#

. $IPKG_INSTROOT/usr/share/libubox/jshn.sh

_PROCD_SERVICE=

_procd_call() {
        local old_cb

        json_set_namespace procd old_cb
        "$@"
        json_set_namespace $old_cb
}

_procd_wrapper() {
        while [ -n "$1" ]; do
                eval "$1() { _procd_call _$1 \"\$@\"; }"
                shift
        done
}

_procd_ubus_call() {
        local cmd="$1"

        [ -n "$PROCD_DEBUG" ] && json_dump >&2
        ubus call service "$cmd" "$(json_dump)"
        json_cleanup
}

_procd_open_service() {
        local name="$1"
        local script="$2"

        _PROCD_SERVICE="$name"
        _PROCD_INSTANCE_SEQ=0

        json_init
        json_add_string name "$name"
        [ -n "$script" ] && json_add_string script "$script"
        json_add_object instances
}

_procd_close_service() {
        json_close_object
        service_triggers
        _procd_ubus_call set
}

_procd_add_array_data() {
        while [ "$
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值