1. 程式人生 > >Java SE專案簡單釋出指令碼

Java SE專案簡單釋出指令碼

1、釋出指令碼

[[email protected] deploy]# cat deploy.sh
#/bin/sh
TIME=`date +%Y%m%d%H%M%S`
NAME=blog-service
cd /data/${NAME}
sh deploy/stop.sh
rm -rf ./classes ./lib
tar zxf *-dist.tar.gz -C ./
rm ./lib/${NAME}*.jar
sh deploy/start.sh

cp ${NAME}*.tar.gz ./bak/${NAME}*.tar.gz_${TIME}

2、停止指令碼

[[email protected]
deploy]# cat stop.sh #!/bin/sh MAIN_CLASS="com.blog.service.server.Server" #kill server SERVER_PID=`ps auxf | grep "${MAIN_CLASS}" | grep -v "grep"| awk '{print $2}'` echo "${MAIN_CLASS} pid is ${SERVER_PID}" if [ -n "$SERVER_PID" ] then kill $SERVER_PID echo "$SERVER_PID is killed!"

3、啟動指令碼

[[email protected] deploy]# cat start.sh 
#!/bin/sh
SERVICE_HOME=/data/blog-service

cd ${SERVICE_HOME}

MAIN_CLASS="com.blog.service.server.Server"

LIB_DIR=${SERVICE_HOME}/lib

LOGS_DIR=${SERVICE_HOME}/logs

ARCHIVE_SUFFIX=`date +%Y%m%d-%H%M`

JAVA_ARGS="-server -Xms70m -Xmx70m -XX:NewSize=16m -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=78 -XX:ThreadStackSize=256 -Xloggc:${SERVICE_HOME}/logs/gc.log"

JAVA_ARGS="${JAVA_ARGS} -Dsun.rmi.dgc.server.gcInterval=3600000 -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.server.exceptionTrace=true"

CLASSPATH=$CLASSPATH:${SERVICE_HOME}/classes/
files=`ls -1 ${LIB_DIR}`
for file in ${files} ;do
        CLASSPATH=$CLASSPATH:${LIB_DIR}/${file}
done
export CLASSPATH

java ${JAVA_ARGS} ${MAIN_CLASS}  1>${SERVICE_HOME}/logs/stdout.log 2>${SERVICE_HOME}/logs/stderr.log&

echo "${SERVICE_HOME}-${MAIN_CLASS} starting"

#tail -f logs/stdout.log