8

我想從我們的運行團隊城市的構建服務器將windows服務部署到windows server 2012,並使用最少的服務器配置。從團隊城市部署Windows服務

什麼是最好的方法之一呢?

回答

5

我通常使用直PowerShell或MSBuild的。我儘量避免片狀的msdeploy。 在MSBuild的,你可以這樣使用非常方便的MSBuild擴展包,所以假設你可以將文件複製到目標位置(的Robocopy是非常方便的是)這將做休息:

<Project ToolsVersion="4.0" DefaultTargets="InstallService" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
    <UsingTask AssemblyFile="..\packages\MSBuild.Extension.Pack.1.2.0\lib\net40\MSBuild.ExtensionPack.dll" 
TaskName="MSBuild.ExtensionPack.Computer.WindowsService"/> 

    <PropertyGroup> 
    <MachineName Condition="$(MachineName)==''"></MachineName> 
    <ServiceName Condition="$(ServiceName)==''"></ServiceName> 
    <ServicePath Condition="$(ServicePath)==''"></ServicePath> 
    <User Condition="$(User)==''"></User> 
    <Password Condition="$(Password)==''"></Password> 
    <SuppressStart Condition="$(SuppressStart)==''"></SuppressStart> 
    </PropertyGroup> 

    <Target Name="CheckProperties" BeforeTargets="StopService"> 
    <Message Text="MachineName: $(MachineName)"/> 
    <Message Text="ServiceName: $(ServiceName)"/> 
    <Message Text="ServicePath: $(ServicePath)"/> 
    <Message Text="User : $(User)"/> 
    <Message Text="SuppressStart : $(SuppressStart)"/> 
    </Target> 

    <Target Name="StopService" BeforeTargets="InstallService"> 

    <MSBuild.ExtensionPack.Computer.WindowsService 
     TaskAction="CheckExists" 
     ServiceName="$(ServiceName)" 
     MachineName="$(MachineName)"> 
     <Output TaskParameter="Exists" PropertyName="DoesExist"/> 
    </MSBuild.ExtensionPack.Computer.WindowsService> 

    <MSBuild.ExtensionPack.Computer.WindowsService 
     TaskAction="Stop" 
     ServiceName="$(ServiceName)" 
     MachineName="$(MachineName)" 
     Condition="$(DoesExist)=='True'"> 
    </MSBuild.ExtensionPack.Computer.WindowsService> 
    </Target> 

    <Target Name="StartService" AfterTargets="InstallService"> 

    <MSBuild.ExtensionPack.Computer.WindowsService 
    TaskAction="CheckExists" 
    ServiceName="$(ServiceName)" 
    MachineName="$(MachineName)"> 
     <Output TaskParameter="Exists" PropertyName="DoesExist"/> 

    </MSBuild.ExtensionPack.Computer.WindowsService> 

    <MSBuild.ExtensionPack.Computer.WindowsService 
     TaskAction="Start" 
     ServiceName="$(ServiceName)" 
     MachineName="$(MachineName)" 
     Condition="$(DoesExist)=='True' And $(SuppressStart)=='False'" 
     RetryAttempts="20"> 
    </MSBuild.ExtensionPack.Computer.WindowsService> 
    <Message Text="Service $(ServiceName) set not to start" Condition="$(SuppressStart)=='True'" Importance="High" /> 
    </Target> 

    <Target Name="InstallService"> 

    <PropertyGroup> 
     <ServiceExeExists Condition="Exists('$(ServicePath)')">True</ServiceExeExists> 
    </PropertyGroup> 

    <Message Text="Installing $(ServicePath) %(ServiceName.Identity)" Importance="high"/> 
    <MSBuild.ExtensionPack.Computer.WindowsService 
     TaskAction="CheckExists" 
     ServiceName="$(ServiceName)" 
     MachineName="$(MachineName)"> 
     <Output TaskParameter="Exists" PropertyName="DoesExist"/> 

    </MSBuild.ExtensionPack.Computer.WindowsService> 

    <Message Text="Installed $(ServiceName) $(ServicePath) for $(User) and $(Password)" Importance="high"/> 
    <MSBuild.ExtensionPack.Computer.WindowsService 
     TaskAction="Install" 
     ServiceName="$(ServiceName)" 
     User="$(User)" 
     Password="$(Password)" 
     ServicePath="$(ServicePath)" 
     MachineName="$(MachineName)" 
     Condition="!$(DoesExist)"/> 

    <MSBuild.ExtensionPack.Computer.WindowsService 
     TaskAction="SetAutomatic" 
     ServiceName="$(ServiceName)" 
     MachineName="$(MachineName)" 
     Condition="!$(DoesExist)"/> 
    <Warning Text="%(ServiceName.Identity) service already exists" Condition="$(DoesExist)"/> 

    </Target> 

</Project> 
+0

沒有太多的經驗與msdeploy(使用它幾次,但從來沒有真正理解它是如何工作的「在引擎蓋下「),我必須承認我也覺得它有點片狀。然而,這只是意見,但我最終使用了帶有複製命令和幾個bat文件的msbuild。你的解決方案似乎更強大,但是當你說自己某種文件共享訪問時需要。 在我們的案例中,我們做到了!所以這個解決方案的工作原理和我將它標記爲答案。 您是否知道「卸載服務」或「停止服務」會等待服務正常停止多久?永遠? – marko

+1

您好Marko很高興我可以幫助,從在線文檔http://www.msbuildextensionpack.com/help/4.0.8.0/index.html它說,retryattempts屬性默認爲60。 –

1

我們使用這樣定義的msdeploy包:

<sitemanifest> 
    <runCommand path='presync.cmd' waitInterval='30000'/> 
    <dirPath path='$winSvc' /> 
    <runCommand path='postsync.cmd' waitInterval='30000'/> 
</sitemanifest> 

presync.cmd

net stop Svc 
installUtil /u /name=Svc $destPath\Svc.exe 

postsync.cmd

installUtil /name=Svc $destPath\Svc.exe 
net start Svc 

所有文件都通過PowerShell腳本生成的。

+0

什麼,如果等待時間不夠了嗎? – marko

+0

http://technet.microsoft.com/en-us/library/ee619740(v=ws.10).aspx –