跳转到主要内容

ZC Buildout配方,用于组织启动脚本。

项目描述

代码仓库: http://svn.plone.org/svn/collective/buildout/plone.recipe.cluster/

变更历史

trunk (2008-08-11)

  • xxx [Ingeniweb]

0.1.0 (未发布)

  • Linux守护进程的初始实现。 [tarek]

  • 使用ZopeSkel创建配方。 [tarek]

详细文档

支持选项

该配方支持以下选项

debug

默认选项是0。当设置为1时,允许在非阻塞守护进程中运行测试。

start

多行选项。每行是守护进程在启动时调用的命令行。命令必须立即返回,因为守护进程在启动下一个命令之前会等待它。

但是,可以使用带有background:前缀的命令行将其推送到后台。

stop

多行选项。每行是守护进程在停止时调用的命令行。命令必须立即返回,因为守护进程在启动下一个命令之前会等待它。

可以通过提供带 PID 的 pid:value 命令行来请求守护进程终止指定的进程。其中 value 是 PID 号码,或者是一个包含 PID 的文本文件。

还提供了 background: 前缀。

重启

多行选项。每一行都是一个命令行,当守护进程使用 restart 选项时将被调用。这些命令必须立即返回,因为守护进程在启动下一个命令之前会等待它。

可以通过提供带 PID 的 pid:value 命令行来请求守护进程终止指定的进程。其中 value 是 PID 号码,或者是一个包含 PID 的文本文件。

还提供了 background: 前缀。

pid-file

定义了守护进程 PID 文件的路径。

示例用法

cluster 配方允许您为 buildout 创建复合命令。有三个命令

  • start

  • stop

  • 重启

每个命令都是一个包含要运行命令列表的变量。然后配方启动:- 基于 Linux 的系统下的守护进程 - Windows 下的 NT 服务

例如,一个典型的用法是启动 zeo、zope 和 pound

[buildout]

...

[cluster]
recipe = plone.recipe.cluster

poundctl = ${buildout:bin-directory}/pound -f ${buildout:directory}/parts/pound/etc/pound.cfg -c ${buildout:directory}/pound.pid


start =
    ${buildout:bin-directory}/zeoserver start
    ${buildout:bin-directory}/instance start
    ${cluster:poundctl}

stop =
    ${buildout:bin-directory}/zeoserver stop
    ${buildout:bin-directory}/instance stop
    pid:${buildout:directory}/pound.pid

restart =
    ${buildout:bin-directory}/zeoserver restart
    ${buildout:bin-directory}/instance restart
    ${cluster:poundctl}

让我们试试这个

>>> write('buildout.cfg',
... """
... [buildout]
... parts = cluster
... index = http://pypi.python.org/simple
... [cluster]
... recipe = plone.recipe.cluster
... debug = 1
... start =
...    background:${buildout:bin-directory}/script1
...    ${buildout:bin-directory}/script2 start
...
... stop =
...    ${buildout:bin-directory}/script2 stop
...
... restart =
...    background:${buildout:bin-directory}/script1
...    ${buildout:bin-directory}/script2 restart
...
... """)

运行 buildout 给我们

>>> print system(buildout)
Getting distribution for 'zc.recipe.egg'.
Got zc.recipe.egg 1.0.0.
Installing cluster.
Generated script '/.../bin/cluster'.
<BLANKLINE>

现在让我们看看创建的脚本

>>> script = join(sample_buildout, 'bin', 'cluster')
>>> print open(script).read()
#!...python
<BLANKLINE>
import sys
sys.path[0:0] = [
  ...
  ]
<BLANKLINE>
import plone.recipe.cluster.ctl
<BLANKLINE>
if __name__ == '__main__':
    plone.recipe.cluster.ctl.main(...)
<BLANKLINE>

让我们创建假的脚本

>>> script2 = join(sample_buildout, 'bin', 'script2')
>>> f = open(script2, 'w')
>>> f.write('echo script 2')
>>> f.close()
>>> import os
>>> os.chmod(script2, 0770)

>>> script1 = join(sample_buildout, 'bin', 'script1')
>>> f = open(script1, 'w')
>>> import sys
>>> f.write("""\
... #!%s
... import time
... while 1:
...     time.sleep(0.1)
... """ % sys.executable)
>>> f.close()
>>> os.chmod(script1, 0770)

让我们尝试执行它

>>> print system(script)
usage: /sample-buildout/bin/cluster start|stop|restart|status
<BLANKLINE>

让我们请求状态

>>> print system('%s status' % script)
Not running.

啊,让我们启动它!

>>> print system('%s start' % script)
Cluster is starting...
Running in background ...script1
Background pid is ...
Background subpid is ...
Running ...script2 start
script 2
Child PIDs: ..., ...
Started with pid ...
Cluster is alive...
<BLANKLINE>

让我们请求状态

>>> print system('%s status' % script)
Running.

我们不应该能够启动两次

>>> print system('%s start' % script)
<BLANKLINE>
Start aborded since pid file '...' exists.
<BLANKLINE>

让我们停止它

>>> print system('%s stop' % script)
<BLANKLINE>
Cluster is going down...
<BLANKLINE>

让我们重启它

>>> print system('%s restart' % script)
Could not stop, pid file 'cluster.pid' missing.
<BLANKLINE>

哦,它已经停止了!

贡献者

Tarek Ziade,作者

下载

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源代码分发

plone.recipe.cluster-0.1.0.tar.gz (22.0 kB 查看哈希值)

源代码

构建分发

plone.recipe.cluster-0.1.0-py2.4.egg (40.1 kB 查看哈希值)

源代码

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面