Manage custom extensions in batches

更新时间:
复制 MD 格式

You can use OOS (CloudOps Orchestration Service) to manage software in batches. In addition to installing software through Alibaba Cloud agents or package management tools, OOS also allows you to install custom extensions. A custom extension can be a standard software package, such as an RPM, DEB, or MSI file. This feature lets you efficiently manage software across different platforms and architectures. This topic describes how to create and manage custom extensions in batches.

Prerequisites

  1. You need an ECS instance deployed in a VPC.

    For more information, see Create an instance by using the wizard. You can install or uninstall custom extensions only on instances in a VPC. Make sure that the network type of your ECS instance is VPC.

    Confirm that the network type is VPC

    1. Log on to the ECS console.

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

    3. Find the target ECS instance and check the Network Type column to confirm that the instance is in a VPC.

  2. You need a RAM role attached to your ECS instance.

    For more information, see Step 1: Create a RAM role. When you create the role, take note of the following parameter settings:

    1. Create a custom permission policy.

      For more information, see Create a custom permission policy. The RAM role must include the permissions in the following policy:

      Permission policy 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 normal service role. Take note of the following parameter settings:

      • For Alibaba Cloud Service, select Alibaba Cloud Service.

      • For Role Type, select Normal Service Role.

      • For Elastic Compute Service, select Elastic Compute Service.

    3. Grant permissions to the RAM role.

      When you grant a permission to a RAM role, for Permission Policy, select the custom policy that you created in 2.a Create a custom permission policy. For more information, see Manage the permissions of a RAM role.

    4. Attach the RAM role to the ECS instance.

      For the RAM Role parameter, select the role that you created and configured in the previous steps. For more information, see Step 1: Create a RAM role.

  3. You need an OSS bucket to store your custom extensions.

    For more information, see Create buckets. When you select a Region, you must choose Region-specific and select the same region where you use OOS.

Create a custom extension

  1. Go to the OOS console, choose Server Management > Extensions in the left-side navigation pane, and then click the Custom Extensions tab.

  2. Click Create Custom Extension. In the Basic Information section, configure the parameters, and then click Next Step.

    Custom extensions are visible only to you. You can use your account to install or uninstall them. The following table describes the key parameters.

    Parameter

    Description

    Extension Type

    The category of the extension. You can select Driver, Performance Acceleration, Agent, or Application based on your business needs.

    Version Description

    The first version that you create is automatically labeled V1. After the extension is created, you can view the version number and details on its details page.

    Note

    To modify the extension, you must use the update feature. When you update an extension, the system automatically creates a new version, such as V2.

    Supported Scope

    Defines the conditions for using the extension, including the supported instance families, image types, and operating system platforms or versions. After you set this scope, users can select only applicable extensions when installing extensions from the ECS buy page or the ECS instance details page.

    Command Parameter

    Specifies the input parameters for the extension commands. You can add multiple parameters. The parameter type can be string, numeric, or Boolean. You can define the parameter name, default value, and description. After you set the installation command parameters, users must provide values for these parameters when installing the extension from the ECS buy page or the ECS instance details page.

  3. In the Extension Configuration step, configure the parameters.

    Note

    You can add multiple extension configurations. When you later install the extension, the system finds the configuration that matches the operating system and architecture of the ECS instance. The system then downloads the corresponding software package and runs the specified installation or uninstallation script to complete the process.

    脚本.png

    The following code provides examples of an Installation Execution Script and an Uninstallation Execution Script:

    • Example installation execution script

      #!/bin/bash
      #######  Notes on the installation script template for a single-process software package  #########
      #1. This script runs in the root directory by default. For Linux, the default directory is /root.
      #2. After the software is successfully installed, the remote download path is deleted by default.
      #3. We recommend that you add your custom logic in the job_start function.
      #4. You must store the process ID of the software package in the specified path.
      
      #######  error code specification  #########
      # Please update this documentation if new error codes are added.
      # 1   => Installation failed.
      # 2   => Health check failed.
      # 3   => Failed to record process ID.
      # 4   => User shell script failed.
      
      function user_shell() {
          # Custom installation script START
          $nohup java -jar demo-1.0.0-SNAPSHOT.jar > /demo.log 2>&1 &
          # Custom installation script END
      }
      
      ##### You can call this function when the script starts to print the timestamp and PID and record the process ID to the specified path.
      function job_start() {
          user_shell
          if [ $? -ne 0 ]; then
              exit4
          else
              # Do not delete this constraint.
              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 PID storage path: $pidPath"
              fi
              echo "$pid" > "$pidPath/main_process_id"
              if [ $? -ne 0 ]; then
                  exit3
              fi
          fi
      }
      
      ##### In this function, check whether the service is running. For example, you can check the process or run a curl command to an HTTP address.
      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
      }
      
      
      ##### A return value of 0 indicates success. A non-zero value indicates failure.
      function main() {
          job_start
          if [ $? -ne 0 ]; then
              exit1
          fi
          check_health
          if [ $? -ne 0 ]; then
              exit2
          fi
      }
      
      ##### OOS automatically records logs for triggered executions.
      main
    • Example uninstallation execution script

      #!/bin/bash
      ##### You can call this function when the script starts to print the current timestamp and PID.
      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
  4. Click Create.

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

    我的软件.png

Install a custom extension

  1. Go to the OOS console, choose Automated Tasks > Common O&M Tasks > Batch Software Management in the left-side navigation pane, and then click Create.

  2. On the Create Batch Software Management Task page, configure the parameters and click Create.

    • For Operation, select Install.

    • For Extension Name, select Custom Extensions, and then select the custom extension that you want to install.

    • For Select Instances, select Manually Select Instances. In the instance list, select the ECS instances where you want to install the custom extension. Ensure that the instances are deployed in a VPC.

  3. In the Parameter Confirmation dialog box, verify the parameters and click OK to create the execution.

    After the execution is created, you can go to the Task Execution Management page to view the custom extension's installation status in the task list.

    任务执行管理.png

Uninstall a custom extension

  1. Go to the OOS console, choose Automated Tasks > Common O&M Tasks > Batch Software Management in the left-side navigation pane, and then click Create.

  2. On the Create Batch Software Management Task page, configure the parameters and click Create.

    • For Operation, select Uninstall.

    • For Extension Name, select Custom Extensions, and then select the custom extension that you want to uninstall.

    • For Select Instances, select Manually Select Instances and select the ECS instances from which you want to uninstall the custom extension.

  3. In the Parameter Confirmation dialog box, verify the parameters and click OK to create the execution.

    After the execution is created, you can go to the Task Execution Management page to check the task list and confirm that the custom extension is uninstalled.

    任务执行管理.png