title: Cherrypy Daemon shutdown fails
body: <p>I've followed the Cherrypy daemon webapp skeleton <a href="https://stackoverflow.com/questions/1463510/deploying-cherrypy-daemon">Deploying CherryPy (daemon)</a> which is great. But I've got a shutdown problem.</p>
  
  <p>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</p>
  
  <pre><code>[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 &lt;bound method Server.start of &lt;cherrypy._cpserver.Server object at 0xe60e10&gt;&gt;
  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# 
  </code></pre>
  
  <p>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 &amp; shouldn't be free) and therefore failing.</p>
  
  <p>This leaves the service running - not what's wanted..</p>
  
  <p>BTW my config that sets the port to 8082 is inside the module I load - rather than in a config file.</p>
  
  <p>Thanks for any pointers in anticipation.</p>