All Products
Search
Document Center

CloudOps Orchestration Service:Manage custom software on multiple ECS instances at a time

Last Updated:Jun 14, 2024

CloudOps Orchestration Service (OOS) provides the Batch Software Management feature that allows you to manage not only Alibaba Cloud agents and software package management tools, but also custom software on Elastic Compute Service (ECS) instances. You can upload regular software packages such as .rpm, .deb, and .msi packages and manage the software for various operating systems and architectures in an efficient manner. This topic describes how to create and manage custom software on multiple ECS instances at a time.

Prerequisites

  1. The ECS instances on which you want to install or uninstall custom software reside in virtual private clouds (VPCs). You can install or uninstall custom software only on ECS instances that reside in VPCs.

  2. A Resource Access Management (RAM) role is assigned to each ECS instance and the policy in the following JSON script is attached to the RAM role. For more information, see Grant ECS access to resources of other Alibaba Cloud services by using instance RAM roles.

JSON script of the policy:

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "oos:GetTemplate"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "oss:GetObject",
                "oss:GetBucketAcl"
            ],
            "Effect": "Allow",
            "Resource": "*"
        }
    ]
}

Check the network type of an ECS instance

  1. Log on to the ECS console.

  2. In the left-side navigation pane, choose Instances & Images > Instances.

  3. Find the ECS instance that you want to manage and check whether the Network Type column displays VPC.

Assign a RAM role to an ECS instance

  1. Check whether a RAM role is assigned to the ECS instance. On the Instance page, click the ID of the ECS instance that you want to manage to view the instance details. image

  2. In the Other Information section, check the value of the RAM Role parameter. If this parameter is left empty, no RAM role is assigned to the instance.

  3. Log on to the RAM console.

  4. In the left-side navigation pane, choose Permissions > Policies. On the Policies page, click Create Policy. On the Create Policy page, click the JSON tab, copy the JSON script in the Prerequisites section of this topic, and then paste it to the script editor. image

  5. Click Next to edit policy information. On the page that appears, specify a policy name in the Basic information section and click OK. image

  6. In the left-side navigation pane, choose Identities > Roles. On the Roles page, click Create Role. On the Create Role page, set the Select Trusted Entity parameter to Alibaba Cloud Service in the Select Role Type step. Click Next.image

  7. In the Configure Role step, set the Role Type parameter to Normal Service Role and specify a role name. Select Elastic Compute Service as the trusted service. Click OK. image

  8. In the Finish step, click Add Permissions to RAM Role. On the page that appears, click Grant Permission on the Permissions tab. In the Grant Permission panel, click Custom Policy in the Select Policy section, select the policy that you create, and then click OK.

  9. Return to the Instances page of the ECS console.

  10. Find the ECS instance that you want to manage and choose More > Instance Settings > Attach/Detach RAM Role in the Actions column. image

  11. In the Attach/Detach RAM Role dialog box, select the RAM role that you create from the RAM Role drop-down list. image

  12. Click Confirm.

  13. Click the ID of the instance. On the Instance Details tab of the instance details page, check whether the RAM role is assigned to the instance.

image

Create an OSS bucket

  1. Log on to the Object Storage Service (OSS) console. Create an OSS bucket to store custom software in OOS.

  2. In the left-side navigation pane, click Buckets. On the Buckets page, click Create Bucket.

  3. In the Create Bucket panel, specify a bucket name.

  4. Set the Region parameter to the current region in which OOS provides services. Configure other parameters such as Storage Class based on your business requirements or use the default values.image

  5. Click OK.

