自动启动多个暴发户实例 [英] Starting multiple upstart instances automatically

查看:96
本文介绍了自动启动多个暴发户实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用PHP齿轮工来并行运行各种任务.一切正常,我有一个愚蠢的小shell脚本可以在需要时将其旋转.作为一名程序员(因此很懒惰),我想看看是否可以通过一个暴发户脚本将它们升级.

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

我要使用这些工作程序的方式是启动一些工作程序(也许每个内核一个,等等),我想在启动时这样做.需要明确的是,我不需要upstart脚本来检测内核数量.我很高兴只说做8个实例",所以这就是为什么我要多次运行.我有办法在暴发户脚本中使用开始于"子句来自动执行此操作吗?

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?

例如,启动实例1、2、3、4?然后让它们在关机时正确退出吗?

For example, start instance 1, 2, 3, 4? Then have them exit on shutdown properly?

我想我可以将其连接到init.d脚本中,但是我想知道新贵是否可以处理类似的事情,或者是否有人发现了这个问题.

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.

干杯!

推荐答案

您需要的是一个引导任务,该任务在启动时运行,并遍历您的所有工作者作业,并逐个开始.

What you need is a bootstrap task that runs on startup and iterates over all your worker jobs, starting each one.

#/etc/init/async-workers-all.conf

start on runlevel [2345]

task

env NUM_WORKERS=8

script
  for i in `seq 1 $NUM_WORKERS`
  do
    start async-worker N=$i
  done
end script

关键是使它成为 task ,它告诉新贵让任务运行到完成,然后再发出任何事件.请参见 http://upstart.ubuntu.com/cookbook/#task http://upstart.ubuntu.com/cookbook/#instance

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

这篇关于自动启动多个暴发户实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