Update athena-start thx to <Talaysen> for reminding
Fix log directory check/creation Fix watch option Add help command to know how to use the script and explain a bit
This commit is contained in:
parent
3029d3bbc4
commit
8ce56465ad
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,6 +5,7 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
# /
|
# /
|
||||||
|
/*_fifo
|
||||||
/*.exe
|
/*.exe
|
||||||
/*.ilk
|
/*.ilk
|
||||||
/*.log
|
/*.log
|
||||||
|
93
athena-start
93
athena-start
@ -5,6 +5,7 @@
|
|||||||
inst_launch_workaround
|
inst_launch_workaround
|
||||||
|
|
||||||
PATH=./:$PATH
|
PATH=./:$PATH
|
||||||
|
LOG_DIR="./log"
|
||||||
|
|
||||||
print_start() {
|
print_start() {
|
||||||
# more << EOF
|
# more << EOF
|
||||||
@ -29,8 +30,8 @@ get_status(){
|
|||||||
start_serv(){
|
start_serv(){
|
||||||
get_status $1
|
get_status $1
|
||||||
if [ $2 ]; then #is logging on ?
|
if [ $2 ]; then #is logging on ?
|
||||||
LOGFILE="log/$1.launch.log"
|
LOGFILE="$LOG_DIR/$1.launch.log"
|
||||||
LOGRUN="log/$1.log"
|
LOGRUN="$LOG_DIR/$1.log"
|
||||||
FIFO="$1_fifo"
|
FIFO="$1_fifo"
|
||||||
echo "stat_serv, log is enabled"
|
echo "stat_serv, log is enabled"
|
||||||
echo "My logfile=${LOGFILE}"
|
echo "My logfile=${LOGFILE}"
|
||||||
@ -54,30 +55,40 @@ start_serv(){
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
#experimental
|
|
||||||
watch_serv(){
|
watch_serv(){
|
||||||
LOGFILE="log/$1.launch.log"
|
|
||||||
LOGRUN="log/$1.log"
|
|
||||||
FIFO="$1_fifo"
|
|
||||||
ulimit -Sc unlimited
|
ulimit -Sc unlimited
|
||||||
|
|
||||||
|
#now checking status and looping
|
||||||
|
count=0;
|
||||||
while true; do
|
while true; do
|
||||||
get_status $1
|
for i in ${L_SRV} ${C_SRV} ${M_SRV}
|
||||||
if [ -z ${PSRUN} ]; then
|
do
|
||||||
$count=$count+1
|
LOGFILE="$LOG_DIR/$i.launch.log"
|
||||||
echo "server '$1' is down" | tee ${LOGFILE}
|
LOGRUN="$LOG_DIR/$i.log"
|
||||||
echo "restarting server at time at `date +"%m-%d-%H:%M-%S"`" | tee ${LOGFILE}
|
FIFO=$i"_fifo"
|
||||||
if [ -e ./${FIFO} ]; then rm "$FIFO"; fi
|
|
||||||
mkfifo "$FIFO"; tee "$LOGRUN" < "$FIFO" & "./$1" > "$FIFO" 2>&1 & PID=$!
|
get_status $i
|
||||||
echo "$PID" > .$1.pid
|
#echo "Echo id of $i is ${PSRUN}"
|
||||||
if [ $3 ] && [ $3 -lt $count ]; then break; fi
|
if [ -z ${PSRUN} ]; then
|
||||||
else sleep $2
|
count=$((count+1))
|
||||||
fi
|
#echo "fifo=$FIFO"
|
||||||
|
echo "server '$i' is down"
|
||||||
|
echo "server '$i' is down" >> ${LOGFILE}
|
||||||
|
echo "restarting server at time at `date +"%m-%d-%H:%M-%S"`"
|
||||||
|
echo "restarting server at time at `date +"%m-%d-%H:%M-%S"`" >> ${LOGFILE}
|
||||||
|
if [ -e $FIFO ]; then rm $FIFO; fi
|
||||||
|
mkfifo "$FIFO"; tee "$LOGRUN" < "$FIFO" & "./$i" > "$FIFO" 2>&1 & PID=$!
|
||||||
|
echo "$PID" > .$i.pid
|
||||||
|
if [ $2 ] && [ $2 -lt $count ]; then break; fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
sleep $1
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
restart(){
|
restart(){
|
||||||
$0 stop
|
$0 stop
|
||||||
|
if [ $1 ]; then sleep $1; fi
|
||||||
for i in ${L_SRV} ${C_SRV} ${M_SRV}
|
for i in ${L_SRV} ${C_SRV} ${M_SRV}
|
||||||
do
|
do
|
||||||
FIFO="$1_fifo"
|
FIFO="$1_fifo"
|
||||||
@ -101,7 +112,8 @@ case $1 in
|
|||||||
echo "Looks good, a nice Athena!"
|
echo "Looks good, a nice Athena!"
|
||||||
if [ "$2" = "--enlog" ]; then
|
if [ "$2" = "--enlog" ]; then
|
||||||
ENLOG=1
|
ENLOG=1
|
||||||
echo "Logging is enable"
|
if [ ! -d "$LOG_DIR" ]; then mkdir -p $LOG_DIR; fi
|
||||||
|
echo "Logging is enable in $LOG_DIR"
|
||||||
else
|
else
|
||||||
echo "Logging is disable"
|
echo "Logging is disable"
|
||||||
fi
|
fi
|
||||||
@ -112,10 +124,15 @@ case $1 in
|
|||||||
echo "Now Started Athena."
|
echo "Now Started Athena."
|
||||||
;;
|
;;
|
||||||
'watch')
|
'watch')
|
||||||
|
if [ ! -d "$LOG_DIR" ]; then mkdir -p $LOG_DIR; 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
|
||||||
|
echo " Gonna watch rA 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
|
||||||
watch_serv $i 10 3
|
start_serv $i 1
|
||||||
done
|
done
|
||||||
|
watch_serv $Restart_count $Restart_sleep
|
||||||
echo "Now watching Athena."
|
echo "Now watching Athena."
|
||||||
;;
|
;;
|
||||||
'stop')
|
'stop')
|
||||||
@ -138,9 +155,41 @@ case $1 in
|
|||||||
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}' seem down"; fi
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
|
'help')
|
||||||
|
case $2 in
|
||||||
|
'start')
|
||||||
|
echo "syntaxe: 'start {--enlog}'"
|
||||||
|
echo "This option will starts the servs"
|
||||||
|
echo "--enlog will tee all terminal output into a log/$servname.log file"
|
||||||
|
;;
|
||||||
|
'stop')
|
||||||
|
echo "This option will shutdowns the servs'"
|
||||||
|
;;
|
||||||
|
'restart')
|
||||||
|
echo "syntaxe: 'restart {<delay>}'"
|
||||||
|
echo "This option will wait delay then will attempt to restart the servs"
|
||||||
|
echo "NB, even if delay is over it will wait the pid is finished before atetmpting to restart servs"
|
||||||
|
;;
|
||||||
|
'status')
|
||||||
|
echo "This option let you know if 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 " If it wasn't the case please use something like 'ps ax | grep server' to know their status"
|
||||||
|
;;
|
||||||
|
'watch')
|
||||||
|
echo "syntaxe: 'watch {<restart_intervall> <restart_count>}'"
|
||||||
|
echo "The watch option allow you to auto restart the server when this one was stopped"
|
||||||
|
echo "<restart_intervall> delay in second before recheking if server are down (default 10) "
|
||||||
|
echo "<restart_count> how many time should we restart servs (default 3), (-1=undefinitly)"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Please specify a command you'll like more info { start | stop | restart | status | watch }"
|
||||||
|
read -p "Enter a valid command: " readEnterKey
|
||||||
|
$0 "help" $readEnterKey
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Usage: athena-start { start | stop | restart | status | watch }"
|
echo "Usage: athena-start { start | stop | restart | status | watch | help }"
|
||||||
echo "option --enlog will tee output into a logfile"
|
|
||||||
read -p "Enter a valid option: " readEnterKey
|
read -p "Enter a valid option: " readEnterKey
|
||||||
$0 $readEnterKey
|
$0 $readEnterKey
|
||||||
;;
|
;;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user