テンプレート名
ACS-ECS-RescueUnreachableInstance-Linux
テンプレートの説明
強制停止、再起動、または突然の故障によってシステムディスクが損傷した場合、ECS インスタンスが到達できなくなることがあります。その他の原因としては、/etc/fstab または initrd ファイルの欠損や破損、データディスクのデタッチ後に /etc/fstab を更新しなかったことなどが挙げられます。インスタンスは ECS コンソールで [Running] と表示されていても、アプリケーション、ネットワーク、ワークベンチ、SSH 接続はすべて失敗します。VNC 接続では、システムの起動失敗メッセージが表示されることがあります。このテンプレートは、インスタンスのシステムディスクを一時インスタンスにアタッチし、修復スクリプトを実行し、修復されたディスクを元のインスタンスに再アタッチすることでインスタンスを修復します。
テンプレートタイプ
自動
所有者
Alibaba Cloud
入力パラメーター
|
パラメーター |
説明 |
タイプ |
必須 |
デフォルト値 |
制限 |
|
unreachableInstanceId |
修復対象の ECS インスタンスの ID。 |
String |
はい |
||
|
credentialType |
ECS インスタンスへのログインに使用する認証情報のタイプ。 |
String |
はい |
||
|
credentialValue |
ECS インスタンスへのログインに使用する認証情報の値。 |
String |
はい |
||
|
imagePrefix |
ECS インスタンスのバックアップイメージの名前プレフィックス。 |
String |
いいえ |
OOSRescueBackup- |
|
|
helperInstanceTypes |
修復用の一時インスタンスで使用可能なインスタンスタイプ。 |
List |
いいえ |
['ecs.t6-c4m1.large', 'ecs.t5-lc1m1.small', 'ecs.t5-lc1m2.small', 'ecs.s6-c1m1.small', 'ecs.s6-c1m2.small', 'ecs.n1.small', 'ecs.mn4.small', 'ecs.e3.small', 'ecs.e4.small', 'ecs.n2.small', 'ecs.n4.small', 'ecs.t5-lc1m2.large', 'ecs.c6.large', 'ecs.sn2ne.large'] |
|
|
OOSAssumeRole |
OOS が引き受ける RAM ロール。 |
String |
いいえ |
"" |
出力パラメーター
|
パラメーター |
説明 |
タイプ |
|
diskId |
String |
|
|
imageId |
String |
|
|
rtCommandOutput |
String |
|
|
finalHelperInstanceType |
String |
実行に必要なアクセス許可ポリシー
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:AddTags",
"ecs:AttachDisk",
"ecs:CreateImage",
"ecs:DescribeAvailableResource",
"ecs:DescribeDisks",
"ecs:DescribeImages",
"ecs:DescribeInstances",
"ecs:DescribeInvocationResults",
"ecs:DescribeInvocations",
"ecs:DetachDisk",
"ecs:RunCommand",
"ecs:StartInstance",
"ecs:StopInstance"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"ros:CreateStack",
"ros:DeleteStack",
"ros:GetStack"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
関連ドキュメント
GitHub でテンプレートのソースを表示: ACS-ECS-RescueUnreachableInstance-Linux.yml。
テンプレートの内容
FormatVersion: OOS-2019-06-01
Description:
ja: 'ECS インスタンスを使用していると、インスタンスの強制停止や再起動、突然のダウンタイム、ディスクのデタッチ時に /etc/fstab を更新しなかった、あるいは /etc/fstab や initrd ファイルの欠損や破損など、システムディスクの破損につながる状況が発生することがあります。インスタンスが到達できなくなった場合、ECS インスタンスコンソールに表示されるインスタンスの状態は [Running] のままであっても、インスタンス内のアプリケーションへのアクセスやネットワーク接続ができず、ワークベンチや SSH 経由での接続も確立できません。コンソールから VNC でインスタンスに接続できる場合、システムの起動失敗を示すページが表示されることがあります。このような場合、このテンプレートを実行して破損したインスタンスを修復することを検討できます。修復プロセスでは、破損したインスタンスのシステムディスクを新しく作成された一時インスタンスにアタッチし、その一時インスタンスで修復スクリプトを実行した後、最後に修復されたシステムディスクを元のインスタンスにアタッチし直します。'
zh-cn: the description in Chinese
name-ja: ACS-ECS-RescueUnreachableInstance-Linux
name-zh-cn: the description in Chinese
categories:
- 診断
Parameters:
unreachableInstanceId:
Label:
ja: 到達できないインスタンス ID
zh-cn: the description in Chinese
Type: String
AssociationProperty: ALIYUN::ECS::Instance::InstanceId
AssociationPropertyMetadata:
RegionId: '{{ ACS::RegionId }}'
credentialType:
Description:
ja: '復旧後の到達できない ECS インスタンスの認証情報タイプ。KeyPairName または Password タイプを選択できます。'
zh-cn: the description in Chinese
Label:
ja: 認証情報タイプ
zh-cn: the description in Chinese
Type: String
AllowedValues:
- KeyPairName
- Password
credentialValue:
Description:
ja: '復旧後の到達できない ECS インスタンスの認証情報の値。KeyPairName または Password の値を指定します。'
zh-cn: the description in Chinese
Type: String
Label:
ja: 認証情報
zh-cn: the description in Chinese
imagePrefix:
Label:
ja: イメージプレフィックス
zh-cn: the description in Chinese
Type: String
Default: OOSRescueBackup-
helperInstanceTypes:
Label:
ja: ヘルパーインスタンスタイプ
zh-cn: the description in Chinese
Type: List
Default:
- ecs.t6-c4m1.large
- ecs.t5-lc1m1.small
- ecs.t5-lc1m2.small
- ecs.s6-c1m1.small
- ecs.s6-c1m2.small
- ecs.n1.small
- ecs.mn4.small
- ecs.e3.small
- ecs.e4.small
- ecs.n2.small
- ecs.n4.small
- ecs.t5-lc1m2.large
- ecs.c6.large
- ecs.sn2ne.large
OOSAssumeRole:
Label:
ja: OOSAssumeRole
zh-cn: the description in Chinese
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: checkInstanceReady
Action: 'ACS::CheckFor'
Description:
ja: ECS インスタンスが Linux OS であることを確認します
zh-cn: the description in Chinese
OnError: ACS::END
Properties:
Service: ECS
API: DescribeInstances
Parameters:
InstanceIds:
- '{{ unreachableInstanceId }}'
DesiredValues:
- linux
PropertySelector: 'Instances.Instance[].OSType'
Outputs:
status:
Type: String
ValueSelector: 'Instances.Instance[].Status'
vSwitchId:
Type: String
ValueSelector: 'Instances.Instance[].VpcAttributes.VSwitchId'
zoneId:
Type: String
ValueSelector: 'Instances.Instance[].ZoneId'
oSNameEn:
Type: String
ValueSelector: 'Instances.Instance[].OSNameEn'
oSName:
Type: String
ValueSelector: 'Instances.Instance[].OSName'
imageID:
Type: String
ValueSelector: 'Instances.Instance[].ImageId'
- Name: querySystemDisks
Action: 'ACS::CheckFor'
Description:
ja: ECS インスタンスのシステムディスクを確認します
zh-cn: the description in Chinese
OnError: ACS::END
Properties:
Service: ECS
API: DescribeDisks
Parameters:
InstanceId: '{{ unreachableInstanceId }}'
DiskType: system
DesiredValues:
- 'true'
PropertySelector: '.Disks.Disk[] as $disk|$disk.Category|startswith("cloud") and ($disk.Encrypted|not)|tostring'
Outputs:
diskId:
Type: String
ValueSelector: 'Disks.Disk[].DiskId'
category:
Type: String
ValueSelector: 'Disks.Disk[].Category'
encrypted:
Type: String
ValueSelector: 'Disks.Disk[].Encrypted'
- Name: whetherStopInstance
Action: 'ACS::Choice'
Description:
ja: インスタンスのステータスに応じて次のタスクを選択します
zh-cn: the description in Chinese
Properties:
DefaultTask: stopInstance
Choices:
- When:
'Fn::Equals':
- Stopped
- '{{ checkInstanceReady.status }}'
NextTask: checkAvailableInstanceTypesExist
- Name: stopInstance
Action: 'ACS::ExecuteAPI'
Description:
ja: ECS インスタンスを停止します
zh-cn: the description in Chinese
Properties:
Service: ECS
API: StopInstance
Parameters:
InstanceId: '{{ unreachableInstanceId }}'
- Name: Sleep3Minutes
Description:
ja: インスタンスが停止するのを待ちます
zh-cn: the description in Chinese
Action: 'ACS::Sleep'
Properties:
Duration: PT3M
- Name: queryUnreachableInstanceStatus
Action: 'ACS::ExecuteAPI'
Description:
ja: 到達できないインスタンスのステータスを照会します
zh-cn: the description in Chinese
Properties:
Service: ECS
API: DescribeInstances
Parameters:
InstanceIds:
- '{{ unreachableInstanceId }}'
Outputs:
status:
Type: String
ValueSelector: 'Instances.Instance[].Status'
- Name: whetherForceStopInstance
Action: 'ACS::Choice'
Description:
ja: インスタンスのステータスに応じて次のタスクを選択します
zh-cn: the description in Chinese
Properties:
DefaultTask: forceStopInstance
Choices:
- When:
'Fn::Equals':
- Stopped
- '{{ queryUnreachableInstanceStatus.status }}'
NextTask: checkAvailableInstanceTypesExist
- Name: forceStopInstance
Action: 'ACS::ExecuteAPI'
Description:
ja: ECS インスタンスを強制的に停止します
zh-cn: the description in Chinese
Properties:
Service: ECS
API: StopInstance
Parameters:
InstanceId: '{{ unreachableInstanceId }}'
ForceStop: 'true'
- Name: untilStopUnreachableInstanceSuccess
Action: 'ACS::WaitFor'
Description:
ja: ECS インスタンスが停止状態になるのを待ちます
zh-cn: the description in Chinese
Properties:
Service: ECS
API: DescribeInstances
Parameters:
InstanceIds:
- '{{ unreachableInstanceId }}'
DesiredValues:
- Stopped
PropertySelector: 'Instances.Instance[].Status'
- Name: checkAvailableInstanceTypesExist
Action: 'ACS::Template'
OnError: ACS::END
Description:
ja: 到達できないインスタンスのゾーンでヘルパーインスタンスを作成するために、現在利用可能なインスタンスタイプを照会します
zh-cn: the description in Chinese
Properties:
TemplateName: 'ACS::ECS::CheckAvailableInstanceTypes'
Parameters:
zoneId: '{{ checkInstanceReady.zoneId }}'
instanceTypes: '{{ helperInstanceTypes }}'
Outputs:
availableInstanceType:
Type: String
ValueSelector: '.availableInstanceTypes[0]'
- Name: createImage
Action: 'ACS::ExecuteAPI'
Description:
ja: カスタムイメージを作成します
zh-cn: the description in Chinese
Properties:
Service: ECS
API: CreateImage
Parameters:
ImageName: '{{imagePrefix}}{{ ACS::ExecutionId }}'
InstanceId: '{{ unreachableInstanceId }}'
DetectionStrategy: Standard
Tag:
- Key: 'instance_to_rescue'
Value: '{{unreachableInstanceId}}'
- Key: 'oos_exec'
Value: '{{ ACS::ExecutionId }}'
Outputs:
imageId:
Type: String
ValueSelector: ImageId
- Name: createStack
Action: 'ACS::ExecuteAPI'
Description:
ja: ROS リソーススタックを作成します
zh-cn: the description in Chinese
Properties:
Service: ROS
API: CreateStack
Parameters:
StackName: 'OOS-{{ACS::ExecutionId}}'
TimeoutInMinutes: 10
DisableRollback: false
Parameters:
- ParameterKey: helperInstanceType
ParameterValue: '{{checkAvailableInstanceTypesExist.availableInstanceType}}'
- ParameterKey: zoneId
ParameterValue: '{{ checkInstanceReady.zoneId }}'
- ParameterKey: resourcePrefix
ParameterValue: 'OOS-{{ACS::ExecutionId}}'
- ParameterKey: imageId
ParameterValue: 'centos_8_0_x64_20G_alibase_20191225.vhd'
- ParameterKey: instanceIdToRescue
ParameterValue: '{{unreachableInstanceId}}'
- ParameterKey: executionId
ParameterValue: '{{ ACS::ExecutionId }}'
TemplateURL: 'https://oos-debug.oss-cn-hangzhou.aliyuncs.com/ros_template.json'
Outputs:
StackId:
Type: String
ValueSelector: StackId
- Name: untilImageReady
Action: ACS::WaitFor
Description:
ja: イメージが利用可能になるのを待ちます
zh-cn: the description in Chinese
OnError: deleteStack
Properties:
Service: ECS
API: DescribeImages
Parameters:
ImageId: '{{ createImage.imageId }}'
DesiredValues:
- Available
PropertySelector: Images.Image[].Status
Retries: 50
Delay: 36
DelayType: Constant
- Name: untilStackReady
Action: 'ACS::WaitFor'
OnError: queryStackStatusReason
OnSuccess: putRTToHelperInstance
Description:
ja: スタックのステータスが CREATE_COMPLETE になるのを待ちます。
zh-cn: the description in Chinese
Properties:
Service: ROS
API: GetStack
Parameters:
StackId: '{{createStack.StackId}}'
DesiredValues:
- CREATE_COMPLETE
StopRetryValues:
- CREATE_FAILED
- CHECK_FAILED
- ROLLBACK_FAILED
- ROLLBACK_COMPLETE
- CREATE_ROLLBACK_COMPLETE
PropertySelector: Status
Outputs:
helperInstanceId:
Type: String
ValueSelector: 'Outputs[0].OutputValue'
statusReason:
Type: String
ValueSelector: 'StatusReason'
- Name: queryStackStatusReason
Action: ACS::ExecuteAPI
OnError: deleteStack
OnSuccess: deleteStack
Description:
ja: 作成に失敗したスタックの理由を照会します。
zh-cn: the description in Chinese
Properties:
Service: ROS
API: GetStack
Parameters:
StackId: '{{createStack.StackId}}'
Outputs:
statusReason:
Type: String
ValueSelector: 'StatusReason'
- Name: putRTToHelperInstance
Action: 'ACS::ECS::RunCommand'
OnError: deleteStack
Description:
ja: ECS インスタンスで Cloud Assistant コマンドを実行して rt をダウンロードします
zh-cn: the description in Chinese
Properties:
commandContent: 'cd /tmp ; wget https://oos-debug.oss-cn-hangzhou.aliyuncs.com/guestos-scripts-0.0.1.tar.gz; tar -zxvf guestos-scripts-0.0.1.tar.gz'
commandType: RunShellScript
instanceId: '{{ untilStackReady.helperInstanceId }}'
- Name: addTags
Action: ACS::ExecuteAPI
OnError: deleteStack
Description:
ja: システムディスクのタグを復旧対象のインスタンスに追加します
zh-cn: the description in Chinese
Properties:
Service: ECS
API: AddTags
Parameters:
ResourceType: instance
ResourceId: '{{ unreachableInstanceId }}'
Tag:
- Key: 'source_sys_disk'
Value: '{{ querySystemDisks.diskId }}'
- Name: detachDisk
Action: 'ACS::ECS::DetachDisk'
OnError: deleteStack
Description:
ja: 到達できないインスタンスからシステムディスクをデタッチします
zh-cn: the description in Chinese
Properties:
instanceId: '{{ unreachableInstanceId }}'
diskId: '{{ querySystemDisks.diskId }}'
- Name: attachAsDataDisk
Action: 'ACS::ECS::AttachDisk'
OnError: deleteStack
Description:
ja: システムディスクをデータディスクとしてヘルパーインスタンスにアタッチします
zh-cn: the description in Chinese
Properties:
instanceId: '{{ untilStackReady.helperInstanceId }}'
diskId: '{{ querySystemDisks.diskId }}'
- Name: runCommand
Action: 'ACS::ECS::RunCommand'
OnError: deleteStack
Description:
ja: ECS インスタンスでディスクを復旧するための Cloud Assistant コマンドを実行します
zh-cn: the description in Chinese
Properties:
commandContent: cd /tmp/guestos-scripts-0.0.1;./rescue_system_disk.sh
commandType: RunShellScript
instanceId: '{{ untilStackReady.helperInstanceId }}'
Outputs:
commandOutput:
Type: String
ValueSelector: invocationOutput
- Name: forceStopHelperInstance
Action: 'ACS::ExecuteAPI'
OnError: deleteStack
Description:
ja: ヘルパーインスタンスを強制的に停止します
zh-cn: the description in Chinese
Properties:
Service: ECS
API: StopInstance
Parameters:
InstanceId: '{{ untilStackReady.helperInstanceId }}'
ForceStop: 'true'
- Name: untilforceStopHelperInstanceSuccess
Action: 'ACS::WaitFor'
OnError: deleteStack
Description:
ja: ヘルパーインスタンスが停止状態になるのを待ちます
zh-cn: the description in Chinese
Properties:
Service: ECS
API: DescribeInstances
Parameters:
InstanceIds:
- '{{ untilStackReady.helperInstanceId }}'
DesiredValues:
- Stopped
PropertySelector: 'Instances.Instance[].Status'
- Name: detachHelperInstanceDataDisk
Action: 'ACS::ECS::DetachDisk'
OnError: deleteStack
Description:
ja: ヘルパーインスタンスからデータディスクをデタッチします
zh-cn: the description in Chinese
Properties:
instanceId: '{{ untilStackReady.helperInstanceId }}'
diskId: '{{ querySystemDisks.diskId }}'
- Name: untilUnreachableInstanceSystemDiskAvailable
Action: 'ACS::WaitFor'
OnError: 'ACS::NEXT'
Description:
ja: ディスクがデタッチされるのを待ちます
zh-cn: the description in Chinese
Properties:
Service: ECS
API: DescribeDisks
Parameters:
DiskIds:
- '{{ querySystemDisks.diskId }}'
DesiredValues:
- Available
PropertySelector: 'Disks.Disk[].Status'
- Name: deleteStack
Action: 'ACS::ExecuteAPI'
OnError: 'ACS::NEXT'
Description:
ja: ROS リソーススタックを削除します
zh-cn: the description in Chinese
Properties:
Service: ROS
API: DeleteStack
Parameters:
StackId: '{{createStack.StackId}}'
- Name: untilStackDeleted
Action: 'ACS::WaitFor'
OnError: 'ACS::NEXT'
Description:
ja: ROS スタックのステータスが DELETE_COMPLETE になるのを待ちます
zh-cn: the description in Chinese
Properties:
Service: ROS
API: GetStack
Parameters:
StackId: '{{createStack.StackId}}'
DesiredValues:
- DELETE_COMPLETE
StopRetryValues:
- DELETE_FAILED
- CHECK_FAILED
PropertySelector: Status
- Name: checkForUnreachableInstanceSystemDiskAvailable
Action: 'ACS::CheckFor'
OnError: 'ACS::END'
Description:
ja: ディスクがデタッチされたことを確認します
zh-cn: the description in Chinese
Properties:
Service: ECS
API: DescribeDisks
Parameters:
DiskIds:
- '{{ querySystemDisks.diskId }}'
DesiredValues:
- Available
PropertySelector: 'Disks.Disk[].Status'
- Name: whetherCredentialTypeIsKeyPairName
Action: 'ACS::Choice'
OnError: 'ACS::NEXT'
Description:
ja: 入力された認証情報タイプに応じて次のタスクを選択します
zh-cn: the description in Chinese
Properties:
DefaultTask: attachAsSysDiskWithKeyPairName
Choices:
- When:
'Fn::Equals':
- Password
- '{{ credentialType }}'
NextTask: attachAsSysDisk
- Name: attachAsSysDiskWithKeyPairName
Action: 'ACS::ExecuteAPI'
OnSuccess: untilDiskAttached
OnError: 'ACS::NEXT'
Description:
ja: 元のシステムディスクを到達できないインスタンスにアタッチし、root の認証情報タイプとして KeyPairName を設定します
zh-cn: the description in Chinese
Properties:
Service: ECS
API: AttachDisk
Parameters:
DiskId: '{{ querySystemDisks.diskId }}'
InstanceId: '{{ unreachableInstanceId }}'
Bootable: 'true'
KeyPairName: '{{credentialValue}}'
- Name: attachAsSysDisk
Action: 'ACS::ExecuteAPI'
OnError: 'ACS::NEXT'
Description:
ja: 元のシステムディスクを到達できないインスタンスにアタッチし、root の認証情報タイプとして Password を設定します
zh-cn: the description in Chinese
Properties:
Service: ECS
API: AttachDisk
Parameters:
DiskId: '{{ querySystemDisks.diskId }}'
InstanceId: '{{ unreachableInstanceId }}'
Bootable: 'true'
Password: '{{credentialValue}}'
- Name: untilDiskAttached
Action: 'ACS::WaitFor'
OnError: 'ACS::NEXT'
Description:
ja: システムディスクがアタッチされるのを待ちます
zh-cn: the description in Chinese
Retries: 7
Properties:
Service: ECS
API: DescribeDisks
Parameters:
DiskIds:
- '{{ querySystemDisks.diskId }}'
DesiredValues:
- In_use
PropertySelector: 'Disks.Disk[].Status'
- Name: whetherStartUnreachableInstance
Action: 'ACS::Choice'
OnError: 'ACS::NEXT'
Description:
ja: 元のインスタンスのステータスに応じて次のタスクを選択します
zh-cn: the description in Chinese
Properties:
DefaultTask: ACS::END
Choices:
- When:
'Fn::Equals':
- Running
- '{{ checkInstanceReady.status }}'
NextTask: startUnreachableInstance
- Name: startUnreachableInstance
Action: 'ACS::ECS::StartInstance'
Description:
ja: 到達できないインスタンスを起動します
zh-cn: the description in Chinese
Properties:
instanceId: '{{ unreachableInstanceId}}'
Outputs:
diskId:
Type: String
Value: '{{ querySystemDisks.diskId }}'
imageId:
Type: String
Value: '{{ createImage.imageId }}'
rtCommandOutput:
Type: String
Value: '{{ runCommand.commandOutput }}'
finalHelperInstanceType:
Type: String
Value: '{{checkAvailableInstanceTypesExist.availableInstanceType}}'
Metadata:
ALIYUN::OOS::Interface:
ParameterGroups:
- Parameters:
- credentialType
- credentialValue
- imagePrefix
- helperInstanceTypes
Label:
default:
zh-cn: the description in Chinese
ja: パラメーターの設定
- Parameters:
- unreachableInstanceId
Label:
default:
zh-cn: the description in Chinese
ja: ECS インスタンスの選択
- Parameters:
- OOSAssumeRole
Label:
default:
zh-cn: the description in Chinese
ja: 制御オプション