Create custom software

  1. Log on to the OOS console.

  2. In the left-side navigation pane, click Extensions. On the Extensions page, click Create Custom Extension on the Custom Extensions tab.

  3. In the Basic Information step of the Create Custom Extension page, upload an extension image and enter the extension ID.

  4. Enter the extension name, extension description, and version description. Then, click Next Step.image

  5. In the Extension Configuration step, specify the operating system, architecture, path of the software package, installation script, and uninstallation script.image

    1. Sample installation script:

      #!/bin/bash
      #######  Usage notes of the installation script template for single-process software packages  #########
      #1. By default, this script is executed in the root directory. The default directory is /root for an ECS instance that runs Linux.
      #2. After the software is installed by using the script, the remote download path is deleted by default.
      #3. We recommend that you use the job_start function to customize the software.
      #4. The process ID of the software package must be stored in the specified path based on the process ID storage constraints.
      
      #######  error code specification  #########
      # Please update this documentation if new error code is added.
      # 1   => install fail
      # 2   => check health fail
      # 3   => record process id fail
      # 4   => user shell fail
      
      function user_shell() {
          # Run the custom installation script.
          $nohup java -jar demo-1.0.0-SNAPSHOT.jar > /demo.log 2>&1 &
          # Stop running the custom installation script.
      }
      
      ##### When the script starts to run, you can invoke this function to display the timestamp and process ID of the software package and store the process ID in the specified path. 
      function job_start() {
          user_shell
          if [ $? -ne 0 ]; then
              exit4
          else
              # This constraint cannot be deleted.
              now=$(date +'%Y-%m-%d %H:%M:%S')
              pid=$!
              echo "[$now][$pid] job_start"
              pidPath="/etc/aliyun"
              if [ ! -d $pidPath ]; then
                  mkdir -p /etc/aliyun
                  echo "Create the $pidPath path to store the process ID."
              fi
              echo "$pid" > "$pidPath/main_process_id"
              if [ $? -ne 0 ]; then
                  exit3
              fi
          fi
      }
      
      ##### Invoke this function to check whether the service runs as expected. You can check the process status or call the curl command in this function.
      function check_health() {
          now=$(date +'%Y-%m-%d %H:%M:%S')
          echo "[$now][$$] check_health"
      }
      
      function exit1() {
        echo "exit code 1, install fail"
        exit 1
      }
      
      function exit2() {
        echo "exit code 2, check health fail"
        exit 2
      }
      
      function exit3() {
        echo "exit code 3, record process id fail"
        exit 3
      }
      
      function exit4() {
        echo "exit code 4, user shell fail"
        exit 4
      }
      
      
      ##### If 0 is returned, the execution is successful. Otherwise, the execution fails.
      function main() {
          job_start
          if [ $? -ne 0 ]; then
              exit1
          fi
          check_health
          if [ $? -ne 0 ]; then
              exit2
          fi
      }
      
      ##### The execution is triggered. OOS automatically records logs for the execution.
      main
    2. Sample uninstallation script:

      #!/bin/bash
      ##### When the script starts to run, you can invoke the function to display the timestamp and the process ID. 
      function job_stop() {
          pid=$(cat /etc/aliyun/main_process_id)
          kill -9 $pid
          now=`date +'%Y-%m-%d %H:%M:%S'`
          echo "[$now][$pid] job_stop"
      }
      
      job_stop
      if [ $? -ne 0 ]; then
          echo "[$now][$$] job stop failed."
          exit 1
      fi
  6. Click Create.

Install custom software

  1. Before you install custom software, make sure that the destination ECS instances meet the prerequisites. You can install custom software by using the My Software or Batch Software Management feature. This example describes how to install custom software by using the Batch Software Management feature.

  2. On the Common O&M Tasks page, click Batch Software Management on the left and click Create. In the Select Task Type section of the Create Task Batch Software Management page, set the Software Type parameter to Extensions. Set the Operation parameter to Install and select the custom software to be installed. image

  3. Click Select Instances. In this example, select Manually Select Instances and select ECS instances that reside in VPCs from the instance list. Click Create.

    image

  4. In the Parameter Confirmation dialog box, confirm the parameters and click OK. You can check the installation status on the Batch Software Management page.image

Uninstall custom software

  1. Before you uninstall custom software, make sure that the destination ECS instances meet the prerequisites. In the left-side navigation pane, click Common O&M Tasks. On the Common O&M Tasks page, click Batch Software Management on the left.

  2. Click Create. In the Select Task Type section of the Create Task Batch Software Management page, set the Software Type parameter to Extensions.

  3. Set the Operation parameter to Uninstall and select the custom software to be uninstalled.

    image

  4. Click Select Instances. In this example, select Manually Select Instances and select ECS instances that reside in VPCs from the instance list.

    image

  5. Click Create.

    image

  6. Return to the Batch Software Management page to view the uninstallation status.