【发布时间】:2016-02-16 14:33:03
【问题描述】:
我想用 DSC(Desired State Configuration)做一件非常简单的事情:
停止一个 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,我将它与 Microsoft 发布管理一起使用,在这里,'MyTestConfig2' 似乎不再执行(或其他未提及的错误在日志中)。
如何在发布管理的上下文中使用 dsc 实现这个简单的场景?或者有没有更好的方法来做这样的事情?
【问题讨论】:
-
这是个坏消息!也许使用 Chef 会更好。我认为要记住它适用于他们的解决方案。但是非常感谢您的输入和链接(如果链接被破坏,“解决方案”似乎是:编写您自己的自定义 DSC 资源)。
-
@DanielMann - 也许您想发布一个我可以接受的答案?你给我指出了正确的方向。 :)