Configuring the Startup Command and Lifecycle of a Component
For container-deployed components, ServiceStage provides callback functions for the lifecycle management during and after application component startup. For example, if you want an application component to perform a certain operation before stopping, you can register a hook function.
Lifecycle Callback Functions
ServiceStage provides the following lifecycle callback functions:
- Startup command: corresponds to the ENTRYPOINT startup command of Docker, and is used to start an application component.
- Post-start processing: triggered after an application component is started.
- Pre-stop processing: triggered before an application component is stopped (Terminated), not when an application component exits (Completed) due to execution completion.
Configuring the Startup Command and Lifecycle of a Component
- Choose Container Settings.
- 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]
- Command: Enter an executable command, for example, /run/server.
If there are multiple commands, you are advised to run /bin/sh or other shell commands. Other commands are used as parameters.
- Parameter: Enter a parameter that controls the container running command, for example, --port=8080. If there are multiple parameters, separate them in different lines.
- Command: Enter an executable command, for example, /run/server.
- Click Lifecycle and set Post-start Processing and Pre-stop Processing.
- Set Post-start Processing.
Table 2 describes the Post-start Processing parameters. Select either of the processing modes.
Table 2 Post-start Processing parameters Processing Mode
Command
CLI mode
Command to be executed in the component instance.
The command format is Command Args[1] Args[2]..... Command is a system command (bash mode) or a user-defined executable program (binary mode). If no path is specified, the system searches for an executable program in the default path.
To run multiple commands, write them in different lines or into a script.
NOTE:Commands that are executed in the background or asynchronously are not supported.
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 install.sh will be executed after the component is deployed.
HTTP request mode
HTTP call request.
- Path: (optional) URL of a request. Example: /nginx.
- Port: (mandatory) request port. Example: 80.
- Host Address: (optional) IP address of the request. The default value is the IP address of the node where the application is located. Example: 127.0.0.1.
- Set Pre-stop Processing.
Table 3 describes the Pre-stop Processing parameters. Select either of the processing modes.
Table 3 Pre-stop Processing parameters Processing Mode
Command
CLI mode
Command to be executed in the component instance.
The command format is Command Args[1] Args[2]..... Command is a system command (bash mode) or a user-defined executable program (binary mode). If no path is specified, the system searches for an executable program in the default path.
To run multiple commands, write them in different lines or into a script.
For example, the following commands need to be executed:
exec: command: - /uninstall.sh - uninstall_agent
Enter /uninstall.sh uninstall_agent in the script. This command indicates that uninstall.sh will be executed before the component is deleted or stopped.
HTTP request mode
HTTP call request.
- Path: (optional) URL of a request. Example: /nginx.
- Port: (mandatory) request port. Example: 80.
- Host Address: (optional) IP address of the request. The default value is the IP address of the node where the application is located. Example: 127.0.0.1.
- Set Post-start Processing.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot