All Products
Search
Document Center

CloudOps Orchestration Service:ACS-ECS-RepairWindowsBlueScreenIssue

Last Updated:Nov 25, 2024

Template name

ACS-ECS-RepairWindowsBlueScreenIssue

Execute Now

Template description

Fixes the Windows blue screen issue.

Template type

Automated

Owner

Alibaba Cloud

Input parameters

Parameter

Description

Type

Required

Default value

Limit

instanceId

The ID of the Elastic Compute Service (ECS) instance.

String

Yes

password

The password that is used to log on to the ECS instance.

String

Yes

regionId

The region ID.

String

No

{{ ACS::RegionId }}

Output parameters

None

Permission policy that is required to execute the template

{
    "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"
        }
    ]
}

References

For more information, see ACS-ECS-RepairWindowsBlueScreenIssue.yml at GitHub.

Template content

FormatVersion: OOS-2019-06-01
Description:
  en: Solutions to Repair Windows System Blue Screen Issues
  zh-cn: the description in Chinese
  name-en: ACS-ECS-RepairWindowsBlueScreenIssue
  name-zh-cn: the description in Chinese
Parameters:
  regionId:
    Type: String
    Label:
      en: RegionId
      zh-cn: the description in Chinese
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  instanceId:
    Type: String
    AssociationProperty: ALIYUN::ECS::Instance::InstanceId
    AssociationPropertyMetadata:
      RegionId: regionId
    Label:
      en: InstanceId
      zh-cn: the description in Chinese
  password:
    Type: String
    AssociationProperty: ALIYUN::ECS::Instance::Password
    Label:
      en: ECS Instance Password
      zh-cn: the description in Chinese
    NoEcho: true
RamRole: ''
Tasks:
  - Name: getZoneId
    Action: ACS::ExecuteApi
    Description:
      en: Get zoneId of ECS instance
      zh-cn: the description in Chinese
    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: the description in Chinese
    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: the description in Chinese
    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: the description in Chinese
    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: the description in Chinese
    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: the description in Chinese
    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: the description in Chinese
    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: the description in Chinese
    OnError: deleteInstance
    Properties:
      regionId: '{{ regionId }}'
      instanceId: '{{ runInstances.instanceId }}'
      diskId: '{{ getDiskId.diskId }}'
  - Name: waitForAWhile
    Description:
      en: Wait for ready
      zh-cn: the description in Chinese
    Action: ACS::Sleep
    Properties:
      Duration: PT4M
  - Name: runCommand
    Action: ACS::ECS::RunCommand
    Description:
      en: Run the repair command.
      zh-cn: the description in Chinese
    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: the description in Chinese
    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: the description in Chinese
    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: the description in Chinese
    Properties:
      regionId: '{{ regionId }}'
      instanceId: '{{ instanceId }}'
  - Name: deleteInstance
    Action: ACS::ExecuteAPI
    Description:
      en: Delete the temporary instance.
      zh-cn: the description in Chinese
    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: the description in Chinese
    Properties:
      Service: ROS
      API: DeleteStack
      Parameters:
        RegionId: '{{ regionId  }}'
        StackId: '{{ createStack.StackId }}'