Commit 9fb9661b authored by 杨伊博's avatar 杨伊博

add spring - mybatis package

parent f17d0e74
#!/bin/sh
#########################
# based on docker bin
packageName=$1
imageVersion=$2
dockerDestFolder=$3
env=$4
packageTZ=Asia/Shanghai
if [ "${packageName}" = "" ]; then
echo [ERROR] "Please provide image name as first param"
exit 1
fi
if [ "${imageVersion}" = "" ]; then
echo [ERROR] "Please provide image version as second param"
exit 1
fi
if [ "${dockerDestFolder}" = "" ]; then
echo [ERROR] "Please provide docker dest folder"
exit 1
fi
if [ "${env}" = "" ]; then
echo [ERROR] "Please provide env folder"
exit 1
fi
COUNT=`docker -v 2>&1 | grep 'version' | grep -v grep | wc -l`
if [ ${COUNT} != 1 ]; then
echo [ERROR] "Cannot find docker command"
exit 1
fi
echo [INFO] "Remove old image from docker repository..."
count=`docker images | grep "${packageName}" | grep "${imageVersion}" | wc -l`
if [ ${count} != 1 ]; then
echo [WARN] "image ${packageName} with version ${imageVersion} does not exist in docker repo"
else
docker rmi -f ${packageName}:${imageVersion}
fi
#generate Dockerfile dynamically
echo [INFO] "generating Dockerfile..."
warName=${packageName}-${imageVersion}.war
dateVersion=`date +%Y%m%d-%H%M%S`
#cat out to Dockerfile with content begin/end with EOF
cat > target/Dockerfile <<EOF
FROM debian:jessie
MAINTAINER Cliff Ma
COPY target/${warName} ${dockerDestFolder}/${dateVersion}/
ENV LANG C.UTF-8
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/${packageTZ} /etc/localtime && echo ${packageTZ} > /etc/timezone
RUN cd ${dockerDestFolder} \
&& ln -svnf ${dateVersion} current \
&& cd current \
&& touch docker-entrypoint.sh \
&& chmod +x docker-entrypoint.sh \
&& echo "/opt/apps/java/bin/java -jar ${dockerDestFolder}/current/*.war --spring.config.location=${dockerDestFolder}/current/env/application.properties >/dev/null 2>&1" > docker-entrypoint.sh
CMD .${dockerDestFolder}/current/docker-entrypoint.sh
EOF
# echo $TZ > /etc/timezone TO someString to one file.
# To set the right time.
# ENV TZ=Asia/Shanghai
# RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime && echo ${TZ} > /etc/timezone
# COPY conf/${env}/*.cer ${dockerDestFolder}/${dateVersion}/
#read Dockerfile
echo [INFO] "Building image..."
docker build -t ${packageName}:${imageVersion} -f target/Dockerfile . || exit 1
echo [INFO] "Exporting image to target folder..."
docker save ${packageName}:${imageVersion} > target/${packageName}-${imageVersion}.image
# EMBEDDED SERVER CONFIGURATION (ServerProperties)
server.port=8099
ms.db.driverClassName=com.mysql.jdbc.Driver
ms.db.url=jdbc:mysql://localhost:3306/msm?useSSL=false&useUnicode=true&characterEncoding=UTF-8
ms.db.username=root
ms.db.password=admin
ms.db.maxActive=500
\ No newline at end of file
#dev
################
##this property file is used to export shell session-scoped variables by command 'source *.properties'
################
#app root
prop_appRoot=/opt/apps
#run postinstall or not.(It is not used any more.)
prop_runPreinstall=false
prop_runPostinstall=false
#the package name
prop_package=springboot-mybatis
#the package version
prop_packageVersion=v1
#Your Java Home
prop_javaHome=/opt/apps/jdk/current
#owner and group for package
prop_ownerGroup=root:root
#folders which need to be created manually, the folder path will be relative to the app home folder
#seperate multi folders with space, don't forget the double "
prop_manualFolders="var/logs"
#manual folders mode
prop_manualFolderMode=777
###################
#Cluster config
###################
#used by install.sh to decide the install mode: cluster or single node(default false)
prop_isCluster=false
#single
prop_singleNode=springboot-mybatis-dev
#cluster
#all the nodes for the cluster, only is is accepted now
#seperated by , sign (EX di,d2,192.168.100.2)(If you want to use d1 d2,you must config the url in etc/local)
prop_clusterNodes=d1
###################
#springboot config
###################
prop_springbootWarName=${prop_package}
prop_springbootWarVersion=${prop_packageVersion}
prop_springbootProcessKeyWord=${prop_springbootWarName}-${prop_springbootWarVersion}.war
##############
#docker config
##############
prop_dockerDestFolder=${prop_appRoot}/${prop_package}
#docker daemon.(Docker is online or not.)
prop_dockerProcessKeyWord='docker'
#docker image name, e.g. cliff/nginx or nginx
prop_dockerImageName=${prop_package}
#docker image version, e.g. v1/v2 or latest
prop_dockerImageVersion=${prop_packageVersion}
#docker container count in each host server(1 in most situation.)
prop_dockerContainerCount=1
#docker config file mapping, multiple file mappings is supported so you can specify multiple -v xx:xx
prop_dockerConfigFileMapping="env:${prop_dockerDestFolder}/current/env"
prop_dockerLogFolderMapping="var/logs/nodexxx:${prop_dockerDestFolder}/var/logs"
prop_dockerUploadFolderMapping="uploadFiles:${prop_dockerDestFolder}/uploadFiles"
# It is not used any more. Add command `--net=host`
prop_dockerPortMappings=80:8081
##########################################
#seconds config before start and stop
##########################################
#the sleep time to wail for each node starting up after another, the unit is second
prop_startAllSleep=2
#the sleep time to wail for one node starting up.
#sometimes we start up server by backend job so we need wait some time
prop_startOneSleep=8
#stop node timeout, if timeout we will kill -9, the unit is second
prop_stopNodeTimeout=2
\ No newline at end of file
# Output pattern : date [thread] priority category - message
log4j.rootLogger=INFO, Console, R
#Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=logs/cmbms.log
log4j.appender.R.MaxFileSize=50kB
log4j.appender.R.MaxBackupIndex=5
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n
log4j.appender.ServerDailyRollingFile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.ServerDailyRollingFile.DatePattern='.'yyyy-MM-dd
log4j.appender.ServerDailyRollingFile.layout=org.apache.log4j.PatternLayout
#log4j.appender.ServerDailyRollingFile.Append=true
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %p [%c] %m%n
......@@ -13,7 +13,7 @@ prop_runPreinstall=false
prop_runPostinstall=false
#the package name
prop_package=epp-manager
prop_package=springboot-mybatis
#the package version
prop_packageVersion=v1
......
#!/bin/bash
#####################
# bash only
# usage ./package.sh
#####################
#declare -a: define an array
#declare -i: define an integer
declare -i index=1
declare -a envMap
declare -a formatMap=(["1"]="docker" ["2"]="springboot")
#GET THE URL OF CURRENT PATH
CURRENT_DIR=`dirname $0`
cd $CURRENT_DIR
#########################
# confirm the env
#########################
index=1
#scan the envs from conf/*
for i in env/* ; do
if [ -d ${i} ]; then
envMap["${index}"]="`basename ${i}`"
index=index+1
fi
done
#Print the choice
env=1
echo "Please choose the environment by typing the number [default ${env}]"
for i in ${!envMap[@]} ;do
echo [${i}]:${envMap[${i}]}
done
#Read the envTmp . Set The finalEnv. Pay Attention 'read' NOT 'Read'
read envTmp
# echo "${envTmp}"
if [ "${envTmp}" != "" ]; then
env=${envTmp}
fi
# echo "${env}"
finalEnv=${envMap[${env}]}
echo "${finalEnv}"
echo "[INFO] You are choosing environment: ${finalEnv}"
echo "[INFO] Set the env properties by env/${finalEnv}/env.properties"
#Load the env/${finalEnv}/env.properties
. env/${finalEnv}/env.properties
echo ""
echo ""
#########################
# confirm the format
#########################
format=1
for i in ${!formatMap[@]};do
echo [${i}]: ${formatMap[${i}]}
done
read formatTmp
if [ "${formatTmp}" != "" ]; then
format=${formatTmp}
fi
finalFormat=${formatMap[${format}]}
#########################
# confirm the package
#########################
finalPackage=${prop_package}
echo "[INFO] You are choosing package version: ${finalPackage}"
echo ""
echo ""
#########################
# confirm the version
#########################
finalPackageVersion=${prop_packageVersion}
echo "[INFO] You are choosing package version: ${finalPackageVersion}"
echo ""
echo ""
######################
# begin packing
######################
if [ -n "${finalFormat}" ] && [ "${finalFormat}" = "springboot" ]; then
##############################
# generate executable war file
##############################
#noneed.properties The .properties is outside the war . So it is no need any more.
theCommand="./war-it.sh ${finalPackage} ${finalPackageVersion} ${finalEnv} 'noneed.properties'"
echo [INFO] ${theCommand}
eval ${theCommand} || exit 1
else
##############################
# generate executable war file
##############################
theCommand="./war-it.sh ${finalPackage} ${finalPackageVersion} ${finalEnv} 'noneed.properties'"
echo [INFO] ${theCommand}
eval ${theCommand} || exit 1
#####################################
# generate docker image and export it
#####################################
theCommand="./docker-it.sh ${finalPackage} ${finalPackageVersion} ${prop_dockerDestFolder} ${finalEnv}"
echo [INFO] ${theCommand}
eval ${theCommand} || exit 1
fi
theCommand="./tar-it.sh ${finalEnv} ${finalPackage} ${finalPackageVersion} ${finalFormat}"
echo [INFO] ${theCommand}
eval ${theCommand} || exit 1
echo "[INFO] package is done successfully"
......@@ -6,7 +6,8 @@
<groupId>com.u</groupId>
<artifactId>springboot-mybatis</artifactId>
<version>1.0-SNAPSHOT</version>
<version>v1</version>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
......@@ -93,19 +94,23 @@
</dependencies>
<build>
<plugins>
<!-- to generate compressed package(tar package) specified by package.xml begin -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>${package}-${package.version}</finalName>
<ignorePermissions>true</ignorePermissions>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>${basedir}/scripts/${package.format}/common/package.xml</descriptor>
</descriptors>
<mainClass>${start-class}</mainClass>
</configuration>
</plugin>
<!-- to generate excutable jar/war with springboot style end -->
<!-- to generate executable jar/war with standard style begin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
......@@ -116,7 +121,7 @@
<mainClass>${start-class}</mainClass>
</manifest>
</archive>
<webappDirectory>${project.build.directory}/epp-manager</webappDirectory>
<webappDirectory>${project.build.directory}/springboot-mybatisma</webappDirectory>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<webResources>
<resource>
......@@ -138,30 +143,73 @@
</execution>
</executions>
</plugin>
<!-- to generate executable jar/war with standard style end -->
<!--test-->
<!-- to generate compressed package(tar package) specified by package.xml begin -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<finalName>${package}-${package.version}</finalName>
<ignorePermissions>true</ignorePermissions>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>${basedir}/scripts/${package.format}/common/package.xml</descriptor>
</descriptors>
</configuration>
</plugin>
<!-- to generate compressed package specified by package.xml end -->
<!-- resource插件, 设定编码,防止中文乱码 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<skip>true</skip>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<!--打依赖包-->
<!--test plugin begin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- method level parallel -->
<parallel>methods</parallel>
<threadCount>10</threadCount>
<argLine>-Dfile.encoding=UTF-8</argLine>
<!-- if want junit test before packaging, set it to be false -->
<!-- if the skipTests is false, and the junit test is wrong. The packaging will be stopped. -->
<skipTests>true</skipTests>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
<executions>
<execution>
<phase>package</phase>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>shade</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<!--&lt;!&ndash;打依赖包&ndash;&gt;-->
<!--<plugin>-->
<!--<groupId>org.apache.maven.plugins</groupId>-->
<!--<artifactId>maven-shade-plugin</artifactId>-->
<!--<version>2.3</version>-->
<!--<executions>-->
<!--<execution>-->
<!--<phase>package</phase>-->
<!--<goals>-->
<!--<goal>shade</goal>-->
<!--</goals>-->
<!--</execution>-->
<!--</executions>-->
<!--</plugin>-->
</plugins>
</build>
</project>
\ No newline at end of file
#ident "%W%"
#!/bin/sh -x
#SCRIPT_PATH must be defined firstly by calling script
echo "[INFO] calling common-env.sh"
if [ "${SCRIPT_PATH}" = "" ]; then
echo "[ERROR] SCRIPT_PATH is not defined in calling script"
exit 1
else
#############
# define own function
#############
#print out command into console (and log file if there is one) and then execute it
myexecute () {
local dt=`date +%Y-%m-%d\ %H:%M:%S`
local theCommand=${1}
echo "${dt}: [COMMAND] ${theCommand}"
if [ "${LOG}" != "" ]; then
echo "${dt}: [COMMAND] ${theCommand}" >> ${LOG}
fi
${theCommand}
return $?
}
myexecute2 () {
local dt=`date +%Y-%m-%d\ %H:%M:%S`
local theCommand=${1}
echo "${dt}: [COMMAND] ${theCommand}"
if [ "${LOG}" != "" ]; then
echo "${dt}: [COMMAND] ${theCommand}" >> ${LOG}
fi
eval ${theCommand}
return $?
}
#print out log into console (and log file if there is one)
mylog () {
local dt=`date +%Y-%m-%d\ %H:%M:%S`
local theLog=${1}
echo "${dt}: ${theLog}"
if [ "${LOG}" != "" ]; then
echo "${dt}: ${theLog}" >> ${LOG}
fi
}
#print out log into console (and log file if there is one), and transate \n into new line
mylog2 () {
local dt=`date +%Y-%m-%d\ %H:%M:%S`
local theLog=${1}
echo -e "${dt}: ${theLog}"
if [ "${LOG}" != "" ]; then
echo -e "${dt}: ${theLog}" >> ${LOG}
fi
}
#check it is a number or not
isNumber () {
var=${1}
if [ ${var} -eq ${var} 2> /dev/null ]
then
return 0
else
return 1
fi
}
############
# to export variables
############
#export all variables in env.properties
echo "[INFO] export all variables in env.properties"
if [ -f ${SCRIPT_PATH}/../env/env.properties ]; then
myexecute "source ${SCRIPT_PATH}/../env/env.properties"
elif [ -f ${SCRIPT_PATH}/../env/env.properties ]; then
myexecute "source ${SCRIPT_PATH}/../env/env.properties"
else
echo "[ERROR] cannot find env.properties"
exit 1
fi
fi
echo "[INFO] common-env.sh is done"
#exit 0 is not allowed here which is stop calling script from going on executing
#ident "%W%"
#!/bin/sh -x
###############################
## used for cluster install
###############################
#the path of this script when running
if cd "`dirname $0`"; then
SCRIPT_PATH=${PWD}
cd "${OLDPWD}" || exit 1
else
exit 1
fi
#call setenv
. ${SCRIPT_PATH}/setenv.sh
if [ "${prop_runPreinstall}" = "true" ]; then
myexecute "${SCRIPT_PATH}/preinstall.sh"
if [ $? != 0 ]; then
exit 1
fi
fi
mylog "[INFO] Begin install-cluster.sh"
APPVERSION=`date +%Y%m%d-%H%M%S`
LOG=/tmp/install-${prop_package}-${APPVERSION}.log
APPROOT=${prop_appRoot}
APPNAME=${prop_package}
APPHOME=${APPROOT}/${APPNAME}
HOSTNAME=`hostname`
CLUSTER_NODES=${prop_clusterNodes}
#replace ',' with space
CLUSTER_NODES=${CLUSTER_NODES//,/ }
#replace '"' with null
CLUSTER_NODES=${CLUSTER_NODES//\"/}
MANUAL_FOLDERS=${prop_manualFolders}
MANUAL_FOLDER_MODE=${prop_manualFolderMode}
for i in ${CLUSTER_NODES}
do
mylog ""
mylog "-----------------------------"
mylog "[INFO] Connecting to host ${i}"
#create app home folder and new version folder
myexecute "ssh -oStrictHostKeyChecking=no root@${i} mkdir -p ${APPHOME}/${APPVERSION}"
mylog "[INFO] Folder ${APPHOME}/${APPVERSION} is created successfully on host <<${i}>>"
#copy files from current host to another node by scp command
#-p preserves modification times, access times, and modes from the original file
mylog "[INFO] copying files to host <<${i}>> by scp command"
myexecute "scp -rp ${SCRIPT_PATH}/../* root@${i}:${APPHOME}/${APPVERSION}/"
mylog "[INFO] Copy is done!"
#change owner and group for app package
mylog "[INFO] changing owner and group recursively"
myexecute "ssh -oStrictHostKeyChecking=no root@${i} chown -R ${prop_ownerGroup} ${APPHOME}/${APPVERSION}/"
mylog "[INFO] Owner and group set up done!"
#create manual folders
if [ "${MANUAL_FOLDERS}" != "" ]; then
theCommand="ssh -oStrictHostKeyChecking=no root@${i} \"pwd "
for MANUAL_FOLDER in ${MANUAL_FOLDERS}
do
theCommand="${theCommand} && mkdir -p ${APPHOME}/${MANUAL_FOLDER}"
if [ "${MANUAL_FOLDER_MODE}" != "" ]; then
theCommand="${theCommand} && chmod -R ${MANUAL_FOLDER_MODE} ${APPHOME}/${MANUAL_FOLDER}"
fi
done
theCommand="${theCommand} \" "
myexecute2 "${theCommand}"
fi
#create soft link named 'current', -s:soft link -v:debug mode -n:treate link as normal file if it linking to a folder
#-f:force create it is already there
mylog "[INFO] Create soft link named 'current'"
myexecute "ssh -oStrictHostKeyChecking=no root@${i} ln -svnf ${APPHOME}/${APPVERSION} ${APPHOME}/current"
mylog "[INFO] Link creation is done!"
if [ "${prop_runPostinstall}" = "true" ]; then
myexecute "ssh -oStrictHostKeyChecking=no root@${i} ${APPHOME}/current/scripts/postinstall.sh"
mylog "[INFO] postinstall is done on node ${i}"
fi
mylog "--------------------------------"
done
mylog "[INFO] Cluster installation is done successfully, for more detail please check log ${LOG}"
exit 0
#ident "%W%"
#!/bin/sh -x
###############################
## used for single server install
###############################
#the path of this script when running
if cd "`dirname $0`"; then
SCRIPT_PATH=${PWD}
cd "${OLDPWD}" || exit 1
else
exit 1
fi
#call setenv
. ${SCRIPT_PATH}/setenv.sh
if [ "${prop_runPreinstall}" = "true" ]; then
myexecute ". ${SCRIPT_PATH}/preinstall.sh"
if [ $? != 0 ]; then
exit 1
fi
fi
mylog "[INFO] Begin install-single.sh"
APPVERSION=`date +%Y%m%d-%H%M%S`
LOG=/tmp/install-${prop_package}-${APPVERSION}.log
APPROOT=${prop_appRoot}
APPNAME=${prop_package}
APPHOME=${APPROOT}/${APPNAME}
HOSTNAME=`hostname`
SINGLE_NODE=${prop_singleNode}
MANUAL_FOLDERS=${prop_manualFolders}
MANUAL_FOLDER_MODE=${prop_manualFolderMode}
mylog ""
mylog "-----------------------------"
mylog "[INFO] Installing on host ${SINGLE_NODE}"
#create app home folder and new version folder
myexecute "mkdir -p ${APPHOME}/${APPVERSION}"
mylog "[INFO] Folder ${APPHOME}/${APPVERSION} is created successfully on host <<${SINGLE_NODE}>>"
#copy files from current folder to app home folder
#-p reserve the specified attributes (default: mode,ownership,timestamps)
mylog "[INFO] copying files to host <<${SINGLE_NODE}>> by cp command"
myexecute "cp -rp ${SCRIPT_PATH}/../* ${APPHOME}/${APPVERSION}/"
mylog "[INFO] Copy is done!"
#change owner and group for app package
mylog "[INFO] changing owner and group recursively"
myexecute "chown -R ${prop_ownerGroup} ${APPHOME}/${APPVERSION}"
mylog "[INFO] Owner and group set up done!"
#create manual folders
if [ "${MANUAL_FOLDERS}" != "" ]; then
for MANUAL_FOLDER in ${MANUAL_FOLDERS}
do
myexecute "mkdir -p ${APPHOME}/${MANUAL_FOLDER}"
if [ "${MANUAL_FOLDER_MODE}" != "" ]; then
myexecute "chmod -R ${MANUAL_FOLDER_MODE} ${APPHOME}/${MANUAL_FOLDER}"
fi
done
fi
#create soft link named 'current', -s:soft link -v:debug mode -n:treate link as normal file if it linking to a folder
#-f:force create it ignoring if it is already there
mylog "[INFO] Create soft link named 'current'"
myexecute "ln -svnf ${APPHOME}/${APPVERSION} ${APPHOME}/current"
mylog "[INFO] Link creation is done!"
mylog "--------------------------------"
mylog "[INFO] Installation is done successfully, for more detail please check log ${LOG}"
mylog "------------------------------------"
mylog "------------------------------------"
if [ "${prop_runPostinstall}" = "true" ]; then
myexecute ". ${SCRIPT_PATH}/postinstall.sh"
fi
exit 0
#ident "%W%"
#!/bin/sh -x
###############################
## used to install package
###############################
#the path of this script when running
if cd "`dirname $0`"; then
export SCRIPT_PATH=${PWD}
echo "[INFO] export SCRIPT_PATH=${SCRIPT_PATH}"
cd "${OLDPWD}" || exit 1
else
exit 1
fi
#call setenv
. ${SCRIPT_PATH}/setenv.sh
APPVERSION=`date +%Y%m%d-%H%M%S`
LOG=/tmp/install-${prop_package}-${APPVERSION}.log
mylog "[INFO] Begin install.sh"
#check it is a single node installation or a cluster installation
if [ "${prop_isCluster}" = "true" ]; then
mylog "[INFO] checked you are doing CLUSTER installation"
myexecute "${SCRIPT_PATH}/install-cluster.sh"
else
mylog "[INFO] checked you are doing SINGLE NODE installation"
myexecute "${SCRIPT_PATH}/install-single.sh"
fi
exit 0
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3
http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>0.1</id>
<formats>
<format>tar</format>
</formats>
<fileSets>
<fileSet>
<directory>scripts/${package.format}/manager</directory>
<outputDirectory>/scripts</outputDirectory>
<fileMode>0755</fileMode>
</fileSet>
<fileSet>
<directory>scripts/${package.format}/common</directory>
<outputDirectory>/scripts</outputDirectory>
<fileMode>0755</fileMode>
<includes>
<include>install-cluster.sh</include>
<include>install-single.sh</include>
<include>install.sh</include>
<include>common-env.sh</include>
</includes>
</fileSet>
<fileSet>
<directory>env/${package.environment}</directory>
<outputDirectory>/env</outputDirectory>
</fileSet>
</fileSets>
<files>
<file>
<source>target/${package}-${package.version}.image</source>
<outputDirectory>/</outputDirectory>
<destName>${package}-${package.version}.img.tar</destName>
<fileMode>0755</fileMode>
</file>
</files>
</assembly>
\ No newline at end of file
#ident "%W%"
#!/bin/sh -x
#######################
###for redhat 7 only
#######################
1. close whole firewall
issue:
all port like 80/20 and so on cannot be accessed
check:
systemctl list-unit-files|grep enabled | grep firewall (if not null, firewall is open)
fix:
systemctl stop firewalld.service
systemctl disable firewalld.service
rollabck:
systemctl enable firewalld.service
systemctl start firewalld.service
#ident "%W%"
#!/bin/sh -x
echo "[INFO] calling setenv.sh"
#find out the absolute path of the script when being executed
if cd "`dirname $0`"; then
SCRIPT_PATH=${PWD}
echo "[INFO] SCRIPT_PATH=${SCRIPT_PATH}"
cd "${OLDPWD}" || exit 1
else
echo "[ERROR] cannot find script folder path"
exit 1
fi
############
# call common-env.sh
############
. ${SCRIPT_PATH}/common-env.sh
#other env setup
#xxx
#xxx
echo "[INFO] setenv.sh is done"
#exit 0 is not allowed here which will stop calling script from going on executing
#ident "%W%"
#!/bin/sh -x
#find out the absolute path of the script when being executed
if cd "`dirname $0`"; then
SCRIPT_PATH=${PWD}
echo "[INFO] SCRIPT_PATH=${SCRIPT_PATH}"
cd "${OLDPWD}" || exit 1
else
echo "[ERROR] cannot find script folder path"
exit 1
fi
#call setenv
. ${SCRIPT_PATH}/setenv.sh
mylog "[INFO] calling start.sh"
HOSTNAME=`hostname`
APPNAME=${prop_package}
APPROOT=${prop_appRoot}
APPHOME=${APPROOT}/${APPNAME}
LOG=/tmp/start-${APPNAME}.log
PROCESS_ID=`ps -ef | grep "${prop_dockerProcessKeyWord}" | grep -v grep | awk '{ print $2 }'`
isNumber ${PROCESS_ID}
#$? represents the result of last unix command
numberCheck=$?
if [ numberCheck ]; then
#kill -0 will send a signal to the process to check if the process exists, 0 menas exists and 1 vice visa
if kill -0 ${PROCESS_ID} > /dev/null 2>&1; then
mylog ""
else
mylog "[ERROR] docker daemon is not running on server <<${HOSTNAME}>>, pleae start it first"
exit 1
fi
fi
#check docker image:version running or not
count=`docker ps --no-trunc=true | grep "${prop_dockerImageName}" | grep "${prop_dockerImageVersion}" | wc -l`
if [ ${count} = ${prop_dockerContainerCount} ]; then
mylog "[WARN] ${prop_dockerContainerCount} containers for ${APPNAME} are already running on server <<${HOSTNAME}>>, will do nothing "
exit 0
elif [ ${count} = 0 ]; then
mylog "[INFO] checked no any ${APPNAME} is running on server <<${HOSTNAME}>>"
else
mylog "[ERROR] ${count} containers for ${APPNAME} are already running, but ${prop_dockerContainerCount} is expected. Please check why"
exit 0
fi
#check docker image name and version existing or not in doc repo
count=`docker images | grep "${prop_dockerImageName}" | grep "${prop_dockerImageVersion}" | wc -l`
if [ ${count} != 0 ]; then
mylog "[INFO] image ${prop_dockerImageName} with version ${prop_dockerImageVersion} already exists in docker repo on host <<${HOSTNAME}>>"
remove="yes"
mylog "[????] Do you want to remove it and reload the image (default ${remove}):"
read removeTmp
if [ "${removeTmp}" != "" ]; then
remove=${removeTmp}
fi
if [[ "yes" = "${remove}" || "YES" = "${remove}" ]]; then
mylog "[COMMAND] docker rmi -f ${prop_dockerImageName}:${prop_dockerImageVersion}"
docker rmi -f ${prop_dockerImageName}:${prop_dockerImageVersion}
#check remove result
count=`docker images | grep "${prop_dockerImageName}" | grep "${prop_dockerImageVersion}" | wc -l`
if [ ${count} != 0 ]; then
mylog "[ERROR] failed to remove image, please check why or remove it manually"
exit 1
fi
fi
fi
count=`docker images | grep "${prop_dockerImageName}" | grep "${prop_dockerImageVersion}" | wc -l`
if [ ${count} = 0 ]; then
imageTar=${prop_dockerImageName}-${prop_dockerImageVersion}.img.tar
mylog "[WARN] image ${prop_dockerImageName} with version ${prop_dockerImageVersion} does not exist in docker repo on host <<${HOSTNAME}>>"
mylog "[COMMAND] docker load < ${APPHOME}/current/${imageTar}"
docker load < ${APPHOME}/current/${imageTar}
#check loading result
count=`docker images | grep "${prop_dockerImageName}" | grep "${prop_dockerImageVersion}" | wc -l`
if [ ${count} != 1 ]; then
mylog "[ERROR] failed to load image, please check why or load it manually"
exit 1
fi
fi
DOCKER_PORT_MAPPINGS=${prop_dockerPortMappings}
#replace ',' with space
DOCKER_PORT_MAPPINGS=${DOCKER_PORT_MAPPINGS//,/ }
DOCKER_CONFIG_FOLDER_MAPPING="${APPHOME}/current/${prop_dockerConfigFileMapping}"
DOCKER_LOG_FOLDER_MAPPING="${APPHOME}/${prop_dockerLogFolderMapping}"
DOCKER_UPLOAD_FOLDER_MAPPING="${APPHOME}/${prop_dockerUploadFolderMapping}"
#for port mapping, each time a new container will increate the port no.
#e.g for mapping 9200:9200, container 1 will have 9200:9200, container 2 will 9201:9200
i=0
while [ $i -le `expr ${prop_dockerContainerCount} - 1` ]
do
#concatenate each port mapping
FINAL_PORT_MAPPING=""
for k in ${DOCKER_PORT_MAPPINGS}
do
SOURCE_PORT=`echo ${k} | awk '{ split($0,array,":")} END {print array[1]}'`
TARGET_PORT=`echo ${k} | awk '{ split($0,array,":")} END {print array[2]}'`
FINAL_PORT_MAPPING="${FINAL_PORT_MAPPING} -p `expr ${SOURCE_PORT} + ${i}`:${TARGET_PORT}"
done
DOCKER_NODE_NAME="Node${i}-${HOSTNAME}"
#replace xxx with node name, each node will have seperate data folder/log folder
FINAL_LOG_FOLDER_MAPPING=${DOCKER_LOG_FOLDER_MAPPING//nodexxx/${DOCKER_NODE_NAME}}
#create the mapping folder if not existing in host
# and change folder mode to 777 in case that docker containers cannot write to host folder
SOURCE_LOG_FOLDER=`echo ${FINAL_LOG_FOLDER_MAPPING} | awk '{ split($0,array,":")} END {print array[1]}'`
#create source folder is not existing
myexecute "mkdir -p ${SOURCE_LOG_FOLDER}"
#change mode in case that docker container cannot write data to host folder
myexecute "chmod -R 777 ${SOURCE_LOG_FOLDER}"
mylog "[INFO] starting new docker container for ${APPNAME} on host <<${HOSTNAME}>>"
myexecute "docker run \
--net=host \
-d \
${FINAL_PORT_MAPPING} \
-v ${prop_javaHome}:/opt/apps/java \
-v ${DOCKER_CONFIG_FOLDER_MAPPING} \
-v ${FINAL_LOG_FOLDER_MAPPING} \
-v ${DOCKER_UPLOAD_FOLDER_MAPPING} \
${prop_dockerImageName}:${prop_dockerImageVersion} \
"
#i++
i=`expr $i + 1`
#sleep to wait server process up
myexecute "sleep ${prop_startOneSleep}"
mylog "------------------------------------"
mylog ""
done
count=`docker ps --no-trunc=true | grep "${prop_dockerImageName}" | grep "${prop_dockerImageVersion}" | wc -l`
if [ ${count} = ${prop_dockerContainerCount} ]; then
mylog "[INFO] ${prop_dockerContainerCount} docker containers for ${APPNAME} started successfully on server <<${HOSTNAME}>>"
elif [ ${count} = 0 ]; then
mylog "[ERROR] All containers for ${APPNAME} failed to start on server <<${HOSTNAME}>>, yon can check log by /var/lib/docker/containers/xxx/*.log"
else
mylog "[ERROR] ${prop_dockerContainerCount} containers for ${APPNAME} are expected, but only ${count} started on server <<${HOSTNAME}>>, yon can check log by /var/lib/docker/containers/xxx/*.log"
fi
exit 0
#ident "%W%"
#!/bin/sh -x
#find out the absolute path of the script when being executed
if cd "`dirname $0`"; then
SCRIPT_PATH=${PWD}
echo "[INFO] SCRIPT_PATH=${SCRIPT_PATH}"
cd "${OLDPWD}" || exit 1
else
echo "[ERROR] cannot find script folder path"
exit 1
fi
#call setenv
. ${SCRIPT_PATH}/setenv.sh
mylog "[INFO] calling stop.sh"
APPNAME=${prop_package}
HOSTNAME=`hostname`
STOP_TIMEOUT=${prop_stopNodeTimeout}
mylog "[INFO] Stopping containers for ${APPNAME} on host ${HOSTNAME}"
PROCESS_ID=`ps -ef | grep "${prop_dockerProcessKeyWord}" | grep -v grep | awk '{ print $2 }'`
isNumber ${PROCESS_ID}
#$? represents the result of last unix command
numberCheck=$?
if [ numberCheck ]; then
#kill -0 will send a signal to the process to check if the process exists, 0 menas exists and 1 vice visa
if kill -0 ${PROCESS_ID} > /dev/null 2>&1; then
mylog "[DEBUG] checked docker daemon is running well on server <<${HOSTNAME}>> with pid: ${PROCESS_ID}"
else
mylog "[ERROR] docker daemon is not running on server <<${HOSTNAME}>>, pleae start it first"
exit 0
fi
fi
#check nginx container existing or not
count=`docker ps | grep "${prop_dockerImageName}" | grep "${prop_dockerImageVersion}" | wc -l`
if [ ${count} != 0 ]; then
mylog "[INFO] checked total ${count} containers for ${APPNAME} are running, gonna stop them"
CONTAINER_IDS=`docker ps | grep "${prop_dockerImageName}" | grep "${prop_dockerImageVersion}" | awk '{ print $1 }'`
for i in $CONTAINER_IDS
do
mylog "[INFO] stopping container id <<${i}>>"
myexecute "docker stop ${i}"
myexecute "sleep ${STOP_TIMEOUT}"
#check again if the container is stopped successfully
count=`docker ps | grep "${prop_dockerImageName}" | grep "${prop_dockerImageVersion}" | grep ${i} | wc -l`
if [ ${count} != "0" ]; then
mylog "[WARN] failed to stop the container <<${i}>>, gonna kill it"
myexecute "docker kill ${i}"
fi
done
else
mylog "[INFO] no any container for ${APPNAME} is running, will do nothing"
exit 0;
fi
#check finally
count=`docker ps | grep "${prop_dockerImageName}" | grep "${prop_dockerImageVersion}" | wc -l`
if [ ${count} != "0" ]; then
mylog "[ERROR] failed to stop/kill all containers for ${APPNAME}, please stop it manually"
fi
mylog "[INFO] all containers for ${APPNAME} are stopped successfully on server <<${HOSTNAME}>>"
exit 0
#ident "%W%"
#!/bin/sh -x
#SCRIPT_PATH must be defined firstly by calling script
echo "[INFO] calling common-env.sh"
if [ "${SCRIPT_PATH}" = "" ]; then
echo "[ERROR] SCRIPT_PATH is not defined in calling script"
exit 1
else
#############
# define own function
#############
#print out command into console (and log file if there is one) and then execute it
myexecute () {
local dt=`date +%Y-%m-%d\ %H:%M:%S`
local theCommand=${1}
echo "${dt}: [COMMAND] ${theCommand}"
if [ "${LOG}" != "" ]; then
echo "${dt}: [COMMAND] ${theCommand}" >> ${LOG}
fi
${theCommand}
}
myexecute2 () {
local dt=`date +%Y-%m-%d\ %H:%M:%S`
local theCommand=${1}
echo "${dt}: [COMMAND] ${theCommand}"
if [ "${LOG}" != "" ]; then
echo "${dt}: [COMMAND] ${theCommand}" >> ${LOG}
fi
eval ${theCommand}
}
#print out log into console (and log file if there is one)
mylog () {
local dt=`date +%Y-%m-%d\ %H:%M:%S`
local theLog=${1}
echo "${dt}: ${theLog}"
if [ "${LOG}" != "" ]; then
echo "${dt}: ${theLog}" >> ${LOG}
fi
}
#print out log into console (and log file if there is one), and transate \n into new line
mylog2 () {
local dt=`date +%Y-%m-%d\ %H:%M:%S`
local theLog=${1}
echo -e "${dt}: ${theLog}"
if [ "${LOG}" != "" ]; then
echo -e "${dt}: ${theLog}" >> ${LOG}
fi
}
#check it is a number or not
isNumber () {
var=${1}
if [ ${var} -eq ${var} 2> /dev/null ]
then
return 0
else
return 1
fi
}
############
# to export variables
############
#export all variables in env.properties
echo "[INFO] export all variables in env.properties"
if [ -f ${SCRIPT_PATH}/../env/env.properties ]; then
myexecute "source ${SCRIPT_PATH}/../env/env.properties"
elif [ -f ${SCRIPT_PATH}/../env/env.properties ]; then
myexecute "source ${SCRIPT_PATH}/../env/env.properties"
else
echo "[ERROR] cannot find env.properties"
exit 1
fi
fi
echo "[INFO] common-env.sh is done"
#exit 0 is not allowed here which is stop calling script from going on executing
#ident "%W%"
#!/bin/sh -x
###############################
## used for cluster install
###############################
#the path of this script when running
if cd "`dirname $0`"; then
SCRIPT_PATH=${PWD}
cd "${OLDPWD}" || exit 1
else
exit 1
fi
#call setenv
. ${SCRIPT_PATH}/setenv.sh
# The preinstall.sh has been lost.(It is unused.)
if [ "${prop_runPreinstall}" = "true" ]; then
myexecute "${SCRIPT_PATH}/preinstall.sh"
if [ $? != 0 ]; then
exit 1
fi
fi
mylog "[INFO] Begin install-cluster.sh"
APPVERSION=`date +%Y%m%d-%H%M%S`
LOG=/tmp/install-${prop_package}-${APPVERSION}.log
APPROOT=${prop_appRoot}
APPNAME=${prop_package}
APPHOME=${APPROOT}/${APPNAME}
HOSTNAME=`hostname`
CLUSTER_NODES=${prop_clusterNodes}
#replace ',' with space
CLUSTER_NODES=${CLUSTER_NODES//,/ }
#replace '"' with null
CLUSTER_NODES=${CLUSTER_NODES//\"/}
MANUAL_FOLDERS=${prop_manualFolders}
MANUAL_FOLDER_MODE=${prop_manualFolderMode}
for i in ${CLUSTER_NODES}
do
mylog ""
mylog "-----------------------------"
mylog "[INFO] Connecting to host ${i}"
#create app home folder and new version folder
myexecute "ssh -oStrictHostKeyChecking=no root@${i} mkdir -p ${APPHOME}/${APPVERSION}"
mylog "[INFO] Folder ${APPHOME}/${APPVERSION} is created successfully on host <<${i}>>"
#copy files from current host to another node by scp command
#-p preserves modification times, access times, and modes from the original file
mylog "[INFO] copying files to host <<${i}>> by scp command"
myexecute "scp -rp ${SCRIPT_PATH}/../* root@${i}:${APPHOME}/${APPVERSION}/"
mylog "[INFO] Copy is done!"
#change owner and group for app package
mylog "[INFO] changing owner and group recursively"
myexecute "ssh -oStrictHostKeyChecking=no root@${i} chown -R ${prop_ownerGroup} ${APPHOME}/${APPVERSION}/"
mylog "[INFO] Owner and group set up done!"
#create manual folders
if [ "${MANUAL_FOLDERS}" != "" ]; then
theCommand="ssh -oStrictHostKeyChecking=no root@${i} \"pwd "
for MANUAL_FOLDER in ${MANUAL_FOLDERS}
do
theCommand="${theCommand} && mkdir -p ${APPHOME}/${MANUAL_FOLDER}"
if [ "${MANUAL_FOLDER_MODE}" != "" ]; then
theCommand="${theCommand} && chmod -R ${MANUAL_FOLDER_MODE} ${APPHOME}/${MANUAL_FOLDER}"
fi
done
theCommand="${theCommand} \" "
myexecute2 "${theCommand}"
fi
#create soft link named 'current', -s:soft link -v:debug mode -n:treate link as normal file if it linking to a folder
#-f:force create it is already there
mylog "[INFO] Create soft link named 'current'"
myexecute "ssh -oStrictHostKeyChecking=no root@${i} ln -svnf ${APPHOME}/${APPVERSION} ${APPHOME}/current"
mylog "[INFO] Link creation is done!"
if [ "${prop_runPostinstall}" = "true" ]; then
myexecute "ssh -oStrictHostKeyChecking=no root@${i} ${APPHOME}/current/scripts/postinstall.sh"
mylog "[INFO] postinstall is done on node ${i}"
fi
mylog "--------------------------------"
done
mylog "[INFO] Cluster installation is done successfully, for more detail please check log ${LOG}"
exit 0
#ident "%W%"
#!/bin/sh -x
###############################
## used for single server install
###############################
#the path of this script when running
if cd "`dirname $0`"; then
SCRIPT_PATH=${PWD}
cd "${OLDPWD}" || exit 1
else
exit 1
fi
#call setenv
. ${SCRIPT_PATH}/setenv.sh
# The preinstall.sh has been lost.(It is unused.)
if [ "${prop_runPreinstall}" = "true" ]; then
myexecute ". ${SCRIPT_PATH}/preinstall.sh"
if [ $? != 0 ]; then
exit 1
fi
fi
mylog "[INFO] Begin install-single.sh"
APPVERSION=`date +%Y%m%d-%H%M%S`
LOG=/tmp/install-${prop_package}-${APPVERSION}.log
APPROOT=${prop_appRoot}
APPNAME=${prop_package}
APPHOME=${APPROOT}/${APPNAME}
HOSTNAME=`hostname`
SINGLE_NODE=${prop_singleNode}
MANUAL_FOLDERS=${prop_manualFolders}
MANUAL_FOLDER_MODE=${prop_manualFolderMode}
mylog ""
mylog "-----------------------------"
mylog "[INFO] Installing on host ${SINGLE_NODE}"
#create app home folder and new version folder
myexecute "mkdir -p ${APPHOME}/${APPVERSION}"
mylog "[INFO] Folder ${APPHOME}/${APPVERSION} is created successfully on host <<${SINGLE_NODE}>>"
#copy files from current folder to app home folder
#-p reserve the specified attributes (default: mode,ownership,timestamps)
mylog "[INFO] copying files to host <<${SINGLE_NODE}>> by cp command"
myexecute "cp -rp ${SCRIPT_PATH}/../* ${APPHOME}/${APPVERSION}/"
mylog "[INFO] Copy is done!"
#change owner and group for app package
mylog "[INFO] changing owner and group recursively"
myexecute "chown -R ${prop_ownerGroup} ${APPHOME}/${APPVERSION}"
mylog "[INFO] Owner and group set up done!"
#create manual folders
if [ "${MANUAL_FOLDERS}" != "" ]; then
for MANUAL_FOLDER in ${MANUAL_FOLDERS}
do
myexecute "mkdir -p ${APPHOME}/${MANUAL_FOLDER}"
if [ "${MANUAL_FOLDER_MODE}" != "" ]; then
myexecute "chmod -R ${MANUAL_FOLDER_MODE} ${APPHOME}/${MANUAL_FOLDER}"
fi
done
fi
#create soft link named 'current', -s:soft link -v:debug mode -n:treate link as normal file if it linking to a folder
#-f:force create it ignoring if it is already there
mylog "[INFO] Create soft link named 'current'"
myexecute "ln -svnf ${APPHOME}/${APPVERSION} ${APPHOME}/current"
mylog "[INFO] Link creation is done!"
mylog "--------------------------------"
mylog "[INFO] Installation is done successfully, for more detail please check log ${LOG}"
mylog "------------------------------------"
mylog "------------------------------------"
# The postinstall.sh has been lost.(It is unused.)
if [ "${prop_runPostinstall}" = "true" ]; then
myexecute ". ${SCRIPT_PATH}/postinstall.sh"
fi
exit 0
#ident "%W%"
#!/bin/sh -x
###############################
## used to install package
###############################
#the path of this script when running
if cd "`dirname $0`"; then
export SCRIPT_PATH=${PWD}
echo "[INFO] export SCRIPT_PATH=${SCRIPT_PATH}"
cd "${OLDPWD}" || exit 1
else
exit 1
fi
#call setenv
. ${SCRIPT_PATH}/setenv.sh
APPVERSION=`date +%Y%m%d-%H%M%S`
LOG=/tmp/install-${prop_package}-${APPVERSION}.log
mylog "[INFO] Begin install.sh"
#check it is a single node installation or a cluster installation
if [ "${prop_isCluster}" = "true" ]; then
mylog "[INFO] checked you are doing CLUSTER installation"
myexecute "${SCRIPT_PATH}/install-cluster.sh"
else
mylog "[INFO] checked you are doing SINGLE NODE installation"
myexecute "${SCRIPT_PATH}/install-single.sh"
fi
exit 0
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3
http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>0.1</id>
<formats>
<format>tar</format>
</formats>
<fileSets>
<fileSet>
<directory>scripts/${package.format}/manager</directory>
<outputDirectory>/scripts</outputDirectory>
<fileMode>0755</fileMode>
</fileSet>
<fileSet>
<directory>scripts/${package.format}/common</directory>
<outputDirectory>/scripts</outputDirectory>
<fileMode>0755</fileMode>
<includes>
<include>install-cluster.sh</include>
<include>install-single.sh</include>
<include>install.sh</include>
<include>common-env.sh</include>
</includes>
</fileSet>
<fileSet>
<directory>env/${package.environment}</directory>
<outputDirectory>/env</outputDirectory>
</fileSet>
</fileSets>
<files>
<file>
<source>target/${package}-${package.version}.war</source>
<outputDirectory>/</outputDirectory>
<destName>${package}-${package.version}.war</destName>
<fileMode>0755</fileMode>
</file>
</files>
</assembly>
\ No newline at end of file
#ident "%W%"
#!/bin/sh -x
echo "[INFO] calling setenv.sh"
#find out the absolute path of the script when being executed
if cd "`dirname $0`"; then
SCRIPT_PATH=${PWD}
echo "[INFO] SCRIPT_PATH=${SCRIPT_PATH}"
cd "${OLDPWD}" || exit 1
else
echo "[ERROR] cannot find script folder path"
exit 1
fi
############
# call common-env.sh
############
. ${SCRIPT_PATH}/common-env.sh
#other env setup
#xxx
#xxx
echo "[INFO] setenv.sh is done"
#exit 0 is not allowed here which will stop calling script from going on executing
#ident "%W%"
#!/bin/sh -x
#find out the absolute path of the script when being executed
if cd "`dirname $0`"; then
SCRIPT_PATH=${PWD}
echo "[INFO] SCRIPT_PATH=${SCRIPT_PATH}"
cd "${OLDPWD}" || exit 1
else
echo "[ERROR] cannot find script folder path"
exit 1
fi
#call setenv
. ${SCRIPT_PATH}/setenv.sh
mylog "[INFO] calling start.sh"
HOSTNAME=`hostname`
APPNAME=${prop_package}
APPROOT=${prop_appRoot}
APPHOME=${APPROOT}/${APPNAME}
LOG=/tmp/start-${APPNAME}.log
#check java home
JAVA_HOME=${prop_javaHome}
if [ "${JAVA_HOME}" = "" ]; then
mylog "[ERROR] JAVA_HOME cannot be null"
exit 1
elif [ ! -d ${JAVA_HOME} ]; then
mylog "[ERROR] ${JAVA_HOME} does not exist as JAVA_HOME"
exit 1
fi
#check if springboot process is up or not
PROCESS_ID=`ps -ef | grep java | grep "${prop_springbootProcessKeyWord}" | grep -v grep | awk '{ print $2 }'`
if [ ${PROCESS_ID} ]; then
mylog "[WARN] ${APPNAME} is already running with process id ${PROCESS_ID} on server <<${HOSTNAME}>>"
exit 0
else
mylog "[INFO] checked no ${APPNAME} running process on server <<${HOSTNAME}>>, will start it"
fi
#start up new process
springbootExecutableWar=${APPHOME}/current/${prop_springbootWarName}-${prop_springbootWarVersion}.war
myexecute2 "nohup ${JAVA_HOME}/bin/java -jar ${springbootExecutableWar} --spring.config.location=${APPHOME}/current/env/application.properties >/dev/null 2>&1 &"
myexecute2 "sleep ${prop_startOneSleep}"
PROCESS_ID=`ps -ef | grep java | grep "${prop_springbootProcessKeyWord}" | grep -v grep | awk '{ print $2 }'`
if [ ${PROCESS_ID} ]; then
mylog "[INFO] ${APPNAME} started successfully with process id ${PROCESS_ID} on server <<${HOSTNAME}>>"
else
mylog "[ERROR] ${APPNAME} failed to start up on server <<${HOSTNAME}>>, you can check log ${LOG}"
fi
exit 0
#ident "%W%"
#!/bin/sh -x
#find out the absolute path of the script when being executed
if cd "`dirname $0`"; then
SCRIPT_PATH=${PWD}
echo "[INFO] SCRIPT_PATH=${SCRIPT_PATH}"
cd "${OLDPWD}" || exit 1
else
echo "[ERROR] cannot find script folder path"
exit 1
fi
#call setenv
. ${SCRIPT_PATH}/setenv.sh
mylog "[INFO] calling stop.sh"
APPNAME=${prop_package}
HOSTNAME=`hostname`
STOP_TIMEOUT=${prop_stopNodeTimeout}
mylog "[INFO] Stopping ${APPNAME} on host ${HOSTNAME}"
#check if springboot process is up or not
PROCESS_ID=`ps -ef | grep java | grep "${prop_springbootProcessKeyWord}" | grep -v grep | awk '{ print $2 }'`
if [ ${PROCESS_ID} ]; then
mylog "[INFO] found running ${APPNAME} process with id = ${PROCESS_ID} on server <<${HOSTNAME}>>, will stop it"
#stop running process
myexecute2 "kill -9 ${PROCESS_ID}"
myexecute2 "sleep ${prop_stopNodeTimeout}"
else
mylog "[WARN] no running ${APPNAME} process on server <<${HOSTNAME}>>"
exit 0
fi
#check again
PROCESS_ID=`ps -ef | grep java | grep "${prop_springbootProcessKeyWord}" | grep -v grep | awk '{ print $2 }'`
if [ ${PROCESS_ID} ]; then
mylog "[ERROR] failed to stop running ${APPNAME} process with id = ${PROCESS_ID} on server <<${HOSTNAME}>>, you can check log ${LOG}"
exit 1
else
mylog "[INFO] ${APPNAME} is stopped successfully on server <<${HOSTNAME}>>"
fi
exit 0
#!/bin/bash
################################
# based on maven assembly plugin
environment=$1
package=$2
packageVersion=$3
packageFormat=$4
if [ "${environment}" = "" ]; then
echo [ERROR] "Please provide env as first param"
exit 1
fi
if [ "${package}" = "" ]; then
echo [ERROR] "Please provide package name as second param"
exit 1
fi
if [ "${packageVersion}" = "" ]; then
echo [ERROR] "Please provide version as third param"
exit 1
fi
if [ "${packageFormat}" = "" ]; then
echo [ERROR] "Please provide package format as forth param"
exit 1
fi
theCommand="mvn -e assembly:single -Dpackage=${package} -Dpackage.version=${packageVersion} -Dpackage.environment=${environment} -Dpackage.format=${packageFormat}"
echo ${theCommand}
${theCommand}
#!/bin/sh
# the java must be goal .I think it may be not very good. (Sean 20170216)
COUNT=`java -version 2>&1 | grep 'java version' | grep 1.8 | grep -v grep | wc -l`
if [ ${COUNT} != 1 ]; then
COUNT=`echo $JAVA_HOME | grep 1.8 | grep -v grep | wc -l`
if [ ${COUNT} != 1 ]; then
echo [ERROR] "Cannot find java 8"
exit 1
fi
fi
package=$1
version=$2
env=$3
resources=$4
if [ "${package}" = "" ]; then
echo [ERROR] "Please provide package name as first param"
exit 1
fi
if [ "${version}" = "" ]; then
echo [ERROR] "Please provide package version as second param"
exit 1
fi
if [ "${env}" = "" ]; then
echo [ERROR] "Please provide env as third param"
exit 1
fi
#在pom.xml文件里面定义的 maven的参数 详细请看 maven -D 命令的含义
#-X To debug the command.
theCommand="mvn clean package -Dpackage=${package} -Dpackage.version=${version} -Dpackage.environment=${env} -Dpackage.resources=${resources} "
echo [INFO] ${theCommand}
exec ${theCommand}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment