Windows Restart 配置器

原文


类型:windows-restart

Windows Restart 配置器在 Windows 机器上发起重启并等待机器重新联机。

Windows 配置过程通常需要多次重启,而此配置器有助于简化该过程。

Packer 希望在机器重新启动并就绪后再继续执行配置程序。 Packer 通过 Windows 远程管理 (WinRM) 服务而不是 ACPI 函数进行 RPC 调用来检测重启是否已完成,因此 Windows 必须完全启动才能继续。

基础用法

HCL2:

provisioner "windows-restart" {}

Json:

{
  "type": "windows-restart"
}

配置参数

以下是该配置器可用的一些可选参数:

  • check_registry (bool) - 如果为 true,则检查几个指示系统将要重启的注册表项。如果配置程序启动了重启,并且您希望配置器在重新连接之前等待重启完成,该参数将很有用。请注意,此选项是测试版功能,我们通常建议您在 winrm 配置器程序连接之前的自动无人参与阶段完成自动重启的安装(如 Windows 更新)。
  • registry_keys ([]string) - 如果 check-registrytruewindows-restart 将不会重新连接,直到所有列出的键都不再存在于注册表中。
  default:

      var DefaultRegistryKeys = []string{
        "HKLM:SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\RebootPending",
        "HKLM:SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\PackagesPending",
        "HKLM:Software\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\RebootInProgress",
      }
  • restart_command (string) - 发起启动重启的命令。默认值为 shutdown /r /f /t 0 /c "packer restart"
  • restart_check_command (string) - 执行 restart_command 后运行的命令,用于检查远程计算机是否已重新启动。此命令将重试,直到恢复到客户机的连接或超过 restart_timeout

HCL2:

provisioner "windows-restart" {
  restart_check_command = "powershell -command \"& {Write-Output 'restarted.'}\""
}

Json:

{
  "type": "windows-restart",
  "restart_check_command": "powershell -command \"& {Write-Output 'restarted.'}\""
}
  • restart_timeout (string) - 等待重启的超时时间。默认情况下,这是 5 分钟。示例值:5m。如果您正在安装更新或有很多启动服务,您可能需要增加此持续时间。

所有配置器共有的参数:

  • pause_before (duration) - 执行前休眠一段时间。
  • max_retries (int) - provisioner 在失败的情况下重试的最大次数。默认为零 (0)。零表示不会重试错误。
  • only (array of string) - 只运行列表中指定的的配置器程序。
  • override (object) - 使用特定配置器的不同设置覆盖配置器,例如:

HCL2:

source "null" "example1" {
  communicator = "none"
}

source "null" "example2" {
  communicator = "none"
}

build {
  sources = ["source.null.example1", "source.null.example2"]
  provisioner "shell-local" {
    inline = ["echo not overridden"]
    override = {
      example1 = {
        inline = ["echo yes overridden"]
      }
    }
  }
}

Json:

{
  "builders": [
    {
      "type": "null",
      "name": "example1",
      "communicator": "none"
    },
    {
      "type": "null",
      "name": "example2",
      "communicator": "none"
    }
  ],
  "provisioners": [
    {
      "type": "shell-local",
      "inline": ["echo not overridden"],
      "override": {
        "example1": {
          "inline": ["echo yes overridden"]
        }
      }
    }
  ]
}
  • timeout(duration)- 如果配置器完成时间超过配置值(例如 1h10m1s10m),则配置器将超时并失败。

results matching ""

    No results matching ""