Python 服务 - Wix MSI 安装程序 - 开机自动启动不工作
Python Service - Wix MSI Installer - Auto Start on bootup not working
我有一个可用的 python win32 服务,试图通过使用 WiX 工具集构建的 msi 分发它。
但是,该服务作为 "Startup Type Automatic" 安装,在安装时启动,使用 sc
命令启动,并且运行正常。
但是重新启动计算机时,它不会自动启动。它尝试启动,但我在事件查看器 -> Windows 日志 -> 系统
中收到 2 个错误
A timeout was reached (30000 milliseconds) while waiting for the Edit Service service to connect.
The Edit Service service failed to start due to the following error:
The service did not respond to the start or control request in a timely fashion.
这是引用服务安装的 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" />
知道为什么只有在系统启动时才会启动失败吗?如果需要,我可以提供进一步的 WiX 或 python 服务实现
所以我想我明白了..服务启动函数中的每一行都会被执行。
However - 最后一行代码是对 time.sleep(10)
的调用。这行代码似乎没有完成 运行,导致启动失败 ,即使服务是 运行。
在生产中,睡眠时间将增加到一个小时。因此,我认为 延迟启动 是首选方法。
为了在 WiX 中执行此操作,请遵循以下代码模板。
<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 真正的答案..
FWIW - 在 python 服务中使用 time.sleep()
会进入一个占用处理器时间的无限循环。在无限循环中接收单曲是不可能的。有一个 windows 服务实现 方法来完成睡眠
而不是
sleep.time(10)
使用
#where timeout = sleep time
if win32event.WaitForSingleObject(self.hWaitStop, timeout) == win32event.WAIT_OBJECT_0:
break
注意 - sleep.time 输入以秒为单位,win32event.WaitForSingleObject
以毫秒为单位
我有一个可用的 python win32 服务,试图通过使用 WiX 工具集构建的 msi 分发它。
但是,该服务作为 "Startup Type Automatic" 安装,在安装时启动,使用 sc
命令启动,并且运行正常。
但是重新启动计算机时,它不会自动启动。它尝试启动,但我在事件查看器 -> Windows 日志 -> 系统
中收到 2 个错误A timeout was reached (30000 milliseconds) while waiting for the Edit Service service to connect.
The Edit Service service failed to start due to the following error:
The service did not respond to the start or control request in a timely fashion.
这是引用服务安装的 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" />
知道为什么只有在系统启动时才会启动失败吗?如果需要,我可以提供进一步的 WiX 或 python 服务实现
所以我想我明白了..服务启动函数中的每一行都会被执行。
However - 最后一行代码是对 time.sleep(10)
的调用。这行代码似乎没有完成 运行,导致启动失败 ,即使服务是 运行。
在生产中,睡眠时间将增加到一个小时。因此,我认为 延迟启动 是首选方法。
为了在 WiX 中执行此操作,请遵循以下代码模板。
<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 真正的答案..
FWIW - 在 python 服务中使用 time.sleep()
会进入一个占用处理器时间的无限循环。在无限循环中接收单曲是不可能的。有一个 windows 服务实现 方法来完成睡眠
而不是
sleep.time(10)
使用
#where timeout = sleep time
if win32event.WaitForSingleObject(self.hWaitStop, timeout) == win32event.WAIT_OBJECT_0:
break
注意 - sleep.time 输入以秒为单位,win32event.WaitForSingleObject
以毫秒为单位