MSDeploy to install windows service?

后端 未结 3 460
走了就别回头了
走了就别回头了 2021-02-04 00:33

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 subs

3条回答
  •  长情又很酷
    2021-02-04 00:54

    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
    

提交回复
热议问题