All Products
Search
Document Center

Serverless App Engine:Configure a startup command

Last Updated:Dec 03, 2024

If you deploy an application by using an image or a code package in the Serverless App Engine (SAE) console, SAE starts containers by using the preset startup parameters of the container image or code package. If you want to configure custom settings, such as NGINX settings, before a container startup, or if you do not want to use the preset startup parameters, you can configure a startup command for your application in SAE to overwrite the preset parameter settings in an image file.

Background information

Before you create an image, the startup settings of containers are specified by the ENTRYPOINT or CMD command in the Dockerfile. When containers are started, the commands in the Dockerfile are preferentially run.

In this example, the following command is preset in the Dockerfile. When containers are started, the command is first run.

FROM ubuntu
ENTRYPOINT [nginx, '-g', 'daemon off;']                

Usage notes

You can configure a startup command when you create an application or when you deploy an application.

  • When you create an application, you can configure a startup command in the Deployment Configurations step of the Create Application page.

  • When you deploy an application, perform the following operations based on the number of instances in the application:

    • If the number of instances is greater than or equal to 1, click Deploy Application on the Basic Information page of the application. On the Deploy Application page, configure the parameters based on your business requirements.

    • If the number of instances is 0, click Modify Application Configurations on the Basic Information page of the application. On the Modify Application Configurations page, configure the parameters based on your business requirements.

      Note

      After the configurations of an application are modified, the configurations take effect the next time the number of instances in the application exceeds 0.

The steps to configure a startup command are similar regardless of the method that you use to deploy an application and the environment in which you deploy the application. However, the startup command and parameters that you can configure vary. Follow the on-screen instructions to proceed.

Configure a startup command when you deploy an application by using an image

In this example, a Java application is created. In the Deployment Configurations step, set the Application Deployment Method parameter to Image. In the Startup Command Settings section, configure the parameters. If you set the Startup Mode parameter to Docker Native, run the command that is shown in the following figure.

设置镜像部署启动命令

In this example, the ENTRYPOINT: [nginx, '-g', 'daemon off;'] command is configured. The following table describe the parameters in the command.

Parameter

Description

Startup Command

Enter a startup command. Example: nginx.

Startup Parameter

Enter a startup parameter. Example: -g.

Click + Add to add a parameter in a new line. Example: daemon off.

Configure a startup command when you deploy an application by using a JAR package

To start or run a Java application, you must configure a startup command and parameters, such as the Java virtual machine (JVM) and garbage collection (GC) parameters.

SAE automatically compiles the JAR package that you uploaded into an image, uploads the image to the image repository, and then runs the application as containers. During the compilation, SAE uses the built-in startup command and parameters, and specifies the storage path of the JAR package. You can log on to the SAE console to modify the default startup command and command parameters.

Important

If the startup command is invalid, the application fails to be created. If you are not familiar with the ENTRYPOINT or CMD command in the Dockerfile, we recommend that you do not configure a custom startup command and parameters or modify the default startup command and parameters.

In this example, a Java application is created. In the Deployment Configurations step, set the Application Deployment Method parameter to Deployment with JAR Packages. In the Startup Command Settings section, configure the parameters. The following figure shows the configurations of a sample startup command.

配置启动命令

Parameter

Description

Default Startup Command

The default startup command that is provided by SAE.

options Settings

The JVM parameters. For more information, see JVM options, Tuning Java Virtual Machines, and JVM Tuning: How to Prepare Your Environment for Performance Tuning.

If you want to use the remote debugging feature of the application, configure the following command according to the JDK version:

  • JDK 11 and JDK 17

    -agentlib:jdwp=transport=dt_socket,address=*:9000,server=y,suspend=n
  • Other JDK versions

    -agentlib:jdwp=transport=dt_socket,address=9000,server=y,suspend=n

where:

  • transport: the method that is used to transmit data during remote debugging.

  • address: the IP address of the client from which the O&M engineer performs remote debugging. Use the port that you specified when you enabled remote debugging. For more information, see Perform remote debugging.

Important

The startup command that is used when you deploy an application by using a WAR package is different from the startup command that is used when you deploy an application by using a JAR package. We recommend that you do not use the same startup command when you deploy applications by using different methods. You can use the preceding remote debugging command to debug an application regardless of whether you use a WAR package or a JAR package to deploy the application.

args Settings

