分布式项目中 linux 服务器 部署jar 应用脚本 deploy.sh

时间:2022-09-19 01:55:03

在实际项目的部署中,尤其是分布式项目,有很多服务的jar包需要 部署,这里抽取出公用的 deploy的脚本

下面是不含jdk配置的

#!/bin/bash
JAVA_OPTIONS_INITIAL=-Xms128M
JAVA_OPTIONS_MAX=-Xmx512M APP_NAME=aps-sdk-merchant-manager PID=$(ps aux | grep ${APP_NAME} | grep -v grep | awk '{print $2}' )
ALARM_CONFIG_FILE=`pwd`/alarmConfig.yaml function check_if_process_is_running {
if [ "$PID" = "" ]; then
return
fi
ps -p $PID | grep "java"
return $?
} case "$1" in
status)
if check_if_process_is_running
then
echo -e "\033[32m $APP_NAME is running \033[0m"
else
echo -e "\033[32m $APP_NAME not running \033[0m"
fi
;;
stop)
if ! check_if_process_is_running
then
echo -e "\033[32m $APP_NAME already stopped \033[0m"
exit
fi
kill - $PID
echo -e "\033[32m Waiting for process to stop \033[0m"
NOT_KILLED=
for i in {..}; do
if check_if_process_is_running
then
echo -ne "\033[32m . \033[0m"
sleep
else
NOT_KILLED=
fi
done
echo
if [ $NOT_KILLED = ]
then
echo -e "\033[32m Cannot kill process \033[0m"
exit
fi
echo -e "\033[32m $APP_NAME already stopped \033[0m"
;;
start)
if [ "$PID" != "" ] && check_if_process_is_running
then
echo -e "\033[32m $APP_NAME already running \033[0m"
exit
fi
nohup java -jar $JAVA_OPTIONS_INITIAL $JAVA_OPTIONS_MAX $APP_NAME.jar &
echo -ne "\033[32m Starting \033[0m"
for i in {..}; do
echo -ne "\033[32m.\033[0m"
sleep
done
if check_if_process_is_running
then
echo -e "\033[32m $APP_NAME fail \033[0m"
else
echo -e "\033[32m $APP_NAME started \033[0m"
fi
;;
restart)
$ stop
if [ $? = ]
then
exit
fi
$ start
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit
esac exit

下面是含jdk配置的

#! /bin/bash

## java env
export JAVA_HOME=/usr/local/java/jdk1..0_79
export JRE_HOME=$JAVA_HOME/jre JAVA_OPTIONS_INITIAL=-Xms128M
JAVA_OPTIONS_MAX=-Xmx512M APP_NAME=aps-sdk-merchant-manager PID=$(ps aux | grep ${APP_NAME} | grep -v grep | awk '{print $2}' ) function check_if_process_is_running {
if [ "$PID" = "" ]; then
return
fi
ps -p $PID | grep "java"
return $?
} case "$1" in
status)
if check_if_process_is_running
then
echo -e "\033[32m $APP_NAME is running \033[0m"
else
echo -e "\033[32m $APP_NAME not running \033[0m"
fi
;;
stop)
if ! check_if_process_is_running
then
echo -e "\033[32m $APP_NAME already stopped \033[0m"
exit
fi
kill - $PID
echo -e "\033[32m Waiting for process to stop \033[0m"
NOT_KILLED=
for i in {..}; do
if check_if_process_is_running
then
echo -ne "\033[32m . \033[0m"
sleep
else
NOT_KILLED=
fi
done
echo
if [ $NOT_KILLED = ]
then
echo -e "\033[32m Cannot kill process \033[0m"
exit
fi
echo -e "\033[32m $APP_NAME already stopped \033[0m"
;;
start)
if [ "$PID" != "" ] && check_if_process_is_running
then
echo -e "\033[32m $APP_NAME already running \033[0m"
exit
fi
nohup $JRE_HOME/bin/java -jar $JAVA_OPTIONS_INITIAL $JAVA_OPTIONS_MAX $APP_NAME.jar &
echo -ne "\033[32m Starting \033[0m"
for i in {..}; do
echo -ne "\033[32m.\033[0m"
sleep
done
if check_if_process_is_running
then
echo -e "\033[32m $APP_NAME fail \033[0m"
else
echo -e "\033[32m $APP_NAME started \033[0m"
fi
;;
restart)
$ stop
if [ $? = ]
then
exit
fi
$ start
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit
esac exit