2016-05-03 63 views
4

我有一個DSC資源安裝dotnet功能,然後安裝一個更新到dotnet。配置一個DSC資源重啓

在本地配置管理器中,我已將RebootNodeIfNeeded設置爲$true

在dotnet安裝完成後,它不會請求重啓(甚至使用xPendingReboot模塊來確認這一點)。

Configuration WebServer 
{ 
WindowsFeature NetFramework45Core 
{ 
    Name = "Net-Framework-45-Core" 
    Ensure = "Present" 
} 

xPendingReboot Reboot 
{ 
    Name = "Prior to upgrading Dotnet4.5.2" 
} 

cChocoPackageInstaller InstallDotNet452 
{ 
    name = "dotnet4.5.2" 
} 

} 

這是DOTNET都不能正確使用我們的應用程序,除非服務器已重新啓動,我們正在努力使這些重新啓動自動發生不需要用戶輸入工作的問題。

有什麼辦法可以讓資源推送到localdscmanager(LCM),它需要重新啓動,當有東西正在安裝?

我發現下面的命令

$global:DSCMachineStatus = 1 

這臺重新啓動。但我不確定如何在4.5模塊安裝後立即使用它重新啓動。

回答

4

正常情況下,當我安裝.Net時,它不需要重新啓動,但是如果你想強制你的配置在安裝它之後重新啓動它,你可以執行以下操作。它不適用於漂移(在初始安裝後刪除.net)。在配置漂移期間,配置仍然會安裝.net,但是我添加到重新啓動的腳本資源將認爲它已經重新啓動。

DependsOn在這裏非常重要,您不希望此腳本在WindowsFeature成功運行之前運行。

configuration WebServer 
{ 
    WindowsFeature NetFramework45Core 
    { 
     Name = "Net-Framework-45-Core" 
     Ensure = "Present" 
    } 


    Script Reboot 
    { 
     TestScript = { 
      return (Test-Path HKLM:\SOFTWARE\MyMainKey\RebootKey) 
     } 
     SetScript = { 
      New-Item -Path HKLM:\SOFTWARE\MyMainKey\RebootKey -Force 
      $global:DSCMachineStatus = 1 

     } 
     GetScript = { return @{result = 'result'}} 
     DependsOn = '[WindowsFeature]NetFramework45Core' 
    }  
} 
1

要獲得$global:DSCMachineStatus = 1工作,你首先需要在遠程節點上配置Local Configuration Manager允許自動重新啓動。你可以這樣說:

Configuration ConfigureRebootOnNode 
{ 
    param (
     [Parameter(Mandatory=$true)] 
     [ValidateNotNullOrEmpty()] 
     [String] 
     $NodeName 
    ) 

    Node $NodeName 
    { 
     LocalConfigurationManager 
     { 
      RebootNodeIfNeeded = $true 
     } 
    } 
} 

ConfigureRebootOnNode -NodeName myserver 
Set-DscLocalConfigurationManager .\ConfigureRebootOnNode -Wait -Verbose 

(從colin's alm corner採取代碼)