The redirection parameter for standard output (stdout) and standard errors (stderr). Example: 1>>/tmp/std.log>&1.

options Shortcut Settings

This parameter is available only if you set the Java Environment parameter to Dragonwell.

  • Enable Performance Improvement for Microservices (Wisp2 Coroutine): By default, this feature is enabled. This feature improves the performance of multiple threads at runtime.

  • Enable Application Memory Optimization (G1): By default, this feature is enabled. This feature reduces the GC time in scenarios in which multiple CPUs and large-capacity memory are required. This feature is also suitable for GC optimization and big data scenarios.

  • Enable Application Startup Acceleration (Quickstart): This parameter is available only if you set the Java Environment parameter to Dragonwell 11. You can select Enable Application Startup Acceleration (Quickstart) and configure the Persistent Storage Directory parameter to improve the application startup efficiency.

    Important

    Before you select Enable Application Startup Acceleration (Quickstart), you must configure a File Storage NAS file system. For more information, see Configure NAS storage.

  • Persistent Storage Directory: This parameter is required if you select Enable Application Startup Acceleration (Quickstart). To accelerate application startup across instances, we recommend that you set the Persistent Storage Directory parameter to the directory or subdirectory of the NAS file system. For information about how to configure a NAS file system, see Configure NAS storage.

Configure a startup command when you deploy an application by using a WAR package

In this example, a Java application is created. In the Deployment Configurations step, set the Application Deployment Method parameter to Deployment with WAR Packages. In the Startup Command Settings section, configure the parameters. The following figure shows the configurations of a sample startup command.

配置启动参数-WAR包部署应用到SAE

Parameter

Description

Default Startup Command

The default startup command that is provided by SAE.

options Settings

The JVM parameters. For more information, see JVM options, Tuning Java Virtual Machines, and JVM Tuning: How to Prepare Your Environment for Performance Tuning.

If you want to use the remote debugging feature of the application, configure the following command according to the JDK version:

  • JDK 11 and JDK 17

    -agentlib:jdwp=transport=dt_socket,address=*:9000,server=y,suspend=n
  • Other JDK versions

    -agentlib:jdwp=transport=dt_socket,address=9000,server=y,suspend=n

where:

  • transport: the method that is used to transmit data during remote debugging.

  • address: the IP address of the client from which the O&M engineer performs remote debugging. Use the port that you specified when you enabled remote debugging. For more information, see Perform remote debugging.

Important

The startup command that is used when you deploy an application by using a WAR package is different from the startup command that is used when you deploy an application by using a JAR package. We recommend that you do not use the same startup command when you deploy applications by using different methods. You can use the preceding remote debugging command to debug an application regardless of whether you use a WAR package or a JAR package to deploy the application.

options Shortcut Settings

This parameter is available only if you set the Java Environment parameter to Dragonwell.

  • Enable Performance Improvement for Microservices (Wisp2 Coroutine): By default, this feature is enabled. This feature improves the performance of multiple threads at runtime.

  • Enable Application Memory Optimization (G1): By default, this feature is enabled. This feature reduces the GC time in scenarios in which multiple CPUs and large-capacity memory are required. This feature is also suitable for GC optimization and big data scenarios.

  • Enable Application Startup Acceleration (Quickstart): This parameter is available only if you set the Java Environment parameter to Dragonwell 11. You can select Enable Application Startup Acceleration (Quickstart)and configure the Persistent Storage Directory parameter to improve the application startup efficiency.

    Important

    Before you select Enable Application Startup Acceleration (Quickstart), you must configure a File Storage NAS file system. For more information, see Configure NAS storage.

  • Persistent Storage Directory: This parameter is required if you select Enable Application Startup Acceleration (Quickstart). To accelerate application startup across instances, we recommend that you set the Persistent Storage Directory parameter to the directory or subdirectory of the NAS file system. For information about how to configure a NAS file system, see Configure NAS storage.

Configure a startup command when you deploy an application by using a ZIP package

In this example, a Python application is created. In the Deployment Configurations step, set the Application Deployment Method parameter to Deployment with ZIP Packages. In the Startup Command Settings section, configure the parameters. If you set the Startup Mode parameter to Shell Script, run the following command:

gunicorn -w 3 -b 0.0.0.0:8080 app.hello:app

sc_startup_command_for_ptyhon_application_via_shell