2011-05-19 88 views
0

我试图安装并启动一个简单的CherryPy服务器作为Windows服务。安装并启动CherryPy服务器脚本作为Windows服务(使用sc.exe)

下面是脚本:(去掉了一些线剪短通过命令行手动执行时,它的完全工作)

app = AdminMediaHandler(django.core.handlers.wsgi.WSGIHandler()) 
logged_app = TransLogger(app) 
server = wsgiserver.CherryPyWSGIServer(('127.0.0.1', 8632), logged_app, server_name='localhost', numthreads=20) 

try: 
    server.start() 
except KeyboardInterrupt: 
    server.stop() 

我使用sc.exe安装和启动服务。安装顺利,但我似乎无法启动服务。

使用的命令是:(注意有是在路径空间,虽然我HANDELING这个用双引号,和binPath通过命令行手动执行其字符串时,工作)

> sc.exe create "ServiceName" binPath= "\"C:\Path to Python\python.exe\" \"C:\Path to CherryPy Script\cherryserver.py\"" 

> sc.exe start "ServiceName" 

我不断收到此错误,不管试图开始使用sc.exe或通过services.msc GUI服务:

[SC] StartService FAILED 1053: 

The service did not respond to the start or control request in a timely fashion. 

据我了解,这是因为happenning python.exe不IMPL提供Windows服务API。

我不想从脚本创建.exe,使用py2exe

我发现this answer该建议安装使用不同的工具的服务比sc.exe,称为srvany.exe & instsrv.exe。但是,我无法在Win2K Resource Kit website中找到它们。

是否有人知道如何安装&作为Windows成功启动此.py

有谁知道

回答

0

我最终使用的ServiceInstaller又名SMaster,作为stated in this answer。给定答案中的网址已损坏,并且找不到工作网址。我刚刚在本地提供srunner.exe

注有另一个障碍,虽然克服,如的ServiceInstaller不能空间在其路径处理文件。

因此,我使用旧的DOS路径格式进行服务注册。

取代登记C:\Program Files\MyApp\python.exe,我注册了C:\PROGRA~1\MyApp\python.exe

1

我更喜欢nssm将普通脚本作为服务安装。 根据您的系统,您可以将nssm.exe复制到C:\ Windows \ system32或C:\ Windows \ SysWOW64目录中的目录中。之后,你可以安装一个服务如下:

nssm install yourservicename 

对于您必须将应用程序路径设置为您python.exe Python脚本和参数是脚本的自我。

Basic configuration for nssm

其他常见的命令来启动/停止/编辑你的服务有:

nssm start yourservicename 
nssm stop yourservicename 
nssm edit yourservicename