我想做的事與DSC(期望狀態配置)很簡單的事情:DSC:如何停止並啓動Windows服務
停止Windows服務,部署文件,終於再次啓動該服務。因此,我有以下幾點:
Service ServicesStop
{
Name = "TheTestService"
State = "Stopped"
}
File CopyDeploymentBits
{
Ensure = "Present"
Type = "Directory"
Recurse = $true
SourcePath = $applicationPath
DestinationPath = $deployOutputPath
}
Service ServicesStart
{
Name = "TheTestService"
StartupType = "Automatic"
State = "Running"
}
但不幸的是這是行不通的,因爲它是不允許有在配置相同的名稱(NAME =「TheTestService」)兩次(爲什麼在這種情況下?這是完全有道理的)作爲一種解決方法,我試過這樣的事情
Configuration MyTestConfig {
Node $env:COMPUTERNAME {
Service ServicesStop
{
Name = "TheTestService"
State = "Stopped"
}
File CopyDeploymentBits
{
Ensure = "Present"
Type = "Directory"
Recurse = $true
SourcePath = $applicationPath
DestinationPath = $deployOutputPath
}
}
}
Configuration MyTestConfig2 {
Node $env:COMPUTERNAME {
Service ServicesStart
{
Name = "TheTestService"
StartupType = "Automatic"
State = "Running"
}
}
}
MyTestConfig
MyTestConfig2
看起來瘋了 - 但它的工作!
不幸的是,我沒有使用我使用它與微軟發佈管理,在這裏普通DSC,似乎「MyTestConfig2」不執行了(或遇到其他未在日誌中提到的錯誤) 。
如何在發佈管理的上下文中使用dsc實現這個簡單的場景?還是有更好的方式來做這樣的事情?
非常感謝您的幫助和意見!
看到這個問題:http://stackoverflow.com/questions/35302781/how-to-upgrade-windows-service-using-powershell-desired-state-configuration –
這是個壞消息!也許比使用廚師更好。我想要記住,它的解決方案可以很好地工作。但是非常感謝您的輸入和鏈接(如果鏈接被破壞,'解決方案'似乎是:編寫您自己的自定義DSC資源)。 – timtos
@DanielMann - 也許你想發佈一個我可以接受的答案?你指出我正確的方向。 :) – timtos