Fixed linux server shutdown order (#2151)

Fixes #2141

Thanks to @hurtsky, @RadianFord, @hazimjauhari90 and @aleos89
This commit is contained in:
Lemongrass3110 2017-05-20 18:40:08 +02:00 committed by GitHub
parent ce4ebbe5bc
commit ae540f133f

View File

@ -9,8 +9,8 @@ LOG_DIR="./log"
print_start() { print_start() {
# more << EOF # more << EOF
echo "Athena Starting..." echo "rAthena is starting..."
echo " (c) 2013 rAthena Project" echo " (c) 2017 rAthena Project"
echo "" echo ""
echo "" echo ""
echo "checking..." echo "checking..."
@ -23,10 +23,10 @@ get_status(){
ISRUN=$(ps ax | grep $(cat ${PIDFILE}) | grep $1) ISRUN=$(ps ax | grep $(cat ${PIDFILE}) | grep $1)
PSRUN=$(echo "$ISRUN" | awk '{ print $1 }') PSRUN=$(echo "$ISRUN" | awk '{ print $1 }')
fi fi
#return ${PSRUN} #seem to cause issue for some os #return ${PSRUN} #seems to cause an issue for some os
} }
#cheking if already started, launch and mark in log #checking if already started, launch and mark in log
start_serv(){ start_serv(){
get_status $1 get_status $1
if [ $2 ]; then #is logging on ? if [ $2 ]; then #is logging on ?
@ -42,7 +42,7 @@ start_serv(){
echo "$PID" > .$1.pid echo "$PID" > .$1.pid
echo "Server '$1' started at `date +"%m-%d-%H:%M-%S"`" | tee ${LOGFILE} echo "Server '$1' started at `date +"%m-%d-%H:%M-%S"`" | tee ${LOGFILE}
else else
echo "Can't start '$1', cause is already running p${PSRUN}" | tee ${LOGFILE} echo "Cannot start '$1', because it is already running p${PSRUN}" | tee ${LOGFILE}
fi fi
else else
if [ -z ${PSRUN} ]; then if [ -z ${PSRUN} ]; then
@ -50,7 +50,7 @@ start_serv(){
echo "$!" > .$1.pid echo "$!" > .$1.pid
echo "Server '$1' started at `date +"%m-%d-%H:%M-%S"`" echo "Server '$1' started at `date +"%m-%d-%H:%M-%S"`"
else else
echo "Can't start '$1', cause is already running p${PSRUN}" echo "Cannot start '$1', because it is already running p${PSRUN}"
fi fi
fi fi
} }
@ -94,7 +94,7 @@ restart(){
FIFO="$1_fifo" FIFO="$1_fifo"
while true; do while true; do
get_status ${i} get_status ${i}
if [ ${PSRUN} ]; then echo "'${i}' is still running p${PSRUN} waiting end"; sleep 2; if [ ${PSRUN} ]; then echo "'${i}' is still running p${PSRUN} waiting for the process to end"; sleep 2;
else else
if [ -e ./${FIFO} ]; then rm "$FIFO"; fi if [ -e ./${FIFO} ]; then rm "$FIFO"; fi
break break
@ -109,38 +109,47 @@ case $1 in
print_start print_start
check_files check_files
echo "Check complete." echo "Check complete."
echo "Looks good, a nice Athena!" echo "Looks like a good, nice rAthena!"
if [ "$2" = "--enlog" ]; then if [ "$2" = "--enlog" ]; then
ENLOG=1 ENLOG=1
if [ ! -d "$LOG_DIR" ]; then mkdir -p $LOG_DIR; fi if [ ! -d "$LOG_DIR" ]; then mkdir -p $LOG_DIR; fi
echo "Logging is enable in $LOG_DIR" echo "Logging is enabled in $LOG_DIR"
else else
echo "Logging is disable" echo "Logging is disabled"
fi fi
for i in ${L_SRV} ${C_SRV} ${M_SRV} for i in ${L_SRV} ${C_SRV} ${M_SRV}
do do
start_serv $i $ENLOG start_serv $i $ENLOG
done done
echo "Now Started Athena." echo "rAthena was started."
;; ;;
'watch') 'watch')
if [ ! -d "$LOG_DIR" ]; then mkdir -p $LOG_DIR; fi if [ ! -d "$LOG_DIR" ]; then mkdir -p $LOG_DIR; fi
if [ -z $2 ]; then Restart_count=10; else Restart_count=$2; fi if [ -z $2 ]; then Restart_count=10; else Restart_count=$2; fi
if [ -z $3 ]; then Restart_sleep=3; else Restart_sleep=$3; fi if [ -z $3 ]; then Restart_sleep=3; else Restart_sleep=$3; fi
echo " Gonna watch rA for Restart_count = $Restart_count, Restart_sleep= $Restart_sleep" echo "Going to watch rAthena for restart_count = $Restart_count, restart_sleep = $Restart_sleep"
for i in ${L_SRV} ${C_SRV} ${M_SRV} for i in ${L_SRV} ${C_SRV} ${M_SRV}
do do
start_serv $i 1 start_serv $i 1
done done
watch_serv $Restart_count $Restart_sleep watch_serv $Restart_count $Restart_sleep
echo "Now watching Athena." echo "Watching rAthena now."
;; ;;
'stop') 'stop')
for i in ${L_SRV} ${C_SRV} ${M_SRV} for i in ${M_SRV} ${C_SRV} ${L_SRV}
do do
PIDFILE=.${i}.pid PIDFILE=.${i}.pid
if [ -e ./${PIDFILE} ]; then if [ -e ./${PIDFILE} ]; then
kill $(cat ${PIDFILE}) kill $(cat ${PIDFILE})
while true; do
get_status ${i}
if [ ${PSRUN} ]; then echo "'${i}' is still running p${PSRUN} waiting for the process to end"; sleep 2;
else
break
fi
done
rm ${PIDFILE} rm ${PIDFILE}
fi fi
done done
@ -152,7 +161,7 @@ case $1 in
for i in ${L_SRV} ${C_SRV} ${M_SRV} for i in ${L_SRV} ${C_SRV} ${M_SRV}
do do
get_status ${i} get_status ${i}
if [ ${PSRUN} ]; then echo "'${i}' is running p${PSRUN}"; else echo "'${i}' seem down"; fi if [ ${PSRUN} ]; then echo "'${i}' is running p${PSRUN}"; else echo "'${i}' seems to be down"; fi
done done
;; ;;
'val_runonce') 'val_runonce')
@ -171,39 +180,39 @@ case $1 in
case $2 in case $2 in
'start') 'start')
echo "syntax: 'start {--enlog}'" echo "syntax: 'start {--enlog}'"
echo "This option will starts the servs" echo "This option will start the servers"
echo "--enlog will tee all terminal output into a log/$servname.log file" echo "--enlog will write all terminal output into a log/$servname.log file"
;; ;;
'stop') 'stop')
echo "This option will shutdowns the servs'" echo "This option will shut the servers down"
;; ;;
'restart') 'restart')
echo "syntax: 'restart {<delay>}'" echo "syntax: 'restart {<delay>}'"
echo "This option will wait delay then will attempt to restart the servs" echo "This option will wait for the given delay and will attempt to restart the servers afterwards"
echo "NB, even if delay is over it will wait the pid is finished before atetmpting to restart servs" echo "Note: Even if the delay is over it will wait until the pid is finished before attempting to restart the servers"
;; ;;
'status') 'status')
echo "syntax: 'watch {<restart_intervall> <restart_count>}'" echo "syntax: 'status'"
echo "This option let you know if the server are running or not" echo "This option will let you know whether the server are running or not"
echo "NB this option is based on PID and supposed you have launch the serv by this script" echo "Note: This option is based on PID and requires that you have launched the servers with this script too"
echo " If it wasn't the case please use something like 'ps ax | grep server' to know their status" echo "If this was not the case please use something like 'ps ax | grep server' to check their status"
;; ;;
'watch') 'watch')
echo "syntax: 'watch {<restart_intervall> <restart_count>}'" echo "syntax: 'watch {<restart_interval> <restart_count>}'"
echo "The watch option allow you to auto restart the server when this one was stopped" echo "The watch option allows you to automatically restart the servers when one of them was stopped"
echo "<restart_intervall> delay in second before recheking if server are down (default 10) " echo "<restart_interval> delay in seconds before rechecking if a server is down (default 10) "
echo "<restart_count> how many time should we restart servs (default 3), (-1=undefinitly)" echo "<restart_count> how many times the servers should be restarted (default 3), (-1=indefinitly)"
;; ;;
'val_runonce') 'val_runonce')
echo "syntax: 'val_runonce'" echo "syntax: 'val_runonce'"
echo "This option will run valgrin with run-once to check the serv" echo "This option will run valgrin with run-once to check the servers"
;; ;;
'valchk') 'valchk')
echo "syntax: 'valchk'" echo "syntax: 'valchk'"
echo "This option will run valgrin with the serv" echo "This option will run valgrin with the servers"
;; ;;
*) *)
echo "Please specify a command you'll like more info { start | stop | restart | status | watch }" echo "Please specify a command you would like more info on { start | stop | restart | status | watch }"
read -p "Enter a valid command: " readEnterKey read -p "Enter a valid command: " readEnterKey
$0 "help" $readEnterKey $0 "help" $readEnterKey
;; ;;