Configuring the Lifecycle of an Application
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: started using this startup command.
- Post-start processing: triggered after an application is started.
- Pre-stop processing: triggered before an application is stopped.
Procedure
- When deploying an application component, expand Advanced Settings > Component Configurations on the Configure Component page.
- Click Startup Command to set the command and parameter. Rules are as follows:
A Docker image has metadata related to the stored 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 creation, the default Entrypoint and CMD are overwritten during image creation. The rules are as follows:
Table 1 Application commands and 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]
- Set Lifecycle on the Lifecycle tab page. The following table describes parameters.
Table 2 Container lifecycle parameters Parameter
Description
CLI Mode
Set the specified command in the application to the command to be executed. The command format is Command Args[1] Args[2]…. The command is a system command or a user-defined executable program. If no path is specified, you need to find the executable program in the default path. To execute multiple commands, you are advised to write the commands to the script for execution.
For example, the following commands need to be executed:
exec: command: - /install.sh - install_agent
Enter /install install_agent in the script.
This command indicates that install_agent needs to be executed after the container is created successfully.
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 resides.
- Set Pre-stop Processing on the Lifecycle tab page. For parameter description, see Table 2.
Last Article: Setting Application Environment Variables
Next Article: Configuring Data Storage
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.