Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 部署CherryPy(守护进程)_Python_Deployment_Cherrypy - Fatal编程技术网

Python 部署CherryPy(守护进程)

Python 部署CherryPy(守护进程),python,deployment,cherrypy,Python,Deployment,Cherrypy,我遵循了基本的CherryPy教程()。有一件事没有讨论,那就是部署 如何启动CherryPy应用程序作为守护进程并“忘记它”?如果服务器重新启动会发生什么 有标准配方吗?可能会创建一个服务脚本(/etc/init.d/cherrypy…) 谢谢 默认情况下包含一个CherryPy插件,该插件有助于启动CherryPy,但到目前为止,最简单的方法是使用cherryd脚本: > cherryd -h Usage: cherryd [options] Options: -h, --hel

我遵循了基本的CherryPy教程()。有一件事没有讨论,那就是部署

如何启动CherryPy应用程序作为守护进程并“忘记它”?如果服务器重新启动会发生什么

有标准配方吗?可能会创建一个服务脚本(/etc/init.d/cherrypy…)

谢谢

默认情况下包含一个CherryPy插件,该插件有助于启动CherryPy,但到目前为止,最简单的方法是使用cherryd脚本:

> 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/site-packages/cherrypy/cherryd


或者在:

守护进程可以非常简单地使用:

# 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()

总结如下:

  • /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

  • #!/bin/sh  
    echo "Invoking MyDaemonApp";  
    /path/to/MyDaemonApp  
    echo "Started MyDaemonApp. Tremble, Ye Mighty."  
    
  • 运行
    updaterc.d
    在适当的运行时目录中创建适当的链接

    sudo update rc.d MyDaemonApp默认值80

  • sudo/etc/init.d/MyDaemonApp

  • #!/bin/sh  
    echo "Invoking MyDaemonApp";  
    /path/to/MyDaemonApp  
    echo "Started MyDaemonApp. Tremble, Ye Mighty."  
    

    我编写了一个教程/项目框架,其目标是填补在Debian*上为web开发人员部署真实世界CherryPy应用程序的空白。它具有扩展的cherryd,用于守护进程权限删除。还有许多重要的脚本和配置文件用于
    init.d
    nginx
    monit
    logrotate
    。教程部分描述了如何把事情放在一起,最终忘记它。框架部分提出了CherryPy webapp项目资产的可能安排方式



    *它是为挤压而写的,但实际上对于喘息应该是一样的。

    关于Daemonizer选项的信息

    使用Daemonizer时,不会说明选项,例如如何重定向stdout或stderr。从类的源代码中可以找到选项。作为参考,请从我的项目中选取以下示例:

    # 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()
    

    我不知道spizouzou是什么,但是这个变量完全没有必要。只需简单地说:
    Daemonizer(cherrypy.engine).subscribe()
    ,插件就会持久存在,因为
    engine
    现在保留了对它的引用。@brandon craig rhodes是正确的。无需创建变量。正如其他地方提到的,可以用大约相同的工作量创建windows服务。注意页面底部的日志位!它们很重要。更改为反映@BrandonRhodes评论。本教程中的代码非常有用,谢谢