yoqw/deploy.sh
2020-09-22 01:24:53 +08:00

77 lines
1.8 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_jar="$target_dir/lib/main.jar"
scp -P $port $jar $server:"${target_jar}_new"
ssh -p $port $server "$target_dir/bin/stop.sh;
mv $target_jar {$target_jar}_prev;
mv ${target_jar}_new $target_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.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"
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'
if [ "$1" == "cms" ]; then
ssh -p 4025 xiandou@localhost '/data/program/cms2/bin/stop.sh && /data/program/cms2/bin/start.sh'
fi
fi
popd > /dev/null