自动启动多个upstart实例
我们使用 PHP gearman 工作线程并行运行各种任务。一切都工作得很好,我有一个愚蠢的小 shell 脚本可以在我需要的时候启动它们。作为一名程序员(因此很懒),我想看看是否可以通过新贵脚本来启动它们。
我想出了如何使用实例节,所以我可以用一个实例号来启动它们:
description "Async insert workers"
author "Mike Grunder"
env SCRIPT_PATH="/path/to/my/script"
instance $N
script
php $SCRIPT_PATH/worker.php
end script
这很有效,像这样启动它们:
sudo start async-worker N=1
sudo start async-worker N=2
我想使用这些工作人员的方式是启动其中一些工作人员(也许是一个)每个核心等),我想在启动时执行此操作。需要明确的是,我不需要新贵脚本来检测核心数量。我很高兴只说“执行 8 个实例”,但这就是我想要多次运行的原因。有没有办法让我在新贵脚本中使用“start on”子句来自动执行此操作?
例如启动实例1、2、3、4?然后让它们在关机时正常退出?
我想我可以将其挂接到 init.d 脚本中,但我想知道 upstart 是否可以处理这样的事情,或者是否有人已经解决了这个问题。
干杯伙计们!
We use PHP gearman workers to run various tasks in parallel. Everything works just fine, and I have silly little shell script to spin them up when I want them. Being a programmer (and therefore lazy), I wanted to see if I could spin these up via an upstart script.
I figured out how to use the instance stanza, so I could start them with an instance number:
description "Async insert workers"
author "Mike Grunder"
env SCRIPT_PATH="/path/to/my/script"
instance $N
script
php $SCRIPT_PATH/worker.php
end script
And this works great, to start them like so:
sudo start async-worker N=1
sudo start async-worker N=2
The way I want to use these workers is to spin up some number of them (maybe one per core, etc), and I would like to do this on startup. To be clear, I don't need the upstart script to detect the number of cores. I'm happy to just say "do 8 instances", but that's why I want multiple running. Is there a way for me to use the "start on" clause in an upstart script to do this automatically?
For example, start instance 1, 2, 3, 4? Then have them exit on shutdown properly?
I suppose I could hook this into an init.d script, but I was wondering if upstart can handle something like this, or if anyone has figured out this issue.
Cheers guys!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要的是一个引导任务,该任务在启动时运行并迭代所有辅助作业,启动每个作业。
关键是使其成为一个任务,它告诉 upstart 让任务运行完成,然后再为其发出任何事件。请参阅 http://upstart.ubuntu.com/cookbook/#task 和 http://upstart.ubuntu.com/cookbook/#instance
What you need is a bootstrap task that runs on startup and iterates over all your worker jobs, starting each one.
The key is to make this a task, which tells upstart to let the task run to completion before emitting any events for it. See http://upstart.ubuntu.com/cookbook/#task and http://upstart.ubuntu.com/cookbook/#instance