给Linux上部署的Springboot项目创建启动/关闭sh脚本

1. 创建脚本

#!/bin/bash
# ./start.sh stop	stop Springboot process
# ./start.sh		start directly
# ./start.sh {env}	start with env parameter
# jar list
jars=("api-1.0.0.jar" "batch-1.0.0.jar")
 
start(){
	stop
	
	env="dev"
	if [ ${1} ]
	then
		env=${1}
	fi
	echo ${env}
	
	for jar_name in ${jars[@]};
	do
		# start Jar
		nohup java -jar -Dspring.profiles.active={env} ${jar_name} >./out/${jar_name}.out 2>&1 &
		echo ${env} ${jar_name} start
	done
	echo ${jar_name} "started"
}
 
stop(){
	for jar_name in ${jars[@]};
		do
		# kill process
			tpid=`ps -ef|grep $jar_name|grep -v grep|grep -v kill|awk '{print $2}'`

			if [ ${tpid} ]
			then
				echo ${jar_name} ${tpid} kill
				kill -9 ${tpid}
			fi
		done
	echo "kill process success"
}
 
 
if [ !${1} -a ${1} == "start" ]
then
	start ${2}
elif [ ${1} == "stop" ]
then
	stop
else
	start ${1}
fi

2. 启动

>./start.sh 
or
>./start.sh prod

3. 关闭

>./start.sh stop

你可能感兴趣的:(SpringBoot,Linux)