我想做的事与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