yoqw/lib/ops/install-springboot-app/install-springboot-app.sh
2020-07-23 20:10:53 +08:00

59 lines
1.3 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"
}
install_server() {
local SERVER="$1"
local APP="$2"
local PORT="$3"
if [ -z "$PORT" ]; then
PORT='22'
fi
local BASE_DIR='/data/program'
local TARGET_DIR="$BASE_DIR/$APP"
local LOGS_DIR="$BASE_DIR/logs/$APP"
ssh -p "$PORT" "$SERVER" "mkdir -p $TARGET_DIR"
ssh -p "$PORT" "$SERVER" "tar -xzv -C $TARGET_DIR" < springboot-app.tar.gz
ssh -p "$PORT" "$SERVER" "mkdir -p $LOGS_DIR && ln -sf $LOGS_DIR $TARGET_DIR/logs"
}
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: ./install-springboot-app.sh cms|fsagent test|prod'
exit 1
fi
if [ "$2" == "test" ]; then
echo "Install test."
install_server 'appweb@118.24.251.131' $1
elif [ "$2" == "prod" ]; then
echo "Install prod."
install_server 'xiandou@113.87.175.72' $1 '51022'
fi
popd > /dev/null