ACS-ECS-RepairWindowsBlueScreenIssue

模板名称

ACS-ECS-RepairWindowsBlueScreenIssue 修复Windows系统蓝屏问题

立即执行

模板描述

修复Windows系统蓝屏问题解决方案

模板类型

自动化

所有者

Alibaba Cloud

输入参数

参数名称

描述

类型

是否必填

默认值

约束

instanceId

实例Id

String

password

实例密码

String

regionId

地域ID

String

{{ ACS::RegionId }}

输出参数

执行此模板需要的权限策略

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "ecs:AttachDisk",
                "ecs:DeleteInstance",
                "ecs:DescribeDisks",
                "ecs:DescribeInstances",
                "ecs:DescribeInvocationResults",
                "ecs:DescribeInvocations",
                "ecs:DetachDisk",
                "ecs:RunCommand",
                "ecs:RunInstances",
                "ecs:StartInstance",
                "ecs:StopInstance"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "ros:CreateStack",
                "ros:DeleteStack",
                "ros:GetStack"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

详情

ACS-ECS-RepairWindowsBlueScreenIssue详情

模板内容

FormatVersion: OOS-2019-06-01
Description:
  en: Solutions to Repair Windows System Blue Screen Issues
  zh-cn: 修复Windows系统蓝屏问题解决方案
  name-en: ACS-ECS-RepairWindowsBlueScreenIssue
  name-zh-cn: 修复Windows系统蓝屏问题
Parameters:
  regionId:
    Type: String
    Label:
      en: RegionId
      zh-cn: 地域ID
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  instanceId:
    Type: String
    AssociationProperty: ALIYUN::ECS::Instance::InstanceId
    AssociationPropertyMetadata:
      RegionId: regionId
    Label:
      en: InstanceId
      zh-cn: 实例Id
  password:
    Type: String
    AssociationProperty: ALIYUN::ECS::Instance::Password
    Label:
      en: ECS Instance Password
      zh-cn: 实例密码
    NoEcho: true
