linux 部署脚本

shell 脚本

#!/bin/bash
#设置jdk环境
export JAVA_HOME=/usr/java/jdk1.8.0_45
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

###################################
#环境变量及程序执行参数
#需要根据实际环境以及Java程序名称来修改这些参数
###################################
 
#需要启动的Java主程序(main方法类)
JAR_FILE="schedule.server-1.0-SNAPSHOT.jar"

#项目路径
APP_HOME="/home/robin/wallet_push"
#环境配置
ENV_OPTS="--spring.profiles.active=release"
SPRING_CONFIG_LOCATION="--spring.config.location=$APP_HOME/release/job.properties,$APP_HOME/release/application.properties,$APP_HOME/release/quartz.properties"

#端口号
SERVER_PORT="8085"
 
#java虚拟机启动参数
JAVA_OPTS="-ms512m -mx512m -Xmn256m -Djava.awt.headless=true -XX:MaxPermSize=128m -Dsun.net.http.allowRestrictedHeaders=true"
###################################
# 获取进程id
pid=0

checkpid() {
   server_pid=$(pgrep -f $JAR_FILE)
 
   if [ -n "$server_pid" ]; then
	  pid=`echo $server_pid`
   else
	  pid=0
   fi
}

start(){
	echo "ready to start $JAR_FILE"
	checkpid
		if [ 0 -ne $pid ]
		then
			echo "warn: server started already!"
		else
			java $JAVA_OPS -jar $JAR_FILE --server.port=$SERVER_PORT $SPRING_CONFIG_LOCATION > stdout.log &
			sleep 3s
			checkpid
			if [ 0 -ne $pid ]
			then
				echo "warining: failed"
			else
				echo "server started"
			fi
		fi
}

stop(){
	checkpid
	if [ 0 -ne $pid ]
		then
		kill -9 $pid
		checkpid
		if [ 0 -eq $pid ]
			then
				echo "server stoped"
			else
				echo "warning: server toped failed!"
			fi

		else
			echo 'warning: server not started!'
		fi
}

case $1 in
	start)
	start
		;;
 
	restart)
		stop
	start
	;;
	stop)
	stop
	;;

esac
posted @ 2018-07-02 19:27  SheaChen  阅读(799)  评论(0编辑  收藏  举报