Cherrypy守护程序关闭失败

时间:2014-07-11 09:52:46

标签: daemon cherrypy shutdown

我已经关注了Cherrypy守护程序webapp骨架Deploying CherryPy (daemon),这很棒。但是我遇到了关机问题。

有问题的服务器正在使用端口8082.当关闭来自init.d脚本时,它会点击webapp-cherryd等效项,然后抛出错误。 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# 

到目前为止,我已经完成了冲浪,我相信该服务正在尝试重新启动以响应SIGHUP信号并且它正在接收默认端口8080(这不是&amp;不应该是免费)因此失败。

这使服务运行 - 而不是想要的......

BTW我的配置将端口设置为8082是在我加载的模块内 - 而不是在配置文件中。

感谢您的期待。

2 个答案:

答案 0 :(得分:0)

由于日志明确指出CherryPy正在尝试从127.0.0.1:8080开始并在5秒后失败。所以你实际上有一个启动失败,可能是因为在我的配置中将端口设置为8082是在我加载的模块内 - 而不是在配置文件中你没有正确设置端口而CherryPy使用默认的8080。

另外,我想请注意,您不应在生产中使用Autoreloadercherrypy-webapp-skeleton init.d脚本设置production CherryPy environmentAutoreloader关闭。

答案 1 :(得分:0)

所以当你这样做时

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

默认情况下,您在localhost:8080上创建一个服务器实例,但在调用cherrypy.engine.start()之前它实际上并没有启动。

你可能正在做这样的事情

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

将导致cherry py启动两个服务器实例,一个在localhost:8080,另一个在5002。

答案是:

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

上面的问题是你正在盯着两台服务器,其中只有一台正在崩溃/错误/关闭,所以端口8080仍然绑定到本地主机并阻止重启..