全部產品
Search
文件中心

CloudOps Orchestration Service:ACS-ECS-RepairWindowsBlueScreenIssue

更新時間:Sep 06, 2024

模板名稱

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 }}'