0

I've followed the Cherrypy daemon webapp skeleton Deploying CherryPy (daemon) which is great. But I've got a shutdown problem.

The server in question is using port 8082. When the shutdown comes from the init.d script it hits the webapp-cherryd equivalent and then throws errors. XXX@mgmtdebian7:/etc/init.d# ./XXX stop

[11/Jul/2014:09:39:25] ENGINE Listening for SIGHUP.
[11/Jul/2014:09:39:25] ENGINE Listening for SIGTERM.
[11/Jul/2014:09:39:25] ENGINE Listening for SIGUSR1.
[11/Jul/2014:09:39:25] ENGINE Bus STARTING
[11/Jul/2014:09:39:25] ENGINE Started monitor thread 'Autoreloader'.
[11/Jul/2014:09:39:25] ENGINE Started monitor thread '_TimeoutMonitor'.
[11/Jul/2014:09:39:30] ENGINE Error in 'start' listener <bound method Server.start of <cherrypy._cpserver.Server object at 0xe60e10>>
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.4-py2.7.egg/cherrypy/process/wspbus.py", line 197, in publish
    output.append(listener(*args, **kwargs))
  File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.4-py2.7.egg/cherrypy/_cpserver.py", line 151, in start
    ServerAdapter.start(self)
  File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.4-py2.7.egg/cherrypy/process/servers.py", line 168, in start
    wait_for_free_port(*self.bind_addr)
  File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.4-py2.7.egg/cherrypy/process/servers.py", line 412, in wait_for_free_port
    raise IOError("Port %r not free on %r" % (port, host))
IOError: Port 8080 not free on '127.0.0.1'

[11/Jul/2014:09:39:30] ENGINE Shutting down due to error in start listener:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.4-py2.7.egg/cherrypy/process/wspbus.py", line 235, in start
    self.publish('start')
  File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.4-py2.7.egg/cherrypy/process/wspbus.py", line 215, in publish
    raise exc
ChannelFailures: IOError("Port 8080 not free on '127.0.0.1'",)

[11/Jul/2014:09:39:30] ENGINE Bus STOPPING
[11/Jul/2014:09:39:30] ENGINE HTTP Server cherrypy._cpwsgi_server.CPWSGIServer(('127.0.0.1', 8080)) already shut down
[11/Jul/2014:09:39:30] ENGINE Stopped thread '_TimeoutMonitor'.
[11/Jul/2014:09:39:30] ENGINE Stopped thread 'Autoreloader'.
[11/Jul/2014:09:39:30] ENGINE Bus STOPPED
[11/Jul/2014:09:39:30] ENGINE Bus EXITING
[11/Jul/2014:09:39:30] ENGINE Bus EXITED
XXX@mgmtdebian7:/etc/init.d# 

From the surfing I've done thus far I've believe that the service is trying to restart in response to the SIGHUP signal and that it's picking up a default port of 8080 (which isn't & shouldn't be free) and therefore failing.

This leaves the service running - not what's wanted..

BTW my config that sets the port to 8082 is inside the module I load - rather than in a config file.

Thanks for any pointers in anticipation.

Community
  • 1
  • 1
VernonR
  • 43
  • 1
  • 4

2 Answers2

0

As the log clearly states CherryPy is attempting to start on 127.0.0.1:8080 and fails after 5 seconds. So you actually have a start up fail and likely it is because in my config that sets the port to 8082 is inside the module I load - rather than in a config file you don't set the port correctly and CherryPy uses default 8080.

Also I'd like to note that you shouldn't use Autoreloader in production. The cherrypy-webapp-skeleton init.d script sets production CherryPy environment which has Autoreloader off.

saaj
  • 23,253
  • 3
  • 104
  • 105
  • Thanks. Got it working by changing the approach to follow the skeleton a bit more closely. One learning point for me is that there are intricacies inside the cherrypy-webapp-skeleton that are worth not digging into. So fastest place to start with a new project is with the skeleton - and perhaps just cut out all of the application to give a "hello world".. – VernonR Jul 21 '14 at 10:54
  • @VernonR Good that it works. Complete deployment isn't a very simple thing per se, so it may need time for good understanding of all the aspects and you may return to the skeleton several times later. Just take what you need at the moment. Also it was made for a qooxdoo single-page web application, so if you do other kind of frontend, some shrinking is required. – saaj Jul 21 '14 at 13:08
0

So when you do

cherrypy.tree.graph(app, "/") 

you are by default creating a server instance on localhost:8080, but it doesnt actually get started until you call cherrypy.engine.start().

You are probably doing something like this

E.g. :

    cherrypy.tree.graft(app, "/") # registers a server on localhost:8080

    server = cherrypy._cpserver.Server() # registers a second server...
    server.socket_host="0.0.0.0" # ..on 0.0.0.0 ...
    server.socket_port = 5002 # ..with port 5002
    server.thread_pool = 10
    server.subscribe()

    cherrypy.engine.start() #starts two server instances
    cherrypy.engine.block()

will cause cherry py to start two server instances, one on localhost:8080, and another on 5002.

The answer is to instead do:

    cherrypy.tree.graft(app, "/")
    cherrypy.server.unsubscribe() # very important gets rid of default.

    server = cherrypy._cpserver.Server()
    server.socket_host="0.0.0.0"
    server.socket_port = 5002
    server.thread_pool = 10
    server.subscribe()

    cherrypy.engine.start() #now starts only one server instance
    cherrypy.engine.block()

Your problem above is that you are staring two servers, and only one of them is falling over/erroring/closing, so port 8080 is still bound to local host and prevents a restart..

phil_20686
  • 4,000
  • 21
  • 38