Command command guidelines

更新时间:
复制 MD 格式

This topic describes Command commands and provides examples of how to deploy Java Web Tomcat, Java Fatjar, Spring Boot, and Go applications using Cloud Toolkit.

Command command usage notes

Because of limitations in ECS Cloud Assistant, you must follow specific rules when you use Command commands to deploy applications with Alibaba Cloud Toolkit. Note the following:

  • By default, Command commands execute under the root account. To change the user, you can switch the user within the script.

  • Do not use the sleep command in scripts.

  • Do not use non-breaking commands, such as tail -f, in scripts.

Command commands for Java Web Tomcat applications

This example deploys an application to an ECS instance. If you use the /root/tomcat/ folder on a Linux system as the base folder for the Java application, you can deploy the WAR package of the Java Web application to the /root/tomcat/webapps folder.

The corresponding Command configuration is:

sh /root/restart.sh
            

The restart.sh script is:

source /etc/profile
netstat -anp|grep port_number|awk '{printf $7}'|cut -d/ -f1 |xargs kill -9 || true
rm -rf /root/tomcat/webapps/javademo
sh /root/tomcat/bin/startup.sh
            

You can use /etc/profile to set environment variables. The following is an example:

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
export JAVA_HOME=/usr/share/jdk1.8.0_14
export PATH=$JAVA_HOME/bin:.....
            

Command commands for Java Fatjar applications

If you use the /root/javademo folder on a Linux system as the base folder for the Java application, you can deploy the application's JAR package to the /root/javademo folder.

The corresponding Command configuration is:

sh /root/sh/restart-java.sh
            

The restart-java.sh script is:

source /etc/profile
netstat -anp|grep port_number|awk '{printf $7}'|cut -d/ -f1 |xargs kill -9 || true
nohup java -jar /root/javademo/javademo-0.0.1-SNAPSHOT.jar > nohup.log 2>&1 &
            

Command commands for Spring Boot applications

If you use the /root/springbootdemo folder on a Linux system as the base folder for the Spring Boot application, you can deploy the application's JAR package to the /root/springbootdemo folder.

The corresponding Command configuration is:

sh /root/sh/restart-springboot.sh
            

The restart-springboot.sh script is:

source /etc/profile
netstat -anp|grep port_number|awk '{printf $7}'|cut -d/ -f1 |xargs kill -9 || true
nohup java -jar /root/springbootdemo/springbootdemo-0.0.1-SNAPSHOT.jar > nohup.log 2>&1 &
            

Command commands for Go applications

If you use the /root/godemo folder on a Linux system as the base folder for the Go application, you can deploy the application's executable file to the /root/godemo folder.

The corresponding Command configuration is:

sh /root/sh/restart-go.sh
            

The restart-go.sh script is as follows:

source /etc/profile
pkill -f 'godemo'
chmod 755 /root/godemo/godemo; 
sh -c /root/godemo/godemo
            

FAQ

Notes on using Command commands