I want to do a very simple thing with DSC (Desired State Configuration):
Stop a windows service, deploy files and finally start the service again. Thus I had the following:
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"
}
But unfortunately this is not working as it is not allowed to have the same name (Name = "TheTestService") in a configuration twice (Why? In this case it would totally make sense) as a workaround I tried something like this
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
Looks insane - but it works!
Unfortunately, I am not using plain DSC I am using it with Microsoft Release Management and here, it seems that the 'MyTestConfig2' is not executed anymore (or something else goes wrong that is not mentioned in the logs).
How can I realize this simple scenario with dsc within the context of release management? Or is there even a better way to do something like this?