Simplest CherryPy "Run as Daemon" example?

1,752 views
Skip to first unread message

Damir Prebeg

unread,
Apr 13, 2015, 5:41:24 AM4/13/15
to cherryp...@googlegroups.com
Hi every one.

I have virtualenv in /var/www/ and under html/ subfolder (that is /var/www/html/) I have index.py.

Here's it's source:

#!/var/www/bin/python

import cherrypy

class Root(object):
   
@cherrypy.expose
   
def index(self):
       
        main_page
= """
            <html>
                <head>
                </head>
                <body>
                    This is %s
                </body>
            </html>
            """
%('CherryPy')

       
return main_page

if __name__ == '__main__':
    cherrypy
.quickstart(Root(), '/')

I know that If I run "python index.py" I can open http://127.0.0.1:8000 and I'll get "This is CherryPy" in my browser.

But how to start cherrypy server as a daemon and serve that index.py file? I have found saaj webapp example and I simply can't figure out how to start cherrypy as a daemon and serve specific file...

Please help.

Sylvain Hellegouarch

unread,
Apr 13, 2015, 5:47:56 AM4/13/15
to cherryp...@googlegroups.com
Hi Damir,

One way is to let CherryPy do this for you through this builtin plugin


if __name__ == '__main__':
  from cherrypy.process.plugins import Daemonizer
  d = Daemonizer(cherrypy.engine)
  d.subscribe()
    cherrypy.quickstart(Root(), '/')
 
-- 

Damir Prebeg

unread,
Apr 13, 2015, 8:19:34 AM4/13/15
to cherryp...@googlegroups.com
Hi Sylvain,

Thanks for your answer, I've seen that example in CherryPy documentation and tried but I was thinking more of use of cherryd script.
In CherryPy docs (http://docs.cherrypy.org/en/latest/install.html?highlight=cherryd#cherryd) I don't see how one tells to that script what to serve.

I would like to create init.d script (let say cherry-server) that launches cherrypy server and serves my /var/www/html/index.py. So I can do
sudo service cherry-server start|stop|restart...

Michiel Overtoom

unread,
Apr 13, 2015, 9:16:39 AM4/13/15
to cherryp...@googlegroups.com

On Apr 13, 2015, at 11:40, Damir Prebeg wrote:

> But how to start cherrypy server as a daemon

I use supervisord to do that:

[program:webapp]
command=/usr/local/bin/python /home/motoom/mywebapp.py
directory=/home/motoom
environment=PATH="%(ENV_PATH)s:/usr/local/bin"
user=motoom
autostart=true
autorestart=true
stdout_logfile=NONE
stderr_logfile=NONE

--
"You can't actually make computers run faster, you can only make them do less." - RiderOfGiraffes

Reply all
Reply to author
Forward
0 new messages