多进程 InitScript 逻辑

发布于 2024-10-01 14:06:59 字数 656 浏览 2 评论 0原文

我正在为我们的一些软件开发初始化脚本,但很难决定如何将它用于特定的部分。

我们有自己开发的软件,负责在网络中传递数据,它是基于标准的发布订阅模型构建的。有一个发布者进程(实际上有两个,用于两个不同的用例)、一个代理进程和一个订阅者进程)。这些进程的任意组合,甚至多个相同进程,都可以在给定的机器上同时运行。我无法决定如何最好地进行配置。由于它可能因盒子而异,因此可能会进入 /etc/sysconfig/pubsub ,并由 initscript 读入。

我唯一需要允许配置的是 (1) 进程名称,它是 log_publish、dir_publish、broker、subscribe 之一,以及 (2) 与该特定进程对应的配置文件。

我希望避免告诉人们如何修改每个盒子的初始化脚本以更改正在运行的进程列表,因此每个盒子的这个独特的配置文件是我能想到的实现这一目标的最佳方法。

我认为这也意味着我必须在盒子上为每个进程提供某种唯一标识符,因为我打算使用大多数 RedHat 初始化脚本使用的 touch /var/lock/subsys/* 方法已经锁定一个进程不运行两次。知道这一点,我知道标识符不能总是随机的,否则它永远不会有效,以防止具有相同配置文件的重复进程(因为,同样,我需要能够使用不同的配置文件运行多个进程) 。

我不知道如何最好地在配置中表示这一点。

I am developing initscripts for some of our software, and am having difficulty deciding how I should use it for a particular piece.

We have homegrown software responsible for passing data around out network, it's built on a standard pubsub model. There is a publisher process (two, actually, for two different use cases), a broker process, and a subscriber process). Any combination of these processes, and even multiple of the same process, can run simultaneously on a given box. I'm having trouble deciding how best to allow this to be configured. Since it can vary from box to box, that will likely go into /etc/sysconfig/pubsub which will be read in by the initscript.

The only things I will have to allow to be configured is (1) the process name, which is one of log_publish, dir_publish, broker, subscribe, and (2) the configuration file that corresponds to that particular process.

I wish to avoid telling people how to modify the initscript per box in order to change the list of running processes, so this unique configuration file per box is the best way I can come up with to accomplish that.

I assume this also means that I will have to have some kind of unique identifier per process on the box, as I intend to use the touch /var/lock/subsys/* method that most RedHat initscripts use already to lock a process from running twice. Knowing this, I know the identifier can't always be random, otherwise it will never be effective in order to prevent duplicate processes with the same configuration file (because, again, I need to be able to run multiple processes with different configuration files).

I have no idea how best to represent this in configuration.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

素罗衫 2024-10-08 14:06:59

我的实现方式与 VNC 作为初始化脚本运行时的方式类似。

如果您查看发行版的 vnc init 配置文件(例如 RedHat/CentOS:/etc/sysconfig/vncservers),您会看到以下内容:

# The VNCSERVERS variable is a list of display:user pairs.
#
# Uncomment the line below to start a VNC server on display :1
# as my 'myusername' (adjust this to your own).  You will also
# need to set a VNC password; run 'man vncpasswd' to see how
# to do that.  
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted!  For a secure way of using VNC, see
# <URL:http://www.uk.research.att.com/vnc/sshvnc.html>.

# VNCSERVERS="1:myusername"
# VNCSERVERARGS[1]="-geometry 800x600"

非常简单。您可以定义屏幕编号以及必要时要匹配的参数。

所以现在,我有,例如:

PUBSUBPROCS="1:publish 2:broker 3:subscribe"
PUBSUBARGS[1]="/config/publish.cfg"
PUBSUBARGS[2]="/config/broker.cfg"
PUBSUBARGS[3]="/config/subscribe.cfg"

解析这个的大部分逻辑也从 vncserver initscript 中删除,由于篇幅原因我不会在这里发布。

I've implemented this similarly to how VNC does it when run as an initscript.

If you look at your distro's configuration file for vnc init (ex. RedHat/CentOS: /etc/sysconfig/vncservers), you see this:

# The VNCSERVERS variable is a list of display:user pairs.
#
# Uncomment the line below to start a VNC server on display :1
# as my 'myusername' (adjust this to your own).  You will also
# need to set a VNC password; run 'man vncpasswd' to see how
# to do that.  
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted!  For a secure way of using VNC, see
# <URL:http://www.uk.research.att.com/vnc/sshvnc.html>.

# VNCSERVERS="1:myusername"
# VNCSERVERARGS[1]="-geometry 800x600"

Pretty straight forward. You define a screen number, and parameters to match if necessary.

So now, I have, for example:

PUBSUBPROCS="1:publish 2:broker 3:subscribe"
PUBSUBARGS[1]="/config/publish.cfg"
PUBSUBARGS[2]="/config/broker.cfg"
PUBSUBARGS[3]="/config/subscribe.cfg"

And most all of the logic for parsing this was also ripped out from the vncserver initscript, which I will not post here for length reasons.

爱的那么颓废 2024-10-08 14:06:59

我想说有多个初始化脚本,每个进程类型一个,然后让每个进程的配置确定要生成多少个进程。

I'd say have multiple initscripts, one per process type, and then let the configuration for each determine how many of that process to spawn.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文