Updated on 2024-08-05 GMT+08:00

Configuring the Lifecycle of a Component

For container-deployed components, ServiceStage provides callback functions for the lifecycle management of applications. For example, if you want an application component to perform a certain operation before stopping, you can register a hook function.

ServiceStage provides the following lifecycle callback functions:

  • Startup command: used to start a container.
  • Post-start processing: triggered after an application is started.
  • Pre-stop processing: triggered before an application is stopped.

Procedure

  1. During component deployment, choose Advanced Settings > Deployment Configuration in the Advanced Settings area.
  2. Click Startup Command to set Command and Parameter for the container.

    A Docker image has metadata that stores image information. If no Lifecycle command or parameter is set, the container runs the default command and parameter provided during image creation. The Docker defines the default command and parameter as CMD and Entrypoint. For details about the two fields, see Entrypoint Description and CMD Description.

    If the running command and parameter of the application are set during application component deployment, the default Entrypoint and CMD will be overwritten during image building. Table 1 describes the rules.

    Table 1 Startup command parameters

    Image Entrypoint

    Image CMD

    Application Running Command

    Application Running Parameter

    Final Execution

    [touch]

    [/root/test]

    Not set

    Not set

    [touch /root/test]

    [touch]

    [/root/test]

    [mkdir]

    Not set

    [mkdir]

    [touch]

    [/root/test]

    Not set

    [/opt/test]

    [touch /opt/test]

    [touch]

    [/root/test]

    [mkdir]

    [/opt/test]

    [mkdir /opt/test]

  3. Click Lifecycle and set Post-Start and Pre-Stop parameters. Table 2 describes the parameters. Select one of the parameters.

    Table 2 Container lifecycle parameters

    Parameter

    Description

    CLI mode

    Command to be executed in the component instance. The command format is Command Args[1] Args[2]…. Command is a system command or a user-defined executable program. If no path is specified, an executable program in the default path will be selected. If multiple commands need to be executed, write the commands into a script for execution.

    For example, the following commands need to be executed:

    exec: 
      command: 
      - /install.sh 
      - install_agent

    Write /install.sh install_agent in the script.

    This command indicates that the agent will be installed after the component is deployed.

    HTTP request mode

    HTTP call request. The related parameters are described as follows:

    • Path: (optional) URL of a request.
    • Port: (mandatory) request port.
    • Host Address: (optional) IP address of the request. The default value is the IP address of the node where the application is located.