Python服务-Wix MSI安装程序-启动时自动启动不工作
我有一个工作的python win32服务,试图通过msi分发它,它是用WiX工具集构建的Python服务-Wix MSI安装程序-启动时自动启动不工作,python,wcf,service,wix,windows-installer,Python,Wcf,Service,Wix,Windows Installer,我有一个工作的python win32服务,试图通过msi分发它,它是用WiX工具集构建的 <File Id="MainEXE" Source="editservice.exe" KeyPath="yes"/> <ServiceControl Id="Edit" Name=Edit Service" Start="install" Stop="both" Remove="uninstall" Wait="yes"
<File Id="MainEXE" Source="editservice.exe" KeyPath="yes"/>
<ServiceControl Id="Edit" Name=Edit Service" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
<ServiceInstall
Id="service"
Account="\Ps"
Password="scrubed$"
Start="auto"
ErrorControl="normal"
Name="Edit Service"
Type="ownProcess"
Vital="yes" />
<RemoveFolder Id="Purge" On="uninstall" />
但是,该服务将以“启动类型自动”的方式安装,在安装时启动,使用sc
命令启动,并正常运行
<File Id="MainEXE" Source="editservice.exe" KeyPath="yes"/>
<ServiceControl Id="Edit" Name=Edit Service" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
<ServiceInstall
Id="service"
Account="\Ps"
Password="scrubed$"
Start="auto"
ErrorControl="normal"
Name="Edit Service"
Type="ownProcess"
Vital="yes" />
<RemoveFolder Id="Purge" On="uninstall" />
但是重新启动计算机时,它不会自动启动。它试图启动,但在事件查看器->Windows日志->系统中出现2个错误
<File Id="MainEXE" Source="editservice.exe" KeyPath="yes"/>
<ServiceControl Id="Edit" Name=Edit Service" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
<ServiceInstall
Id="service"
Account="\Ps"
Password="scrubed$"
Start="auto"
ErrorControl="normal"
Name="Edit Service"
Type="ownProcess"
Vital="yes" />
<RemoveFolder Id="Purge" On="uninstall" />
等待编辑服务连接时超时(30000毫秒)。
<File Id="MainEXE" Source="editservice.exe" KeyPath="yes"/>
<ServiceControl Id="Edit" Name=Edit Service" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
<ServiceInstall
Id="service"
Account="\Ps"
Password="scrubed$"
Start="auto"
ErrorControl="normal"
Name="Edit Service"
Type="ownProcess"
Vital="yes" />
<RemoveFolder Id="Purge" On="uninstall" />
由于以下错误,编辑服务无法启动:
服务未及时响应启动或控制请求。
<File Id="MainEXE" Source="editservice.exe" KeyPath="yes"/>
<ServiceControl Id="Edit" Name=Edit Service" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
<ServiceInstall
Id="service"
Account="\Ps"
Password="scrubed$"
Start="auto"
ErrorControl="normal"
Name="Edit Service"
Type="ownProcess"
Vital="yes" />
<RemoveFolder Id="Purge" On="uninstall" />
以下是参考serviceinstall的WiX部分
<File Id="MainEXE" Source="editservice.exe" KeyPath="yes"/>
<ServiceControl Id="Edit" Name=Edit Service" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
<ServiceInstall
Id="service"
Account="\Ps"
Password="scrubed$"
Start="auto"
ErrorControl="normal"
Name="Edit Service"
Type="ownProcess"
Vital="yes" />
<RemoveFolder Id="Purge" On="uninstall" />
<File Id="MainEXE" Source="editservice.exe" KeyPath="yes"/>
<ServiceControl Id="Edit" Name=Edit Service" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
<ServiceInstall
Id="service"
Account="\Ps"
Password="scrubed$"
Start="auto"
ErrorControl="normal"
Name="Edit Service"
Type="ownProcess"
Vital="yes" />
<RemoveFolder Id="Purge" On="uninstall" />
所以我想我明白了执行服务启动函数中的每一行
<File Id="MainEXE" Source="editservice.exe" KeyPath="yes"/>
<ServiceControl Id="Edit" Name=Edit Service" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
<ServiceInstall
Id="service"
Account="\Ps"
Password="scrubed$"
Start="auto"
ErrorControl="normal"
Name="Edit Service"
Type="ownProcess"
Vital="yes" />
<RemoveFolder Id="Purge" On="uninstall" />
然而最后一行代码是调用time.sleep(10)
。这行代码似乎没有完成运行,导致启动失败,即使服务正在运行
<File Id="MainEXE" Source="editservice.exe" KeyPath="yes"/>
<ServiceControl Id="Edit" Name=Edit Service" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
<ServiceInstall
Id="service"
Account="\Ps"
Password="scrubed$"
Start="auto"
ErrorControl="normal"
Name="Edit Service"
Type="ownProcess"
Vital="yes" />
<RemoveFolder Id="Purge" On="uninstall" />
在生产中,睡眠时间将提高到一小时。因此,我认为延迟启动是首选方法
<File Id="MainEXE" Source="editservice.exe" KeyPath="yes"/>
<ServiceControl Id="Edit" Name=Edit Service" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
<ServiceInstall
Id="service"
Account="\Ps"
Password="scrubed$"
Start="auto"
ErrorControl="normal"
Name="Edit Service"
Type="ownProcess"
Vital="yes" />
<RemoveFolder Id="Purge" On="uninstall" />
要在WiX中执行此操作,请遵循以下代码模板
<File Id="MainEXE" Source="editservice.exe" KeyPath="yes"/>
<ServiceControl Id="Edit" Name=Edit Service" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
<ServiceInstall
Id="service"
Account="\Ps"
Password="scrubed$"
Start="auto"
ErrorControl="normal"
Name="Edit Service"
Type="ownProcess"
Vital="yes" />
<RemoveFolder Id="Purge" On="uninstall" />
<ServiceControl Id="Edit" Name="NBC Edit Service" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
<ServiceInstall
Id="service"
Account="NYDPS\Portus"
Password="getyourownpassword"
Start="auto"
ErrorControl="normal"
Name="NBC Edit Service"
Type="ownProcess"
Vital="yes" >
<ServiceConfig DelayedAutoStart="yes" OnInstall="yes" OnReinstall ="yes" />
</ServiceInstall>
<RemoveFolder Id="Purge" On="uninstall" />
@tdelaney@PhilDW真正的答案
<File Id="MainEXE" Source="editservice.exe" KeyPath="yes"/>
<ServiceControl Id="Edit" Name=Edit Service" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
<ServiceInstall
Id="service"
Account="\Ps"
Password="scrubed$"
Start="auto"
ErrorControl="normal"
Name="Edit Service"
Type="ownProcess"
Vital="yes" />
<RemoveFolder Id="Purge" On="uninstall" />
FWIW—在python服务中使用time.sleep()
,就是进入一个无限循环,这需要处理器时间。在一个无限循环中接收单音是不可能的。有一种windows服务实现方法来完成睡眠
<File Id="MainEXE" Source="editservice.exe" KeyPath="yes"/>
<ServiceControl Id="Edit" Name=Edit Service" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
<ServiceInstall
Id="service"
Account="\Ps"
Password="scrubed$"
Start="auto"
ErrorControl="normal"
Name="Edit Service"
Type="ownProcess"
Vital="yes" />
<RemoveFolder Id="Purge" On="uninstall" />
而不是
<File Id="MainEXE" Source="editservice.exe" KeyPath="yes"/>
<ServiceControl Id="Edit" Name=Edit Service" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
<ServiceInstall
Id="service"
Account="\Ps"
Password="scrubed$"
Start="auto"
ErrorControl="normal"
Name="Edit Service"
Type="ownProcess"
Vital="yes" />
<RemoveFolder Id="Purge" On="uninstall" />
睡眠时间(10)
<File Id="MainEXE" Source="editservice.exe" KeyPath="yes"/>
<ServiceControl Id="Edit" Name=Edit Service" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
<ServiceInstall
Id="service"
Account="\Ps"
Password="scrubed$"
Start="auto"
ErrorControl="normal"
Name="Edit Service"
Type="ownProcess"
Vital="yes" />
<RemoveFolder Id="Purge" On="uninstall" />
使用
<File Id="MainEXE" Source="editservice.exe" KeyPath="yes"/>
<ServiceControl Id="Edit" Name=Edit Service" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
<ServiceInstall
Id="service"
Account="\Ps"
Password="scrubed$"
Start="auto"
ErrorControl="normal"
Name="Edit Service"
Type="ownProcess"
Vital="yes" />
<RemoveFolder Id="Purge" On="uninstall" />
#其中超时=睡眠时间
<File Id="MainEXE" Source="editservice.exe" KeyPath="yes"/>
<ServiceControl Id="Edit" Name=Edit Service" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
<ServiceInstall
Id="service"
Account="\Ps"
Password="scrubed$"
Start="auto"
ErrorControl="normal"
Name="Edit Service"
Type="ownProcess"
Vital="yes" />
<RemoveFolder Id="Purge" On="uninstall" />
如果win32event.WaitForSingleObject(self.hWaitStop,超时)=win32event.WAIT\u OBJECT\u 0:
中断
<File Id="MainEXE" Source="editservice.exe" KeyPath="yes"/>
<ServiceControl Id="Edit" Name=Edit Service" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
<ServiceInstall
Id="service"
Account="\Ps"
Password="scrubed$"
Start="auto"
ErrorControl="normal"
Name="Edit Service"
Type="ownProcess"
Vital="yes" />
<RemoveFolder Id="Purge" On="uninstall" />
注意-sleep.time输入以秒为单位,win32event.WaitForSingleObject
以毫秒为单位它是否依赖于另一个尚未启动的服务?顺便说一句,你可能想擦洗的例子中的密码…谢谢,我擦洗了它,并重写了一份副本和粘贴。。。哦。。没有依赖性,我想我在引导期间遇到了“自动”问题,如果网络尚未加载,NYDPS域可能无法正确访问,我正在使用延迟StartWever进行测试,这是从一些早期更改的回归,这让我很困惑,为什么auto
以前可以工作,而现在只有延期
可以工作。。我经历了一次脱钩练习,我的服务现在导入了多个定制模块,而不是没有。我使用py2exe将其捆绑起来,但它应该与1个文件“服务没有及时响应启动或控制请求”没有任何区别。显而易见,这不是安装问题。服务启动逻辑缓慢或失败,花费的时间太长。调试服务,而不是安装@PhilDW同意,但如果我手动启动服务,它会很好地工作,它会在一秒钟内启动,我假设这是我分发它的方式。。。在我看来,如果服务在启动时启动失败,那么如果服务中出现问题,它应该在其他地方启动失败
<File Id="MainEXE" Source="editservice.exe" KeyPath="yes"/>
<ServiceControl Id="Edit" Name=Edit Service" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
<ServiceInstall
Id="service"
Account="\Ps"
Password="scrubed$"
Start="auto"
ErrorControl="normal"
Name="Edit Service"
Type="ownProcess"
Vital="yes" />
<RemoveFolder Id="Purge" On="uninstall" />