Created
May 17, 2020 16:33
-
-
Save seunggabi/49fa44e51d2fe1d0b6e9865898cb9302 to your computer and use it in GitHub Desktop.
boot.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# sh /home1/irteam/apps/boot/boot.sh restart /home1/irteam/deploy/api.jar dev jp | |
USER=`/usr/bin/whoami` | |
readonly BOOT_DIR=/home1/irteam/apps/boot | |
readonly L7CHECK_URL=http://localhost/monitor/l7check | |
readonly PROC_NAME=springboot | |
readonly PROC_PID="${BOOT_DIR}/${PROC_NAME}.pid" | |
function echo_host | |
{ | |
host=`hostname` | |
echo "[$host] $1" | |
} | |
start() | |
{ | |
echo "Starting ${PROC_NAME}..." | |
local PID=$(get_status) | |
if [ -n "${PID}" ]; then | |
echo "${PROC_NAME} is already running" | |
exit 0 | |
fi | |
nohup java -jar -Xms4048m -Xmx8096m "$1" --spring.profiles.active="$2" --music.country="$3" > /dev/null 2>&1 & | |
local PID=${!} | |
if [ -n ${PID} ]; then | |
echo " - Starting..." | |
echo " - Created Process ID in ${PROC_PID}" | |
echo ${PID} > ${PROC_PID} | |
else | |
echo " - failed to start." | |
fi | |
sleep 7 | |
} | |
stop() | |
{ | |
echo "Stopping ${PROC_NAME}..." | |
local DAEMON_PID=`cat "${PROC_PID}"` | |
if [ "$DAEMON_PID" -lt 3 ]; then | |
echo "${PROC_NAME} was not running." | |
else | |
sudo kill -15 $DAEMON_PID | |
rm -f $PROC_PID | |
echo " - Shutdown ...." | |
fi | |
sudo pkill java | |
sleep 5 | |
} | |
restart() | |
{ | |
stop | |
start $1 $2 $3 | |
} | |
status() | |
{ | |
local PID=$(get_status) | |
if [ -n "${PID}" ]; then | |
echo "${PROC_NAME} is running" | |
else | |
echo "${PROC_NAME} is stopped" | |
fi | |
} | |
get_status() | |
{ | |
ps ux | grep ${PROC_NAME} | grep -v grep | awk '{print $2}' | |
} | |
function check | |
{ | |
was_status=`curl $L7CHECK_URL -I -s | grep HTTP | awk '{print $2}'` | |
start_count=0 | |
cum_count=0 | |
while [ $was_status != "200" ]; | |
do | |
restart $1 $2 $3 | |
echo_host "Spring Boot is still startup" | |
echo_host "comm count is $cum_count" | |
if [ $start_count -eq 20 ]; | |
then | |
ps -ef | grep java | grep $component_name | awk '{print $2}' | xargs kill | |
start_count=0 | |
sleep 5 | |
fi | |
if [ $cum_count -eq 40 ]; | |
then | |
exit -1 | |
fi | |
sleep 20 | |
start_count=`expr $start_count + 1` | |
cum_count=`expr $cum_count + 1` | |
was_status=`curl $WASTESTURL -I -s | grep HTTP | awk '{print $2}'` | |
done | |
echo_host "Spring Boot is running" | |
} | |
case $1 in | |
start) | |
start $2 $3 $4 | |
check | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
restart $2 $3 $4 | |
check $2 $3 $4 | |
;; | |
status) | |
status ${PROC_NAME} | |
;; | |
*) | |
echo "Usage: $0 { start | stop | restart | status }" | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment