shell脚本直接启动jar读取同级目录下的 yml文件私有化部署
准备yml文件,启动springBoot的jar会默认优先读取同级目录下的yml配置
server:
port: 10072
spring:
profiles:
active: dev
servlet:
multipart:
max-file-size: 500MB
max-request-size: 500MB
application:
name: xxx
redis:
cluster:
timeout: 5000
nodes: node1:7002,node2:7001,node3:7002,node4:7001,node5:7002
datasource:
url: jdbc:mysql://ip:3306/xxxx?useUnicode=yes&useSSL=false&characterEncoding=UTF-8&allowMultiQueries=true
username: root
password: xxx
driver-class-name: com.mysql.cj.jdbc.Driver
ribbon:
ReadTimeout: 10000
ConnectTimeout: 10000
MaxAutoRetriesNextServer: 1
MaxAutoRetries: 1
OkToRetryOnAllOperations: true
mybatis:
mapper-locations:
- classpath*:/mapper/*Mapper.xml
config-location: classpath:mybatis-config.xml
logging:
config: classpath:logback-prod.xml
准备脚本
if [ $
echo "Usage: sh xx.sh [start|stop|restart] [prod|dev|test]"
exit 1
fi
command=$1
profile=$2
app_name="xxx"
jar_file="${app_name}.jar"
start() {
pid=$(pgrep -f ${jar_file})
if [ -n "${pid}" ]; then
echo "${app_name} is already running. PID: ${pid}"
exit 1
fi
jvm_options="-Xmx2500m -Xms2500m -XX:+PrintGCDetails -XX:+PrintHeapAtGC -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+HeapDumpOnOutOfMemoryError -verbose:gc -Xloggc:./logs/gc.log -XX:HeapDumpPath=./logs"
nohup java ${jvm_options} -jar ${jar_file} --spring.profiles.active=common,${profile} > ./logs/${app_name}.log 2>&1 &
echo "${app_name} is started."
}
stop() {
pid=$(pgrep -f ${jar_file})
if [ -z "${pid}" ]; then
echo "${app_name} is not running."
exit 1
fi
kill ${pid}
echo "${app_name} is stopped."
}
restart() {
stop
sleep 1
start
}
status() {
pid=$(pgrep -f ${jar_file})
if [ -n "${pid}" ]; then
echo "${app_name} is running. PID: ${pid}"
else
echo "${app_name} is not running."
fi
}
case "${command}" in
"start")
start
;;
"stop")
stop
;;
"restart")
restart
;;
"status")
status
;;
*)
echo "Unknown command: ${command}"
exit 1
;;
esac
启动方式
sh start.sh start/restart/stop dev/test/prod
需要注意:start.sh 需要和 application.yml , xxx.jar在同一目录下