All Products
Search
Document Center

CloudOps Orchestration Service:Manage custom extensions in batches

Last Updated:Jan 09, 2025

CloudOps Orchestration Service (OOS) allows you to manage Alibaba Cloud agents, software management tools, and custom extensions on Elastic Compute Service (ECS) instances. Custom extensions support regular packages such as RPM, DEB, and MSI. This topic describes how to manage custom extensions on ECS instances in an effective manner by using OOS.

Preparations

  1. Create an ECS instance in a virtual private cloud (VPC).

    For more information, see Create an instance on the Custom Launch tab. Only an ECS instance in a VPC supports installing and uninstalling of custom extensions. Make sure that the ECS instance is deployed in a VPC.

    Make sure that the ECS instance is deployed in a VPC

    1. Log on to the ECS console.

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

    3. Find the ECS instance and make sure that VPC is displayed in the Network Type column.

  2. Create a RAM role and attach the role to the ECS instance.

    For more information, see Instance RAM roles. Take note of the following parameters:

    1. Create a custom policy.

      For more information, see Create a custom policy. Make sure that the policy in the following JSON script is attached to the RAM role.

      JSON script

      {
          "Version": "1",
          "Statement": [
              {
                  "Action": [
                      "oos:GetTemplate"
                  ],
                  "Resource": "*",
                  "Effect": "Allow"
              },
              {
                  "Action": [
                      "oss:GetObject",
                      "oss:GetBucketAcl"
                  ],
                  "Effect": "Allow",
                  "Resource": "*"
              }
          ]
      }
    2. Create a RAM role.

      For more information, see Create a regular service role. Take note of the following parameters:

      • Select Trusted Entity: Select Alibaba Cloud Service.

      • Role Type: Select Normal Service Role.

      • Select Trusted Service: Select Elastic Compute Service.

    3. Grant permissions to the instance RAM role.

      When you grant permissions to the RAM role, set Policy to the policy created in 2.a Create a custom policy. For more information, see Grant permissions to a RAM role.

    4. Attach the RAM role to the ECS instance.

      Select the RAM Role created in the preceding step. For more information, see Instance RAM roles.

  3. Create an Object Storage Service (OSS) bucket to store custom extensions.

    For more information, see Create buckets. When you specify Region, select Specify Region from the drop-down list and specify the same region as OOS.

Create a custom extension

  1. Log on to the OOS console.

  2. In the left-side navigation pane, choose Server Management > Extensions. On the page that appears, click the Custom Extensions tab.

  3. Click Create Custom Extension, set the Basic Information as prompted, and then click Next Step.

    Only you can view, install, and uninstall the custom extensions. Key parameters:

    Parameter

    Description

    Extension Type

    You can select Driver, Performance Acceleration, Application, and Agent.

    Version Description

    V1 is automatically used for the first creation. After the extension is created, you can view the version number and version details on the extension details page.

    Note

    You can use the extension update feature to modify the extension. When you update the extension, the system automatically generates the v2 version. Later versions are generated in the same manner.

    Extension Applicable Scope

    Specify the applicable conditions of the extension, including the supported instance families, image types, and operating systems and versions. After you specify this parameter, you can select only extensions that meet the conditions on the ECS buy page or details page.

    Command Parameter

    Specify the input parameters of the extension. You can add multiple parameters. The parameter type can be String, Numeric, or Boolean. You can define the parameter name, default value, and parameter description for each parameter. You must assign values to these parameters when you install the extension on the ECS buy page or the details page of an ECS instance.

  4. In the Extension Configuration step, set the parameters as prompted.

    Note

    You can add configurations for multiple extensions. When you install an extension on an ECS instance, the system finds the extension configuration that is applicable to the operating system and architecture of the ECS instance, downloads the specified software package, and then runs the installation or uninstallation script.

    脚本.png

    Examples for installation script and uninstallation script:

    • 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
    • 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
  5. Click Create.

    After the extension is created, you can view it on the Custom Extensions tab.

    我的软件.png

Install a custom extension

  1. Log on to the OOS console.

  2. In the left-side navigation pane, choose Automated Tasks > Common O&M Tasks > Batch Software Management. On the page that appears, click Create.

  3. On the Create Task Batch Software Management page, set the parameters as prompted and click Create.

    • Set Operation to Install.

    • Set Extension Name to Custom Extension and select the custom extension to be installed.

    • Set Select Instances to Manually Select Instances and select the ECS instances on which you want to install the extension. Make sure that the ECS instances are deployed in a VPC.

  4. In the Parameter Confirmation dialog box, confirm the parameters and click OK.

    After the custom extension is created, you can view the installation task on the Task Execution Management page.

    任务执行管理.png

Uninstall a custom extension

  1. Log on to the OOS console.

  2. In the left-side navigation pane, choose Automated Tasks > Common O&M Tasks > Batch Software Management. On the page that appears, click Create.

  3. On the Create Task Batch Software Management page, set the parameters as prompted and click Create.

    • Set Operation to Uninstall.

    • Set Extension Name to Custom Extension and select the custom extension to be uninstalled.

    • Set Select Instances to Manually Select Instances and select the ECS instances on which you want to uninstall the extension.

  4. In the Parameter Confirmation dialog box, confirm the parameters and click OK.

    After the custom extension is uninstalled, you can view the uninstallation task on the Task Execution Management page.

    任务执行管理.png