怎样写一个基于procd的init脚本

摘要:
Examples这个页面还在不断完善中…怎样写一个基于procd的init脚本?procdinit脚本跟原来的init脚本有些类似,但是最主要的不同是,procd期望服务运行在前台它作为已存在的脚本必须以sh/etc/rc.common开始,为兼容考虑也需要"USE_PROCD=1"行.#!/bin/sh/etc/rc.commonUSE_PROCD=1启动一个服务我们需要一个函数'start_service',stop_service函数可选,只在你需要在停止服务的时候需要做某些事的时候需要。stop_service()在procd杀死这个服务后调用。

怎样写一个基于procd的init脚本?

https://wiki.openwrt.org/zh-cn/inbox/procd-init-scripts English

怎样写一个基于procd的init脚本第1张

这个页面还在不断完善中 …

怎样写一个基于procd的init脚本?

procd init 脚本跟原来的init脚本有些类似,但是最主要的不同是,procd期望服务 运行在前台

它作为已存在的脚本必须以sh /etc/rc.common开始, 为兼容考虑也需要 "USE_PROCD=1" 行.

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

USE_PROCD=1

启动一个服务我们需要一个函数'start_service',stop_service函数可选,只在你需要在停止服务的时候需要做某些事的时候需要。 stop_service() 在procd杀死这个服务调用。 The service itself should run in the foreground. (Apparently

start_service() {
  procd_open_instance
  procd_set_param command /sbin/your_service_daemon -b -a --foo
  procd_set_param respawn # respawn automatically if something died, be careful if you have an alternative process supervisor
  procd_set_param env SOME_VARIABLE=funtimes  # pass environment variables to your process
  procd_set_param limits core="unlimited"  # If you need to set ulimit for your process
  procd_set_param file /var/etc/your_service.conf # /etc/init.d/your_service reload will restart the daemon if these files have changed
  procd_set_param netdev dev # likewise, except if dev's ifindex changes.
  procd_set_param data name=value ... # likewise, except if this data changes.
  procd_close_instance
}

TODO: Table old openwrt initscript ↔ new procd

For as much information as is available, see the documentation at the top of procd.sh

Procd triggers on config file / network interface changes

In older versions of OpenWrt, a system called "ucitrack" attempted to track UCI config files, and the processes that depended on each of them, and would restart them all as needed. This too, is replaced with ubus/procd, and expanded to allow notifying services when network interfaces change. This is useful for services like dnsmasq, and proxy/routing software that cares about which network interfaces are in use, and with what configuration.

First, to simply make your service depend on a config file, add a "service_triggers()" clause to your init script

service_triggers()
{
        procd_add_reload_trigger "uci-file-name"
}

This will setup hooks such that issuing 'reload_config' will issue a call to '/etc/init.d/<yourinitscript> reload' when the md5sums of '/etc/config/uci-file-name' has changed. You can edit as many config files as you like, and then issue reload_config, procd will take care of reloading all of them. Note, no change in the config file, no reload. If you want to explicitly reload, you still need to issue '/etc/init.d/<yourservice> reload' manually.

By default, "reload" will cause a stop/start call, unless you have provided the 'reload()' call explicitly in your init script. There is not (currently, r41147) support for grabbing the PID of a procd service, or sending a signal to that service in the reload routine, but it should be possible "soon™"

reload()
{
        service_reload
        printf "service reloaded at %s" "$(date)" >> /tmp/somefile
}

If you want/need your service to depend on changes to networking, simply modify your service_triggers section, like so..

service_triggers()
{
        procd_add_reload_trigger "uci-file-name" "second-uci-file"
        procd_add_network_trigger "lan"|"etho0" FIXME - this is still a work in process....
}

igmpproxy is (currently) the only service that makes use of this, but (hopefully) by the time you read this, dnsmasq will also have been updated, at least.

How do these scripts work?

All arguments are packed into json and send over to procd via ubus

Examples

zh-cn/inbox/procd-init-scripts.txt · Last modified: 2015/01/20 04:04 by czhongm
怎样写一个基于procd的init脚本第2张

免责声明:文章转载自《怎样写一个基于procd的init脚本》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇ffmpeg+java视频转换基础示例高性能MySQL(第3版) 中文PDF带目录清晰版下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

试图加载格式不正确的程序。 (异常来自 HRESULT:0x8007000B)

解决方法:iis应用程序池--˃高级设置--˃启用32位应用程序˂!body{font-family:"Verdana";font-weight:normal;font-size:.7em;color:black;}p{font-family:"Verdana";font-weight:normal;color:black;margin-top:-5px}b...

CAS单点登录------未认证授权服务

问题背景:之前我使用的127.0.0.1进行CAS直接url进行过滤!后来我用nginx进行反向代理出现问题:如下图第一眼,就在内心想,草这什么鬼!调试了五分钟发现还是不行!  网上各种教程!  半小时过去了!我吧配置文件自己看看!    出现这样问题:原因是CAS 的服务认真之前先有个REgx的正则判断,目录如上看这个正则时候,我瞬间明白了,我下面这个问题...

开源跳板机jumpserver的安装部署和使用详细教程及踩坑经验

安装篇jumpserver需要依赖于mysql数据库,python开发工具的支持,所以需要安装一系列软件。按照提示进行所有流程的安装,安装完成之后访问http://ip:8000端口即可登录到jumpserver。因为jumpserver会在被管理的后端主机上通过此处指定的管理用户来添加指定的用户和sudo权限:配置sudo授权,用于添加sudo授权。...

weblogic补丁下载与安装补丁的方法

去:https://jingyan.baidu.com/article/642c9d34b3b493254a46f7e4.htmlweblogic安装应用程序后,可能会发现该版本存在漏洞。我们可以根据weblogic漏洞报告下载补丁,然后修复相应的漏洞。我们如何下载和安装修补程序?Weblogic 10.3.6.0 Linux步骤1:在Weblogic中出现...

Cesium深入浅出之可视域分析【转】

吸引人的视觉领域分析功能终于到来了!但没有办法。铯不支持自定义光源。没有它,我们就无法实现可视化领域分析。MaximumDistanceNumber5000.0生成级联阴影的最大距离。黑暗数字0.3阴影的黑暗。Frustum也称为平截头体,是相机的视觉表示。原始笛卡尔3圆锥体的起点。让我们改变想法。由于ShadowMap的构建需要一个摄像头,我们可以直接使用...

[RTOS]--uCOS、FreeRTOS、RTThread、RTX等RTOS的对比之特点

本博客将详细介绍这些RTOS的特点。以下内容来自官方网站或官方手册Feature的谷歌翻译,由我进行了一些调整,没有任何主观因素。1.FreeRTOS FreeRTOS是一个为小型嵌入式系统设计的可扩展实时内核。亮点包括:小包装。免费RTOS调度器免费嵌入式软件源代码。免版税。抢占式、协作式和混合式配置选项以及时间切片是可选的。SafeRTOS衍生产品提供高...