All Products
Search
Document Center

Elastic Compute Service:Run an existing Cloud Assistant command

Last Updated:Oct 14, 2024

After you create a Cloud Assistant command, you can run the command on one or more Elastic Compute Service (ECS) instances. The execution status and results of the command on multiple instances do not affect each other.

Prerequisites

Before you run a Cloud Assistant command on ECS instances, make sure that the instances meet the following requirements:

  • The instances are in the Running state.

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

    To ensure that scheduled tasks can run as expected, make sure that the version of Cloud Assistant Agent is not earlier than the following versions. A scheduled task can run a command at a specific interval, run a command only once at a specific time, or run a command based on a schedule specified by a cron expression that has a specific year or time zone.

    • Linux: 2.2.3.282

    • Windows: 2.1.3.282

    If the ClientNeedUpgrade error code is returned, update Cloud Assistant Agent to the latest version. For more information, see Upgrade or disable upgrades of Cloud Assistant Agent.

Background information

  • You can call an API operation to run a command on up to 100 instances in a single request. The quota named "Maximum number of instances supported for command execution" specifies the maximum number of instances that a command can run in one execution. You can apply for a quota increase. For information about how to view and increase resource quotas, see Manage quotas.

  • If you select more than 100 instances to run a command in the ECS console, the system runs the command on the instances in batches.

Procedure

Run a command in the ECS console

  1. Log on to the ECS console.

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

  3. In the top navigation bar, select the region and resource group to which the resource belongs. 地域

  4. Click the My Commands tab, find the Cloud Assistant command that you want to run, and then click Run in the Actions column.

  5. In the Run Command panel, specify parameters for the command.

    1. In the Command Information section, check the command content and configure the parameters. The following table describes the parameters.

      Parameter

      Description

      Command content

      Click View command content to view the command content.

      Execution Plan

      Select a plan on when to run the command.

      • Immediate execution: The command is immediately run after you click Run.

      • After the next startup of the system: The command is run the next time the associated instances are started after you click Run.

      • After each system startup: The command is run each time the associated instances are started after you click Run.

      • Run on Schedule: The command is run at a specific interval, at a specific time, or on a schedule after you click Run. The following execution schedule options are available:

        • Run at Fixed Interval: Use a rate expression to specify an interval at which you want to run the command. You can specify the interval in seconds, minutes, hours, or days. This option is suitable for scenarios in which you want to execute command execution tasks at a fixed interval.

          Note

          When you specify an interval, take note of the following limits:

          • The specified interval can range from 60 seconds to 7 days and must be longer than the timeout period of the scheduled task.

          • The interval is the amount of time that elapses between two consecutive executions. The interval is irrelevant to the amount of time that is required to run the command once. For example, you set the interval to 5 minutes, and the command requires 2 minutes to run once. Each time the command is run, the system waits for 3 minutes before it reruns the command.

          • After you create a task, the task does not immediately run. For example, you set the interval to 5 minutes and create a task to run the command. The task runs 5 minutes after it is created.

        • Run Only Once at Specified Time: Specify a point in time and a time zone to run the command only once.

          For example, if you set the Execution time parameter to May 17, 2022, 17:30:50 and the Time Zone parameter to (GMT+08:00) Asia/Shanghai, the command was run only once at 17:30:50 on May 17, 2022 (UTC+8).

        • Run on Clock-based Schedule Cron Expression: Use a cron expression to specify a schedule on which you want to run the command. Specify a schedule that is accurate to seconds, minutes, hours, day of the month, month, day of the week, or year, and select a time zone from the Time Zone drop-down list. The system calculates the schedule based on the cron expression and the time zone and runs the command as scheduled. This option provides flexibility and is suitable for scenarios in which you want to execute command tasks on a schedule. For more information about cron expressions, see Cron expressions.

          Note

          The minimum interval must be 10 seconds or longer and cannot be shorter than the timeout period of scheduled executions.

          For example, if you set the Execution Frequency parameter to 0 0 12 ? * WED 2022 and the Time Zone parameter to (GMT+08:00) Asia/Shanghai, the system runs the command at 12:00:00 every Wednesday in 2022 (UTC+8).

      Username

      Specify a username that you want to use to run the command on ECS instances.

      For security purposes, we recommend that you run Cloud Assistant commands as a regular user based on the principle of least privilege. For more information, see Run Cloud Assistant commands as a regular user.

      By default, Cloud Assistant commands are run by the root user on Linux instances and by the system user on Windows instances.

      Timeout

      Specify a timeout period for the task that runs the command on instances. If the command task times out, Cloud Assistant forcefully terminates the task process.

      Unit: seconds. By default, this parameter is set to the value of Timeout that you specified for the command.

      Note

      This timeout period is applicable only to the command task. When you change the timeout period of the command task, the timeout period of the command is not affected.

      Tag

      Specify Tag key and Tag value to add tags to the command task.

    2. In the Select Instance and Select Managed Instances sections, select one or more instances.

      If you have multiple instances, you can search for the instances on which you want to run the command by instance ID, name, or tag, and filter results by the status of Cloud Assistant Agent.

      Note

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

  6. Click Run.

Run a command by using Alibaba Cloud CLI

When you run a command by using Alibaba Cloud CLI, make sure that you have installed Alibaba Cloud CLI on your computer. The methods for installing Alibaba Cloud CLI vary based on operating systems. For information about how to install Alibaba Cloud CLI on different operating systems, see the following topics:

  1. (Optional) Check the instance status. If an instance is not in the Running (Running) state, call the StartInstance operation to start the instance.

    aliyun ecs StartInstance --InstanceId 'i-bp1f4f6o8lv0wqof****' 
    Note

    In this example, the values enclosed within single quotation marks ('') are example values of the parameters. You must change the values based on your actual conditions.

    For more information about the parameters, see StartInstance.

  2. (Optional) Call the DescribeCloudAssistantStatus operation to check whether Cloud Assistant Agent is installed on the instances.

    aliyun ecs DescribeCloudAssistantStatus --RegionId 'cn-hangzhou' \
    --InstanceId.1 'i-bp1f4f6o8lv0wqof****' 

    If Cloud Assistant Agent is installed on the instances, the value of CloudAssistantStatus is true in the response. Otherwise, call the InstallCloudAssistant operation to install Cloud Assistant Agent on the instances. For more information, see DescribeCloudAssistantStatus and InstallCloudAssistant.

  3. Call the InvokeCommand operation to run a created Cloud Assistant command on one or more instances.

    aliyun ecs InvokeCommand --RegionId 'cn-hangzhou' \
    --InstanceId.1 'i-bp1f4f6o8lv0wqof****' \
    --InstanceId.2 'i-bp137qu6142s3mhm****' \
    --CommandId 'c-hz018qp243j****'

    The following table describes the main parameters. For more information about the parameters, see InvokeCommand.

    Parameter

    Example

    Description

    RegionId

    cn-hangzhou

    The region ID.

    InstanceId.1

    i-bp1f4f6o8lv0wqof****

    The ID of the first instance on which to run the command.

    InstanceId.2

    i-bp137qu6142s3mhm****

    The ID of the second instance on which to run the command.

    CommandId

    c-hz018qp243j****

    The command ID.