加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows – 即使需要重启/重启,如何强制DSC执行所有配置(包)

发布时间:2020-12-14 00:00:41 所属栏目:Windows 来源:网络整理
导读:从 MSDN起 RebootNodeIfNeeded : Certain configuration changes on a target node might require it to be restarted for the changes to be applied. With the value “true,” this property will restart the node immediately and without warning. If
从 MSDN起

RebootNodeIfNeeded: Certain configuration changes on a target node might require it to be restarted for the changes to be applied. With the value “true,” this property will restart the node immediately and without warning. If “false,” the configuration will be completed,but the node must be restarted manually for the changes to take effect.

所以我的理解是,即使需要重启,DSC也应该运行所有配置

但在我的情况下并非如此,安装包后有时会将DSC标记为重新启动,DSC不会运行其余的配置

我必须再次手动执行命令才能运行其余配置

Start-DscConfiguration -Wait -Force -Path .SomePath

我想强制DSC运行所有配置,然后通知我是否需要重新启动服务器

我如何配置包的示例

LocalConfigurationManager
    {
        RebootNodeIfNeeded = $false
    }

   Package MVC3
    {
        Name = "Microsoft ASP.NET MVC 3"
        Ensure = "Present"
        Path = "$Env:SystemDriveAspNetMVC3ToolsUpdateSetup.exe"
        ProductId = "DCDEC776-BADD-48B9-8F9A-DFF513C3D7FA"
        Arguments = "/q"
        DependsOn = "[WindowsFeature]IIS"
        Credential = $Credential
    }

   Package MVC4
    {
        Name = "Microsoft ASP.NET MVC 4 Runtime"
        Ensure = "Present"
        Path = "$Env:SystemDriveAspNetMVC4Setup.exe"
        ProductId = "942CC691-5B98-42A3-8BC5-A246BA69D983"
        Arguments = "/q"
        DependsOn = "[Package]MVC3"
        Credential = $Credential
    }
我想出了这个解决方案

我想找到一个更好的方法来做到这一点.但无论如何它对我有用

我仍然认为DSC过程应该以某种方式通知我,而不仅仅是通过Write-Verbose,因为在我的情况下,这个过程是作为我们的持续集成过程的一部分启动的

[int]$maximumAttempts = 5
[int]$attempt = 0
[ValidateNotNull()][guid]$dscResTmp = [guid]::NewGuid()
[ValidateNotNullOrEmpty()][string]$dscResPathTmp = Join-Path $baseFolderPathTmp "$dscResTmp.log"

do
{
    [bool]$stopLoop = $false
    [int]$attempt = ++$attempt

    Start-DscConfiguration -Wait -Force -Path $folderPathTmp 4> $dscResPathTmp

    [string[]]$rebootServerCoincidences = Select-String -Pattern "reboot" -Path $dscResPathTmp

    if ($rebootServerCoincidences.Length -le 0)
    {
        [bool]$stopLoop = $true
    }
    else
    {
        Write-Warning ($rebootServerCoincidences -join [Environment]::NewLine)
    }
}
while($stopLoop -eq $false -and $attempt -le $maximumAttempts)

if ($stopLoop -eq $false)
{
    Write-Warning "Max attempts reached"
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读