簡體   English   中英

Python服務-Wix MSI安裝程序-啟動時自動啟動無法正常工作

[英]Python Service - Wix MSI Installer - Auto Start on bootup not working

我有一個工作正常的python win32服務,試圖通過WiX Toolset構建的msi進行分發。

但是,該服務將以“自動啟動類型”安裝,在安裝時啟動,以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.

這是引用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" />

有什么想法為什么只能在系統啟動時才能啟動? 如果需要,我可以提供進一步的WiX或python服務實現

所以我想我已經解決了..服務啟動功能中的每一行都被執行了。

但是 -代碼的最后一行是對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以毫秒為單位

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM