Adjust installation and service scripts (#7407)

* Fix install in directory with spaces

* Use $() notation instead of legacy backticks

* Fix help->start enlog message

* Fix typo

* Whitespace cleanup

* Fix restart delay

* Make get_status robust
This commit is contained in:
Livia Medeiros 2022-11-17 06:04:26 +09:00 committed by GitHub
parent 5d8e034868
commit 129ce465b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 47 deletions

View File

@ -20,8 +20,7 @@ print_start() {
get_status(){ get_status(){
PIDFILE=.$1.pid PIDFILE=.$1.pid
if [ -e ${PIDFILE} ]; then if [ -e ${PIDFILE} ]; then
ISRUN=$(ps ax | grep $(cat ${PIDFILE}) | grep $1) PSRUN=$(pgrep -F ${PIDFILE})
PSRUN=$(echo "$ISRUN" | awk '{ print $1 }')
fi fi
#return ${PSRUN} #seems to cause an issue for some os #return ${PSRUN} #seems to cause an issue for some os
} }
@ -36,11 +35,11 @@ start_serv(){
echo "stat_serv, log is enabled" echo "stat_serv, log is enabled"
echo "My logfile=${LOGFILE}" echo "My logfile=${LOGFILE}"
if [ -z ${PSRUN} ]; then if [ -z ${PSRUN} ]; then
if [ -e ./${FIFO} ]; then rm "$FIFO"; fi if [ -e ./${FIFO} ]; then rm "$FIFO"; fi
mkfifo "$FIFO"; tee "$LOGRUN" < "$FIFO" & "./$1" > "$FIFO" 2>&1 & PID=$! mkfifo "$FIFO"; tee "$LOGRUN" < "$FIFO" & "./$1" > "$FIFO" 2>&1 & PID=$!
#"./$1" > >(tee "$LOGRUN") 2>&1 & PID=$! #bash only #"./$1" > >(tee "$LOGRUN") 2>&1 & PID=$! #bash only
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 "Cannot start '$1', because it is already running p${PSRUN}" | tee ${LOGFILE} echo "Cannot start '$1', because it is already running p${PSRUN}" | tee ${LOGFILE}
fi fi
@ -48,7 +47,7 @@ start_serv(){
if [ -z ${PSRUN} ]; then if [ -z ${PSRUN} ]; then
./$1& ./$1&
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 "Cannot start '$1', because it is already running p${PSRUN}" echo "Cannot start '$1', because it is already running p${PSRUN}"
fi fi
@ -66,20 +65,20 @@ watch_serv(){
LOGFILE="$LOG_DIR/$i.launch.log" LOGFILE="$LOG_DIR/$i.launch.log"
LOGRUN="$LOG_DIR/$i.log" LOGRUN="$LOG_DIR/$i.log"
FIFO=$i"_fifo" FIFO=$i"_fifo"
get_status $i get_status ${i}
#echo "Echo id of $i is ${PSRUN}" #echo "Echo id of $i is ${PSRUN}"
if [ -z ${PSRUN} ]; then if [ -z ${PSRUN} ]; then
count=$((count+1)) count=$((count+1))
#echo "fifo=$FIFO" #echo "fifo=$FIFO"
echo "server '$i' is down" echo "server '$i' is down"
echo "server '$i' is down" >> ${LOGFILE} 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")"
echo "restarting server at time at `date +"%m-%d-%H:%M-%S"`" >> ${LOGFILE} echo "restarting server at time at $(date +"%m-%d-%H:%M-%S")" >> ${LOGFILE}
if [ -e $FIFO ]; then rm $FIFO; fi if [ -e $FIFO ]; then rm $FIFO; fi
mkfifo "$FIFO"; tee "$LOGRUN" < "$FIFO" & "./$i" > "$FIFO" 2>&1 & PID=$! mkfifo "$FIFO"; tee "$LOGRUN" < "$FIFO" & "./$i" > "$FIFO" 2>&1 & PID=$!
echo "$PID" > .$i.pid echo "$PID" > .$i.pid
if [ $2 ] && [ $2 -lt $count ]; then break; fi if [ $2 ] && [ $2 -lt $count ]; then break; fi
fi fi
done done
sleep $1 sleep $1
@ -101,11 +100,11 @@ restart(){
fi fi
done done
done done
$0 start $0 start
} }
case $1 in case $1 in
'start') 'start')
print_start print_start
check_files check_files
echo "Check complete." echo "Check complete."
@ -123,7 +122,7 @@ case $1 in
done done
echo "rAthena was started." 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
@ -134,7 +133,7 @@ case $1 in
done done
watch_serv $Restart_count $Restart_sleep watch_serv $Restart_count $Restart_sleep
echo "Watching rAthena now." echo "Watching rAthena now."
;; ;;
'stop') 'stop')
for i in ${W_SRV} ${M_SRV} ${C_SRV} ${L_SRV} for i in ${W_SRV} ${M_SRV} ${C_SRV} ${L_SRV}
do do
@ -155,7 +154,7 @@ case $1 in
done done
;; ;;
'restart') 'restart')
restart restart "$@"
;; ;;
'status') 'status')
for i in ${L_SRV} ${C_SRV} ${M_SRV} ${W_SRV} for i in ${L_SRV} ${C_SRV} ${M_SRV} ${W_SRV}
@ -181,7 +180,7 @@ case $1 in
'start') 'start')
echo "syntax: 'start {--enlog}'" echo "syntax: 'start {--enlog}'"
echo "This option will start the servers" echo "This option will start the servers"
echo "--enlog will write 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 shut the servers down" echo "This option will shut the servers down"
@ -205,11 +204,11 @@ case $1 in
;; ;;
'val_runonce') 'val_runonce')
echo "syntax: 'val_runonce'" echo "syntax: 'val_runonce'"
echo "This option will run valgrin with run-once to check the servers" echo "This option will run valgrind with run-once to check the servers"
;; ;;
'valchk') 'valchk')
echo "syntax: 'valchk'" echo "syntax: 'valchk'"
echo "This option will run valgrin with the servers" echo "This option will run valgrind with the servers"
;; ;;
*) *)
echo "Please specify a command you would like more info on { start | stop | restart | status | watch }" echo "Please specify a command you would like more info on { start | stop | restart | status | watch }"

View File

@ -4,7 +4,7 @@ M_SRV=map-server
W_SRV=web-server W_SRV=web-server
INST_PATH=/opt INST_PATH=/opt
PKG=rathena PKG=rathena
PKG_PATH=$INST_PATH/$PKG PKG_PATH="${INST_PATH}/${PKG}"
check_files() { check_files() {
for i in ${L_SRV} ${C_SRV} ${M_SRV} ${W_SRV} for i in ${L_SRV} ${C_SRV} ${M_SRV} ${W_SRV}
@ -17,11 +17,11 @@ check_files() {
} }
check_inst_right(){ check_inst_right(){
if [ ! -w $INST_PATH ]; then echo "You must have sudo right to use this install (write/read permission in /opt/ )" && exit; fi if [ ! -w "${INST_PATH}" ]; then echo "You must have sudo right to use this install (write/read permission in ${INST_PATH}/ )" && exit; fi
} }
inst_launch_workaround(){ inst_launch_workaround(){
if [ -d $PKG_PATH ]; then if [ -d "${PKG_PATH}" ]; then
if [ $(pwd) != $PKG_PATH ]; then cd $PKG_PATH; fi if [ "$(pwd)" != "${PKG_PATH}" ]; then cd "${PKG_PATH}"; fi
fi fi
} }

View File

@ -6,12 +6,12 @@
# NOTE: This requires GNU getopt. On Mac OS X and FreeBSD, you have to install this # NOTE: This requires GNU getopt. On Mac OS X and FreeBSD, you have to install this
# separately; see below. # separately; see below.
TEMP=`getopt -o d: -l destdir: -- "$@"` TEMP=$(getopt -o d: -l destdir: -- "$@")
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
# Note the quotes around `$TEMP': they are essential! # Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP" eval set -- "${TEMP}"
eval set -- "$TEMP" eval set -- "${TEMP}"
while [ $# -gt 0 ] while [ $# -gt 0 ]
do do
case "$1" in case "$1" in
@ -20,26 +20,26 @@ do
shift shift
done done
echo "destdir = $PKG_PATH " echo "destdir = ${PKG_PATH} "
check_inst_right check_inst_right
check_files check_files
mkdir -p $PKG_PATH/bin/ mkdir -p "${PKG_PATH}/bin/"
mkdir -p $PKG_PATH/etc/$PKG/ mkdir -p "${PKG_PATH}/etc/${PKG}/"
mkdir -p $PKG_PATH/usr/$PKG/ mkdir -p "${PKG_PATH}/usr/${PKG}/"
mkdir -p $PKG_PATH/var/$PKG/log mkdir -p "${PKG_PATH}/var/${PKG}/log"
#we copy all file into opt/ dir and treat dir like normal unix arborescence #we copy all file into opt/ dir and treat dir like normal unix arborescence
cp -r db/ $PKG_PATH/var/$PKG/db cp -r db/ "${PKG_PATH}/var/${PKG}/db"
if [ -d log ]; then cp -r log/* $PKG_PATH/var/$PKG/log/; fi if [ -d log ]; then cp -r log/* "${PKG_PATH}/var/${PKG}/log/"; fi
cp -r conf/ $PKG_PATH/etc/$PKG/conf cp -r conf/ "${PKG_PATH}/etc/${PKG}/conf"
cp -r npc/ $PKG_PATH/usr/$PKG/npc cp -r npc/ "${PKG_PATH}/usr/${PKG}/npc"
cp athena-start $PKG_PATH/ cp athena-start "${PKG_PATH}/"
cp *-server* $PKG_PATH/bin/ cp *-server* "${PKG_PATH}/bin/"
ln -fs $PKG_PATH/var/$PKG/db/ $PKG_PATH/db ln -fs "${PKG_PATH}/var/${PKG}/db/" "${PKG_PATH}/db"
ln -fs $PKG_PATH/var/$PKG/log/ $PKG_PATH/log ln -fs "${PKG_PATH}/var/${PKG}/log/" "${PKG_PATH}/log"
ln -fs $PKG_PATH/etc/$PKG/conf/ $PKG_PATH/conf ln -fs "${PKG_PATH}/etc/${PKG}/conf/" "${PKG_PATH}/conf"
ln -fs $PKG_PATH/usr/$PKG/npc/ $PKG_PATH/npc ln -fs "${PKG_PATH}/usr/${PKG}/npc/" "${PKG_PATH}/npc"
ln -fs $PKG_PATH/athena-start /usr/bin/$PKG ln -fs "${PKG_PATH}/athena-start" "/usr/bin/${PKG}"
for f in $(ls $PKG_PATH/bin/) ; do ln -fs $PKG_PATH/bin/$f $PKG_PATH/$f; done for f in $(ls "${PKG_PATH}/bin/") ; do ln -fs "${PKG_PATH}/bin/${f}" "${PKG_PATH}/${f}"; done
echo "Installation is done. You can now control the server with '$PKG start'" echo "Installation is done. You can now control the server with '${PKG} start'"

View File

@ -1,20 +1,20 @@
#!/bin/sh #!/bin/sh
#source var/function #source var/function
. ./function.sh . ./function.sh
echo "My pkg path is $PKG_PATH" echo "My pkg path is ${PKG_PATH}"
check_inst_right check_inst_right
read -p "WARNING: This script is experimental. Press Ctrl+C to cancel or Enter to continue." readEnterKey read -p "WARNING: This script is experimental. Press Ctrl+C to cancel or Enter to continue." readEnterKey
case $1 in case $1 in
'bin') 'bin')
echo "Starting binary cleanup" echo "Starting binary cleanup"
rm -rf $PKG_PATH/bin/* rm -rf "${PKG_PATH:?}"/bin/*
echo "Binary files have been deleted" echo "Binary files have been deleted"
;; ;;
'all') 'all')
echo "Starting uninstall" echo "Starting uninstall"
rm -rf $PKG_PATH rm -rf "${PKG_PATH:?}"
rm -rf /usr/bin/$PKG rm -rf "/usr/bin/${PKG:?}"
echo "Uninstallation has succeed" echo "Uninstallation has succeed"
;; ;;
*) *)