Alibaba Cloud Toolkit Command Writing Guide

This article provides the best practice for writing commands when you are using the Alibaba Cloud Toolkit plug-in to deploy the following applications:

  • Standard Java Web Tomcat applications
  • Standard Java Fatjar applications
  • Standard Spring Boot applications
  • Standard Go applications

Standard Java Web Tomcat Applications

As shown in the preceding figure, assume that the /root/tomcat/ in the Linux system is the root directory of a Tomcat application. We need to deploy the WAR package (javademo.war) of the Java Web application to the /root/tomcat/webapps directory.

The corresponding command configuration is as follows:

sh /root/sh/restart-tomcat.sh

The content of the restart-tomcat.sh script is as follows:

source /etc/profile
killall java
rm -rf /root/tomcat/webapps/javademo
sh /root/tomcat/bin/startup.sh

The /ect/profile file is used to configure environment variables, and contains content similar to the following:

# 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:.....

Standard Java Fatjar Applications

Assume that the /root/javademo directory in the Linux system is used as the root directory of a Java application. We need to deploy the jar package of the Java application to the /root/javademo directory.

The corresponding command configuration is as follows:

sh /root/sh/restart-java.sh

The content of the restart-java.sh script is as follows:

source /etc/profile
killall java
nohup java -jar /root/javademo/javademo-0.0.1-SNAPSHOT.jar > nohup.log 2>&1 &

Standard Spring Boot Applications

Assume that the/root/springbootdemo directory of the Linux system is used as the root directory of a Spring Boot application. We need to deploy the jar package (springbootdemo-0.0.1-SNAPSHOT.jar) of the Spring Boot application to the /root/springbootdemo directory.

The corresponding command configuration is as follows:

sh /root/sh/restart-springboot.sh

The content of the restart-springboot.sh script is as follows:

source /etc/profile
killall java
nohup java -jar /root/springbootdemo/springbootdemo-0.0.1-SNAPSHOT.jar > nohup.log 2>&1 &

Standard Go Applications

Assume that the /root/godemo directory in the Linux system is used as the root directory of a Go application. We need to deploy the executable file (godemo) of the Go application to the /root/godemo directory.

The corresponding command configuration is as follows:

sh /root/sh/restart-go.sh

The content of the restart-go.sh script is as follows:

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

Original Source

https://www.alibabacloud.com/blog/alibaba-cloud-toolkit-command-writing-guide_594999?spm=a2c41.13111833.0.0

Written by

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store