All Products
Search
Document Center

Elastic Compute Service:Use a specified exit code to stop or restart instances

Last Updated:Dec 29, 2023

This topic describes how to run Cloud Assistant commands with specified exit codes to stop or restart Elastic Compute Service (ECS) instances.

Prerequisites

  • The instances that you want to stop or restart are in the Running (Running) state.

  • Cloud Assistance Agent is installed on the instances. For more information, see Install Cloud Assistant Agent.

    Cloud Assistant Agent is of one of the following versions or later:

    • Linux: 2.2.3.317

    • Windows: 2.1.3.317

    If an error is reported when you run a command with a specified exit code, upgrade Cloud Assistant Agent to the latest version. For more information, see Upgrade or disable upgrades for Cloud Assistant Agent.

Background information

When you run a Cloud Assistant command to stop or restart instances, we recommend that you append a specified exit code to the end of the command to ensure that the command execution states are accurate in real time. If you run a Cloud Assistant command without an exit code to stop or restart instances, the execution states of the command may not be correctly updated even when the command finishes with the stop or restart operation. This is because Cloud Assistant Agent does not save execution states of the command before the command is run to stop or restart the instances.

Procedure

  1. Log on to the ECS console.

  2. In the left-side navigation pane, choose Maintenance & Monitoring > Cloud Assistant.

  3. In the upper-left corner of the top navigation bar, select a region. 地域

  4. In the upper-right corner of the page that appears, click Create/Run Command.

  5. In the Command Information section, configure parameters. For more information, see Use the immediate execution feature.

  6. In the Command content code editor, add an exit code to the end of the specified command.

    • To run a command to stop instances, specify one of the following exit codes based on the operating system type of the instances. The following table describes exit codes.

      Operating system

      Exit code

      Sample command

      Linux

      193

      # If the following shell command returns an exit code of 193, an operation is triggered to stop specified instances.
      exit 193

      Windows

      3009

      # If the following PowerShell command returns an exit code of 3009, an operation is triggered to stop specified instances.
      exit 3009
    • To run a command to restart instances, specify one of the following exit codes based on the operating system type of the instances. The following table describes exit codes.

      Operating system

      Exit code

      Sample command

      Linux

      194

      # If the following shell command returns an exit code of 194, an operation is triggered to stop specified instances.
      exit 194

      Windows

      3010

      # If the following PowerShell command returns an exit code of 3010, an operation is triggered to stop specified instances.
      exit 3010
  7. In the Select Instance or Select Managed Instances section, select the instances on which you want to run the command.

    Note

    A managed instance is an instance that is not provided by Alibaba Cloud but is managed by Cloud Assistant. For more information, see Manage servers that are not provided by Alibaba Cloud.

  8. Click Run and Save or Run to immediately run the command task.