87 lines
1.9 KiB
Bash
Executable File
87 lines
1.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# get real path of softlink
|
|
get_real_path() {
|
|
local f="$1"
|
|
while [ -h "$f" ]; do
|
|
ls=`ls -ld "$f"`
|
|
link=`expr "$ls" : '.*-> \(.*\)$'`
|
|
if expr "$link" : '/.*' > /dev/null; then
|
|
f="$link"
|
|
else
|
|
f=`dirname "$f"`/"$link"
|
|
fi
|
|
done
|
|
echo "$f"
|
|
}
|
|
|
|
deploy_server() {
|
|
local server="$1"
|
|
local app="$2"
|
|
local jar="$3"
|
|
local port="$4"
|
|
if [ -z "$port" ]; then
|
|
port='22'
|
|
fi
|
|
|
|
local target_dir="/data/program/$app"
|
|
local target_lib_dir="$target_dir/lib"
|
|
local target_jar="$target_lib_dir/main.jar"
|
|
local classes_jar="$target_lib_dir/main-clasess.jar"
|
|
|
|
scp -P $port $jar $server:"$classes_jar"
|
|
ssh -p $port $server "
|
|
$target_dir/bin/stop.sh;
|
|
cd $target_lib_dir &&
|
|
unzip $classes_jar &&
|
|
zip -d $target_jar BOOT-INF/classes/* &&
|
|
zip -ur $target_jar BOOT-INF/classes &&
|
|
rm -rf BOOT-INF $classes_jar &&
|
|
$target_dir/bin/start.sh"
|
|
}
|
|
|
|
prg_path=$(get_real_path "$0")
|
|
echo "Script path [$prg_path]"
|
|
|
|
# Service Home
|
|
pushd $(dirname "$prg_path") > /dev/null
|
|
WORK_DIR=$(pwd)
|
|
echo "Work dir [$WORK_DIR]"
|
|
|
|
if [ -z "$1" ] && [ -z "$2" ]; then
|
|
echo 'Usage: ./deploy_classes.sh cms|fsagent|openapi test|prod [nb]'
|
|
exit 1
|
|
fi
|
|
|
|
APP=$1
|
|
|
|
if [ ! -d "$APP" ]; then
|
|
echo "App [$APP] is not valid maven module."
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! "$3" == "nb" ]; then
|
|
mvn -T 4C clean package -pl $APP -am -DskipTests
|
|
fi
|
|
|
|
TARGET_DIR=$APP/target
|
|
echo "Target dir [$TARGET_DIR]"
|
|
JAR=$(find "$TARGET_DIR" -maxdepth 1 -type f -name '*.jar' | grep -v 'sources.jar')
|
|
echo "JAR [$JAR] found"
|
|
|
|
zip -d $JAR \
|
|
BOOT-INF/lib/* \
|
|
META-INF/* \
|
|
org/springframework/*
|
|
|
|
if [ "$2" == "test" ]; then
|
|
echo "Deploy test."
|
|
deploy_server 'xiadou@118.24.251.131' $APP $JAR
|
|
elif [ "$2" == "prod" ]; then
|
|
echo "Deploy prod."
|
|
deploy_server 'xiandou@localhost' $APP $JAR 4025
|
|
fi
|
|
|
|
popd > /dev/null
|
|
|