#!/bin/bash
APPS_HOME=${base_dir_to_be_installted}
INSTALL_DIR=”$APPS_HOME/”`date +%Y%m%d-%H%M`
SOURCE_HOME=`pwd`
synchronized(){
echo -e “\n\n\n######################\nMake newest\n######################”
set timeout 1
git reset –hard HEAD
git checkout master
expect -c”
set timeout 4
spawn git pull –all
expect ‘Password: ‘
send ${password}\r
expect eof”
return 0;
}
build() {
echo -e “\n\n\n######################\nBuild Source\n######################”
`set timeout 1`
profile=$2
if [ ! -n “$profile” ]; then
profile=”stage”
fi
echo -e “load [$profile] configuration”
mvn clean package -P”$profile”
return 0;
}
makeAppDir() {
echo -e “\n\n\n######################\nCreate install directory\n######################”
set timeout 1
currentDateTime=$INSTALL_DIR
if [ ! -d $INSTALL_DIR ]; then
mkdir $INSTALL_DIR
fi
return 0;
}
copy-bin(){
echo -e “\n\n\n######################\nCopy binary file to install directory\n#############”
set timeout 1
cd $SOURCE_HOME
cp -rf ./target/${built-jar-file} ./target/… ./target/… $INSTALL_DIR
cd $INSTALL_DIR
unzip -o ${built-jar-file} -d ${desired-loc-for unzip } ## unzip all for modifing easy
return 0;
}
relink(){
echo -e “\n\n\n######################\nCreate Symbolic Link\n######################”
set timeout 1
cd $APPS_HOME
#if [ -d “$APPS_HOME/default” ]; then
rm -rf “$APPS_HOME/default”
#fi
ln -s $INSTALL_DIR default
return 0;
}
killProcess(){
echo -e “\n\n\n######################\nKill Process previous run\n######################”
`set timeout 1`
processInfo=`ps -ef | grep java | grep ${identified process name} `
if [ ! -n “$processInfo” ]; then
echo -e “not found process”
fi
if [ -n “$processInfo” ]; then
arrayInfo=(${processInfo})
echo -e “kill -9 ${arrayInfo[1]}”
kill -9 ${arrayInfo[1]}
fi
return 0;
}
start(){
echo -e “\n\n\n######################\nStart Java App.\n######################”
`set timeout 1`
runStage=$1
cd “$APPS_HOME/default”
if [ ! -n “$runStage” ]; then
runStage=”bg”
fi
if [ “bg” = “$runStage” ]; then
nohup java -Xmx3096m -Xms3096m -Xss2048k -cp ${defailt-classpath}:${jar-location}/* ${main-class} –spring.config.location=file:${file1},file:${file2},file:${file3} > /dev/null 2>&1 &
fi
if [ “fg” = “$runStage” ]; then
java -Xmx3096m -Xms3096m -Xss2048k -cp ${defailt-classpath}:${jar-location}/* ${main-class} –spring.config.location=file:${file1},file:${file2},file:${file3},…..
fi
return 0;
}
case $1 in
build)
build $@
;;
sync)
synchronized
;;
start)
start $2
;;
kill)
killProcess
;;
*)
synchronized
build
makeAppDir
copy-bin
killProcess
relink
start
;;
esac
exit 0