【问题标题】:Elastic Beanstalk ebextensions Restart Not ResumingElastic Beanstalk ebextensions 重启未恢复
【发布时间】:2015-12-09 16:30:29
【问题描述】:

我有一个命令需要在 container_commands 下的 ebextensions 文件中重新启动计算机

01_Rename.config:

container_commands:
  01-RenameComputer:
    command: powershell.exe .\\RenameComputer.ps1
    ignoreErrors: false
    waitAfterCompletion: 0

重命名计算机.ps1:

$instanceId = (New-Object System.Net.WebClient).DownloadString("http://169.254.169.254/latest/meta-data/instance-id")
If ($env:COMPUTERNAME -ne $instanceId) {
    Try {
        Write-Eventlog -LogName Application -Source Ec2Config -EventId 1000 -EntryType Information -Message "Instance $instanceId's computer name is not sync'd with the instance id. Renaming computer."
        Rename-Computer -NewName $instanceId
        Write-Eventlog -LogName Application -Source Ec2Config -EventId 1000 -EntryType Information -Message "Computer renamed. Restarting..."
        Restart-Computer
    }
    Catch [Exception] {
        Write-Eventlog -LogName Application -Source Ec2Config -EventId 2000 -EntryType Error -Message "An error occurred renaming $instanceId. $($_.Exception)"
    }
}
Else {
    Write-Eventlog -LogName Application -Source Ec2Config -EventId 1000 -EntryType Information -Message "Instance $instanceId's computer name is already sync'd with the instance id."
}

但是当 RenameComputer 运行并重新启动计算机时,我的下一个 container_commands 配置文件永远不会运行(部署不会恢复):

02_JoinDomain.config

container_commands:
  01-JoinDomain:
    command: powershell.exe .\\JoinDomain.ps1
    ignoreErrors: false
    waitAfterCompletion: 0

JoinDomain.ps1:

Import-Module AWSPowerShell

$instanceId = (New-Object System.Net.WebClient).DownloadString("http://169.254.169.254/latest/meta-data/instance-id")

If ($env:USERDNSDOMAIN -ne 'mydomain.com') {
    Write-Eventlog -LogName Application -Source Ec2Config -EventId 1000 -EntryType Information -Message "Instance $instanceId is not joined to the domain. Joining using SSM $env:SsmName in region $env:Region"

    Try {
        New-SSMAssociation -InstanceId:$instanceId -Name:$env:SsmName -Region $env:Region
        Write-Eventlog -LogName Application -Source Ec2Config -EventId 1000 -EntryType Information -Message "Successfully joined $instanceId to the domain. Restarting..."
        Restart-Computer
    }
    Catch [Exception] {
        Write-Eventlog -LogName Application -Source Ec2Config -EventId 2000 -EntryType Error -Message "An error occurred joining $instanceId to the domain. $($_.Exception)"
    }
}
Else {
    Write-Eventlog -LogName Application -Source Ec2Config -EventId 1000 -EntryType Information -Message "Instance $instanceId is already joined to the domain."
}

我知道我的配置和命令正在运行,因为如果我在同一环境中进行应用程序版本更新并且计算机没有从 RenameComputer.ps1 重新启动,因为它已经按需要命名,JoinDomain.ps1 会运行并加入计算机到域并再次重新启动。

文档(未)清楚地说:

waitAfterCompletion
Optional. Seconds to wait after the command completes before running the next command. If the system requires a reboot after the command completes, the system reboots after the specified number of seconds elapses. If the system reboots as a result of a command, Elastic Beanstalk will recover. The default value is 60 seconds. You can also specify forever, but the system must reboot before you can run another command.

这表明命令应该恢复......但它们不是。

我做错了什么?或者这只是另一个没有真正像宣传的那样有效的 AWS 功能?

【问题讨论】:

    标签: .net amazon-web-services amazon-elastic-beanstalk


    【解决方案1】:

    我能想到的几件事:

    1. 您是否尝试过将“01_Rename.config”重命名为使用“-”(连字符)而不是下划线?即名称 "01-Rename.config"(我已经看到下划线在编写 Powershell 脚本时在弹性 beanstalk 中对我造成了问题)。

    2. 还可以尝试使用不同的 "waitAfterCompletion" 值,或将其完全删除。怀疑EC2实例热时0就够了(应用程序版本更新,但冷重启/重启后没有)

    【讨论】:

    • 是的,我有。我还发现,当使用 container_commands 而不是命令时,重启后恢复确实会正确发生。现在我刚刚切换到 container_commands。看起来像一个错误。
    猜你喜欢
    • 2020-07-24
    • 2020-02-28
    • 2018-06-05
    • 2014-07-31
    • 2016-05-12
    • 2017-06-22
    • 2020-08-17
    • 2020-08-17
    • 2018-08-19
    相关资源
    最近更新 更多