用于组织启动脚本的zc构建方法。
plone.recipe.cluster的Python项目详细描述
内容
代码库:http://svn.plone.org/svn/collective/buildout/plone.recipe.cluster/
Change history
trunk (2008-08-11)
- xxx [Ingeniweb]
0.1.0 (unreleased)
- Initial implementation of Linux daemon. [tarek]
- Created recipe with ZopeSkel. [tarek]
Detailed Documentation
Supported options
配方支持以下选项:
- 调试
- 默认选项为0。当设置为1时,允许运行测试 在非阻塞守护进程上。
- 开始
多行选项。每一行都是一个命令行 当使用start选项调用它时由守护进程调用。 命令必须立即返回,因为守护进程等待 在它启动下一个命令之前。
但是,可以在后台推送命令行 使用背景:前缀。
- 停止
多行选项。每一行都是一个命令行 当使用stop选项调用守护进程时调用它。 命令必须立即返回,因为守护进程等待 在它启动下一个命令之前。
可以要求守护进程通过 提供pid:value命令行。其中,值是 一个PID号,或者是包含PID的文本文件。
背景:前缀也可用。
- 重新启动
多行选项。每一行都是一个命令行 使用restart选项调用时由守护进程调用。 命令必须立即返回,因为守护进程等待 在它启动下一个命令之前。
可以要求守护进程通过 提供pid:value命令行。其中,值是 一个PID号,或者是包含PID的文本文件。
背景:前缀也可用。
- PID文件
- 定义守护进程的pid文件的路径。
Example usage
集群配方允许您为 建造。有三个命令:
- 开始
- 停止
- 重新启动
每个命令都是一个变量,其中包含 快跑。然后配方启动: -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 ... ... """)
运行构建会给我们带来:
>>> 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>
哦,对了,停下来了!
Contributors
Tarek Ziade,作者