RamRole: ''
Tasks:
  - Name: getZoneId
    Action: ACS::ExecuteApi
    Description:
      en: Get zoneId of ECS instance
      zh-cn: 获取ECS实例可用区
    Properties:
      Service: ecs
      API: DescribeInstances
      Parameters:
        RegionId: '{{ regionId }}'
        InstanceIds:
          - '{{ instanceId }}'
    Outputs:
      zoneId:
        Type: String
        ValueSelector: .Instances.Instance[].ZoneId
      instanceType:
        Type: String
        ValueSelector: .Instances.Instance[].InstanceType
  - Name: createStack
    Action: ACS::ExecuteAPI
    Description:
      en: Create a resource stack of VPC
      zh-cn: 创建VPC资源栈
    Properties:
      Service: ROS
      API: CreateStack
      Parameters:
        RegionId: '{{ regionId  }}'
        StackName: OOS-{{ACS::ExecutionId}}
        TimeoutInMinutes: 10
        DisableRollback: false
        Parameters:
          - ParameterKey: ZoneId
            ParameterValue: '{{ getZoneId.zoneId }}'
          - ParameterKey: VpcCidrBlock
            ParameterValue: 192.168.0.0/16
          - ParameterKey: VSwitchCidrBlock
            ParameterValue: 192.168.1.0/24
        TemplateBody: |
          ROSTemplateFormatVersion: '2015-09-01'
          Parameters:
            ZoneId:
              Type: String
            VpcCidrBlock:
              Type: String
            VSwitchCidrBlock:
              Type: String
          Resources:
            EcsVpc:
              Type: ALIYUN::ECS::VPC
              Properties:
                CidrBlock:
                  Ref: VpcCidrBlock
                VpcName:
                  Ref: ALIYUN::StackName
            EcsVSwitch:
              Type: ALIYUN::ECS::VSwitch
              Properties:
                ZoneId:
                  Ref: ZoneId
                VpcId:
                  Ref: EcsVpc
                CidrBlock:
                  Ref: VSwitchCidrBlock
            EcsSecurityGroup:
              Type: ALIYUN::ECS::SecurityGroup
              Properties:
                VpcId:
                  Ref: EcsVpc
          Outputs:
            SecurityGroupId:
              Value:
                Ref: EcsSecurityGroup
            VSwitchId:
              Value:
                Ref: EcsVSwitch
    Outputs:
      StackId:
        Type: String
        ValueSelector: StackId
  - Name: untilStackReady
    Action: ACS::WaitFor
    Description:
      en: Wait for the stack status CREATE_COMPLETE
      zh-cn: 等待资源栈至创建成功状态
    OnError: deleteStack
    Retries: 10
    DelayType: Exponential
    Delay: 2
    BackOff: 2
    Properties:
      Service: ROS
      API: GetStack
      Parameters:
        RegionId: '{{ regionId  }}'
        StackId: '{{createStack.StackId}}'
      DesiredValues:
        - CREATE_COMPLETE
      StopRetryValues:
        - CREATE_FAILED
        - CHECK_FAILED
        - ROLLBACK_FAILED
        - ROLLBACK_COMPLETE
        - CREATE_ROLLBACK_COMPLETE
      PropertySelector: Status
      NotDesiredValues: []
    Outputs:
      securityGroupId:
        Type: String
        ValueSelector: Outputs[0].OutputValue
      vSwitchId:
        Type: String
        ValueSelector: Outputs[1].OutputValue
  - Name: runInstances
    Action: ACS::ECS::RunInstances
    Description:
      en: Create a temporary ECS instance
      zh-cn: 创建临时ECS实例
    OnError: deleteStack
    Properties:
      regionId: '{{ regionId }}'
      imageId: wincore_2022_x64_dtc_zh-cn_40G_alibase_20240617.vhd
      instanceType: '{{ getZoneId.instanceType }}'
      securityGroupId: '{{ untilStackReady.securityGroupId }}'
      vSwitchId: '{{ untilStackReady.vSwitchId }}'
      systemDiskCategory: cloud_essd
      systemDiskSize: '40'
      internetMaxBandwidthIn: 0
      internetMaxBandwidthOut: 0
      amount: 1
    Outputs:
      instanceId:
        Type: String
        ValueSelector: instanceIds[0]
  - Name: StopInstance
    Action: ACS::ECS::StopInstance
    Description:
      en: Stop ECS instance pending repair.
      zh-cn: 停止待修复ECS实例
    OnError: deleteInstance
    Properties:
      regionId: '{{ regionId }}'
      instanceId: '{{ instanceId }}'
      forceStop: true
  - Name: getDiskId
    Action: ACS::ExecuteApi
    Description:
      en: Get system disk ID of the ECS instance pending repair.
      zh-cn: 获取待修复ECS实例系统盘Id
    Properties:
      Service: ecs
      API: DescribeDisks
      Parameters:
        RegionId: '{{ regionId }}'
        InstanceId: '{{ instanceId }}'
        DiskType: system
    Outputs:
      diskId:
        Type: String
        ValueSelector: .Disks.Disk[].DiskId
  - Name: detachSystemDisk
    Description:
      en: Detach system disk of the ECS instance pending repair.
      zh-cn: 卸载待修复ECS实例系统盘
    Action: ACS::ECS::DetachDisk
    OnError: deleteInstance
    Properties:
      regionId: '{{ regionId }}'
      instanceId: '{{ instanceId }}'
      diskId: '{{ getDiskId.diskId }}'
  - Name: attachDiskToTempInstance
    Action: ACS::ECS::AttachDisk
    Description:
      en: Attach disk to a temporary ECS instance.
      zh-cn: 将磁盘挂载到临时ECS实例
    OnError: deleteInstance
    Properties:
      regionId: '{{ regionId }}'
      instanceId: '{{ runInstances.instanceId }}'
      diskId: '{{ getDiskId.diskId }}'
  - Name: waitForAWhile
    Description:
      en: Wait for ready
      zh-cn: 等待状态就绪
    Action: ACS::Sleep
    Properties:
      Duration: PT4M
  - Name: runCommand
    Action: ACS::ECS::RunCommand
    Description:
      en: Run the repair command.
      zh-cn: 运行修复命令
    Properties:
      regionId: '{{ regionId }}'
      commandType: RunPowerShellScript
      instanceId: '{{ runInstances.instanceId }}'
      commandContent: |-
        $disks = Get-Disk
        $disks | ForEach-Object {
          if ($_.IsOffline) {
            Set-Disk -Number $_.Number -IsOffline $false
          }

          if ($_.IsReadOnly) {
            Set-Disk -Number $_.Number -IsReadOnly $false
          }
        }

        # Rename driver dir
        $driverDir = "D:\windows\system32\drivers\CrowdStrike"
        if (!(Test-Path $driverDir)) {
          Write-Host "driver path not found"
          exit 1
        }

        Rename-Item -Path $driverDir -NewName ($driverDir + ".bak")
  - Name: detachDisk
    Action: ACS::ECS::DetachDisk
    Description:
      en: Detach disk from the temporary instance.
      zh-cn: 从临时实例卸载磁盘
    Properties:
      regionId: '{{ regionId }}'
      instanceId: '{{ runInstances.instanceId }}'
      diskId: '{{ getDiskId.diskId }}'
  - Name: attachDiskToOriginalInstance
    Action: ACS::ECS::AttachDisk
    Description:
      en: Attach disk to the original instance.
      zh-cn: 将磁盘挂载回源实例
    Properties:
      regionId: '{{ regionId }}'
      instanceId: '{{ instanceId }}'
      diskId: '{{ getDiskId.diskId }}'
      bootable: true
      password: '{{ password }}'
  - Name: startInstance
    Action: ACS::ECS::StartInstance
    Description:
      en: Start original instance.
      zh-cn: 启动源实例
    Properties:
      regionId: '{{ regionId }}'
      instanceId: '{{ instanceId }}'
  - Name: deleteInstance
    Action: ACS::ExecuteAPI
    Description:
      en: Delete the temporary instance.
      zh-cn: 删除临时实例
    Properties:
      Service: ECS
      API: DeleteInstance
      Risk: Normal
      Parameters:
        RegionId: '{{ regionId }}'
        InstanceId: '{{ runInstances.instanceId }}'
        Force: true
  - Name: deleteStack
    Action: ACS::ExecuteApi
    Description:
      en: Delete the stack of VPC
      zh-cn: 删除VPC资源栈
    Properties:
      Service: ROS
      API: DeleteStack
      Parameters:
        RegionId: '{{ regionId  }}'
        StackId: '{{ createStack.StackId }}'