Deploying CherryPy (daemon)

后端 未结 4 2137
傲寒
傲寒 2020-12-08 15:04

I\'ve followed the basic CherryPy tutorial (http://www.cherrypy.org/wiki/CherryPyTutorial). One thing not discussed is deployment.

How can I launch a CherryPy app a

相关标签:
4条回答
  • 2020-12-08 15:26

    Daemonizer can be pretty simple to use:

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

    There is a decent HOWTO for SysV style here.

    To summarize:

    1. Create a file named for your application in /etc/init.d that calls /bin/sh

      sudo vim /etc/init.d/MyDaemonApp

      #!/bin/sh  
      echo "Invoking MyDaemonApp";  
      /path/to/MyDaemonApp  
      echo "Started MyDaemonApp. Tremble, Ye Mighty."  
      
    2. Make it executable

      sudo chmod +x /etc/init.d/MyDaemonApp

    3. Run update-rc.d to create our proper links in the proper runtime dir.

      sudo update-rc.d MyDaemonApp defaults 80

    4. sudo /etc/init.d/MyDaemonApp

    0 讨论(0)
  • 2020-12-08 15:32

    Info on Daemonizer options

    When using Daemonizer, the docs don't state the options, e.g. how to redirect stdout or stderr. From the source of the Daemonizer class you can find the options. As a reference take this example from my project:

    # 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()
    
    0 讨论(0)
  • 2020-12-08 15:42

    There is a Daemonizer plugin for CherryPy included by default which is useful for getting it to start but by far the easiest way for simple cases is to use the cherryd script:

    > 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
    

    As far as an init.d script goes I think there are examples that can be Googled.

    And the cherryd is found in your:

    virtualenv/lib/python2.7/site-packages/cherrypy/cherryd

    or in: https://bitbucket.org/cherrypy/cherrypy/src/default/cherrypy/cherryd

    0 讨论(0)
  • 2020-12-08 15:44

    I wrote a tutorial/project skeleton, cherrypy-webapp-skeleton, which goal was to fill the gaps for deploying a real-world CherryPy application on Debian* for a web-developer. It features extended cherryd for daemon privilege drop. There's also a number of important script and config files for init.d, nginx, monit, logrotate. The tutorial part describes how to put things together and eventually forget about it. The skeleton part proposes a way of possible arrangement of CherryPy webapp project assets.


    * It was written for Squeeze but practically it should be same for Wheezy.

    0 讨论(0)
提交回复
热议问题