MSDeploy to install windows service?

血红的双手。 提交于 2019-12-03 08:22:34

问题


We have a website which publishes events using NServiceBus. The site is deployed using msdeploy. We also have the NServiceBus.exe which should run as a windows service to subscribe to these events, and we'd like to deploy that as well.

Is there any way to package the service as well as the website, so that it can be installed as well? Is it possible to package separately so we can deploy it to another server?

Any tips on where to find information on how to do this would be great, as we can do automated deployments for the website now.


回答1:


I recently did this using MSDeploy, Phantom and installUtil.exe

You just basically need to modify your installer class and elevate your remote wmsvc service privileges if needed.

Link to blog




回答2:


What we wound up doing was creating a 'controller' layer that coordinates deployment tasks, even one that could use msdeploy. Essentially, msdeploy is not the highest level of abstraction in our deployment system.

We chose to use MSBuild to coordinate those tasks of deploying items from a 'package'.

In our deployment process, a web application deployed with msdeploy is just another deployment item, just as is a Windows service.

In all disclosure, we have not actually created msdeploy deployment tasks yet, though it should/would drop in nicely to what we've already created, as MSBuild would invoke the msdeploy. We currently use MSBuild community tasks for webapp deployment automation, coordinated via MSBuild.

You can read a little more about how we 'generalized' our deployments via a blog post I did called "PANDA - Packaging ANd Deployment Automation".




回答3:


Here is a msdeploy cmd line I used to sync an archivedir that is created from a post-build step in my Windows Service.proj file.

It is syncing from my build server to my app server on a different network. I have pre and post build steps that start and stop the services on the remote server. You must wrap the powershell script in a vb script due to a bug with powershell and msdeploy. The -verbose option is very helpful.

I also have the vbscript and ps1 script below. Be careful with the VB sleep and the pre and post msdeploy timeouts.

msdeploy -verb:sync -source:archivedir=\\qa-xxxxx1.qa.lan\deployment\backups\FreddieMacDelivery\FreddieMacDelivery.zip,tempAgent='True',computerName=qa-xxxxx1.qa.lan,userName=QA\xxxxx,password=xxxx,authtype=NTLM,includeAcls='False' -dest:dirpath=\\qa-xxxxxx1.qa.lan\protk\Services\FreddieMacDelivery\1.4.1.test -useCheckSum -verbose -preSync:runCommand="cscript.exe c:\temp\stop_win_svc.vbs" -postSync:runCommand="c:\temp\start_win_svc.vbs",waitInterval=15000,waitAttempts=1

VB script:

Option Explicit
Dim oShell, appCmd,oShellExec
Set oShell = CreateObject("WScript.Shell")

appCmd = "powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ""&c:/temp/Get_Win_SVC.ps1"" "

Set oShellExec = oShell.Exec(appCmd)

WScript.Sleep 1000
oShellExec.StdIn.Close()

Powershell script:

$username = 'QA\xxxxx'
$password = 'xxxxx'
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))

(Get-WmiObject  -computer qa-xxxx1.qa.lan  -Credential $cred Win32_Service -Filter "Name='ProTeck.FreddieMac.DeliveryService'")


$svc = (Get-WmiObject  -computer qa-xxxxx1.qa.lan  -Credential $cred Win32_Service -Filter "Name='ProTeck.FreddieMac.DeliveryService'") 

Write-Host  $svc

$svc.InvokeMethod("StartService", $null)


(Get-WmiObject  -computer qa-xxxxx1.qa.lan  -Credential $cred Win32_Service -Filter "Name='ProTeck.FreddieMac.DeliveryService'")> c:\temp\win_stat_post.txt


来源:https://stackoverflow.com/questions/4055617/msdeploy-to-install-windows-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!