

• AWS Systems Manager CloudWatch 控制面板在 2026 年 4 月 30 日之后将不再可用。客户可以像现在一样继续使用 Amazon CloudWatch 控制台来查看、创建和管理其 Amazon CloudWatch 控制面板。有关更多信息，请参阅 [Amazon CloudWatch 控制面板文档](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)。

# 运行命令时处理重启问题
<a name="send-commands-reboot"></a>

如果使用 Run Command（AWS Systems Manager 中的一项工具）运行脚本来重启托管式节点，建议在脚本中指定退出代码。如果您使用其他一些机制尝试通过脚本重启节点，则即使重启是脚本的最后一步，脚本执行状态也可能无法正确更新。对于 Windows 托管式节点，您需在脚本中指定 `exit 3010`。对于 Linux 和 macOS 托管式节点，需要指定 `exit 194`。退出代码用于指示 AWS Systems Manager Agent (SSM Agent) 重启托管式节点，然后在重启完成后重新启动脚本。在重启开始之前，SSM Agent 会通知云中的 Systems Manager 服务，通信将在服务器重启期间中断。

**注意**  
重启脚本不能作为 `aws:runDocument` 插件的一部分。如果一个文档包含重启脚本，另一个文档尝试通过 `aws:runDocument` 插件运行该文档，则 SSM Agent 会返回错误。

**创建幂等脚本**

在开发用于重启托管式节点的脚本时，使脚本具有幂等性，以便脚本执行在重启后从中断的位置继续进行。幂等脚本管理状态并验证是否执行了该操作。当一个步骤设定为仅运行一次时，可以防止该步骤多次运行。

以下是多次重启托管式节点的幂等脚本的概要示例。

```
$name = Get current computer name
If ($name –ne $desiredName) 
    {
        Rename computer
        exit 3010
    }
            
$domain = Get current domain name
If ($domain –ne $desiredDomain) 
    {
        Join domain
        exit 3010
    }
            
If (desired package not installed) 
    {
        Install package
        exit 3010
    }
```

**示例**

以下脚本示例使用退出代码来重新启动托管式节点。Linux 示例在 Amazon Linux 上安装软件包更新，然后重新启动该节点。Windows Server 示例在节点上安装 Telnet-Client，然后重新启动该节点。

------
#### [ Amazon Linux 2 ]

```
#!/bin/bash
yum -y update
needs-restarting -r
if [ $? -eq 1 ]
then
        exit 194
else
        exit 0
fi
```

------
#### [ Windows ]

```
$telnet = Get-WindowsFeature -Name Telnet-Client
if (-not $telnet.Installed)
    { 
        # Install Telnet and then send a reboot request to SSM Agent.
        Install-WindowsFeature -Name "Telnet-Client"
        exit 3010 
    }
```

------