8

Tôi muốn triển khai dịch vụ cửa sổ từ máy chủ xây dựng của chúng tôi đang chạy thành phố nhóm đến máy chủ Windows 2012 với cấu hình máy chủ tối thiểu.Triển khai dịch vụ windows từ thành phố nhóm

Một trong những cách tốt nhất để làm điều này là gì?

Trả lời

5

Tôi thường sử dụng powerhell thẳng hoặc msbuild cho việc này. Tôi cố gắng tránh các msdeploy flaky. Trong msbuild bạn có thể sử dụng các gói mở rộng msbuild rất tiện dụng như vậy, vì vậy giả sử bạn có thể sao chép các tập tin đến đích mục tiêu của bạn (Robocopy là tiện dụng cho điều đó) này sẽ làm phần còn lại:

<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

Nếu không có quá nhiều kinh nghiệm với msdeploy (đã sử dụng nó một vài lần nhưng chưa bao giờ thực sự hiểu cách hoạt động của nó) dưới mui xe "), tôi phải thừa nhận rằng tôi cũng cảm thấy rằng đó là loại flaky. Đó chỉ là ý kiến ​​tuy nhiên, nhưng tôi đã kết thúc bằng cách sử dụng msbuild với lệnh sao chép và một vài tập tin bat. Giải pháp của bạn có vẻ mạnh mẽ hơn, nhưng cần khi bạn nói chính mình một số loại truy cập fileshare. Trong trường hợp của chúng tôi, chúng tôi đã làm! Vì vậy, giải pháp này hoạt động và tôi sẽ đánh dấu nó như là một câu trả lời. Bạn có biết "dịch vụ gỡ cài đặt" hoặc "ngừng dịch vụ" trong bao lâu sẽ chờ dịch vụ tạm dừng không? Mãi mãi? – marko

+1

Xin chào Marko vui mừng tôi có thể giúp đỡ, từ các tài liệu trực tuyến http://www.msbuildextensionpack.com/help/4.0.8.0/index.html nó nói rằng tài sản retryattempts được mặc định là 60. –

1

Chúng tôi đang sử dụng gói msdeploy định nghĩa như thế này:

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

các presync.cmd:

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

các postsync.cmd:

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

Tất cả các tập tin được tạo ra bởi kịch bản PowerShell.

+0

gì nếu khoảng thời gian chờ đợi không phải là đủ lớn? – marko

+0

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

Các vấn đề liên quan