我遵循的基本CherryPy的教程( http://www.cherrypy.org/wiki/CherryPyTutorial )。 没有讨论的一件事是部署。
我怎样才能启动CherryPy的应用程序作为一个守护进程和“忘记它”? 如果重启服务器时,会发生什么?
有没有一个标准配方? 也许东西,将创建服务脚本(/etc/init.d/cherrypy ...)
谢谢!
我遵循的基本CherryPy的教程( http://www.cherrypy.org/wiki/CherryPyTutorial )。 没有讨论的一件事是部署。
我怎样才能启动CherryPy的应用程序作为一个守护进程和“忘记它”? 如果重启服务器时,会发生什么?
有没有一个标准配方? 也许东西,将创建服务脚本(/etc/init.d/cherrypy ...)
谢谢!
有一个Daemonizer默认情况下这是得到它的开始,但迄今为止简单的情况下,最简单的方法是使用脚本cherryd有用包括插件的CherryPy:
> cherryd -h
Usage: cherryd [options]
Options:
-h, --help show this help message and exit
-c CONFIG, --config=CONFIG
specify config file(s)
-d run the server as a daemon
-e ENVIRONMENT, --environment=ENVIRONMENT
apply the given config environment
-f start a fastcgi server instead of the default HTTP
server
-s start a scgi server instead of the default HTTP server
-i IMPORTS, --import=IMPORTS
specify modules to import
-p PIDFILE, --pidfile=PIDFILE
store the process id in the given file
至于一个脚本init.d中去,我认为有一些可以用谷歌搜索的例子。
而cherryd
在你发现:
的virtualenv / lib目录/ python2.7 /站点包/ CherryPy的/ cherryd
或: https://bitbucket.org/cherrypy/cherrypy/src/default/cherrypy/cherryd
Daemonizer可以很简单的使用方法:
# this works for cherrypy 3.1.2 on Ubuntu 10.04
from cherrypy.process.plugins import Daemonizer
# before mounting anything
Daemonizer(cherrypy.engine).subscribe()
cherrypy.tree.mount(MyDaemonApp, "/")
cherrypy.engine.start()
cherrypy.engine.block()
还有这里的SysV风格像样的HOWTO。
总结:
创建一个名为您的应用程序文件/etc/init.d
调用/bin/sh
sudo vim /etc/init.d/MyDaemonApp
#!/bin/sh echo "Invoking MyDaemonApp"; /path/to/MyDaemonApp echo "Started MyDaemonApp. Tremble, Ye Mighty."
使其可执行
sudo chmod +x /etc/init.d/MyDaemonApp
运行update-rc.d
创建我们在适当的运行目录正确的链接。
sudo update-rc.d MyDaemonApp defaults 80
sudo /etc/init.d/MyDaemonApp
我写了一个教程/项目骨架, CherryPy的-webapp的骨架 ,它的目标是填补国内空白,为网络开发者部署在Debian *现实世界的CherryPy应用。 它具有扩展cherryd
进行守护特权下降。 还有一些重要的脚本和配置文件init.d
, nginx
, monit
, logrotate
。 本教程主要介绍如何把东西放在一起,最终忘掉它 。 框架部分提出CherryPy的webapp项目资产的可能安排的说法。
*它为挤压写,但实际上它应该是相同的喘息。
在Daemonizer选项信息
当使用Daemonizer,该文档没有说明的选项,例如,如何将stdout或标准错误 。 从源Daemonizer类,你可以找到的选项。 作为参考从我的项目这个例子:
# run server as a daemon
d = Daemonizer(cherrypy.engine,
stdout='/home/pi/Gate/log/gate_access.log',
stderr='/home/pi/Gate/log/gate_error.log')
d.subscribe()