# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /home/lighta/Documents/Myscript/RO/Servs/rathena # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: athena-start --- athena-start Base (BASE) +++ athena-start Locally Modified (Based On LOCAL) @@ -1,64 +1,87 @@ #!/bin/sh -# athena starting script by rowla -# modified by shazeya@syafi.com (NL101541) -PATH=./:$PATH +#source var/function +. ./function.sh +inst_launch_workaround -L_SRV=login-server_sql -C_SRV=char-server_sql -M_SRV=map-server_sql - +PATH=./:$PATH print_start() { # more << EOF echo "Athena Starting..." -echo " (c) 2003 Athena Project" -echo " modified by shazeya@syafi.com" + echo " (c) 2013 rAthena Project" echo "" -#echo "Debug informations will appear," -#echo "since this is a test release." -#echo "" + echo "" echo "checking..." #EOF } -check_files() { - - for i in ${L_SRV} ${C_SRV} ${M_SRV} - do - if [ ! -f ./$i ]; then - echo "$i does not exist, or can't run." - echo "Stop. Check your compile." - exit 1; +get_status(){ + PIDFILE=.$1.pid + if [ -e ${PIDFILE} ]; then + ISRUN=$(ps ax | grep $(cat ${PIDFILE}) | grep $1) + PSRUN=$(echo "$ISRUN" | awk '{ print substr( $0, 0, 7) }') fi - done +} -# more << EOF -echo "Check complete." -echo "Looks good, a nice Athena!" -#EOF +#cheking if already started, launch and mark in log +start_serv(){ + LOGFILE="log/$1.log" + get_status $1 + echo "My logfile=${LOGFILE}" + if [ -z ${PSRUN} ]; then + exec ./$1& + echo $! > .$1.pid + echo "Server '$1' started at `date +"%m-%d-%H:%M-%S"`" >> ${LOGFILE} + else + echo "Can't start '$1', cause is already running p${PSRUN}" >> ${LOGFILE} + fi } +#experimental +watch_serv(){ + LOGFILE=./log/$1.log + ulimit -Sc unlimited + while true; do + get_status $1 + if [ -z ${PSRUN} ]; then + $count=$count+1 + echo "server '$1' is down" >> ${LOGFILE} + echo "restarting server at time at `date +"%m-%d-%H:%M-%S"`">> ${LOGFILE} + exec ./$1& + echo $! > .$1.pid + if [ $3 ] && [ $3 -lt $count ]; then break; fi + else sleep $2 + fi + done +} + case $1 in 'start') print_start check_files - - exec ./${L_SRV}& - echo $! > .${L_SRV}.pid - exec ./${C_SRV}& - echo $! > .${C_SRV}.pid - exec ./${M_SRV}& - echo $! > .${M_SRV}.pid - + echo "Check complete." + echo "Looks good, a nice Athena!" + for i in ${L_SRV} ${C_SRV} ${M_SRV} + do + start_serv $i + done echo "Now Started Athena." ;; + 'watch') + for i in ${L_SRV} ${C_SRV} ${M_SRV} + do + watch_serv $i 10 3 + done + echo "Now watching Athena." +;; 'stop') - for i in .${L_SRV}.pid .${C_SRV}.pid .${M_SRV}.pid + for i in ${L_SRV} ${C_SRV} ${M_SRV} do - if [ -e ./$i ]; then - kill $(cat $i) - rm $i + PIDFILE=.${i}.pid + if [ -e ./${PIDFILE} ]; then + kill $(cat ${PIDFILE}) + rm ${PIDFILE} fi done ;; @@ -66,7 +89,16 @@ $0 stop $0 start ;; + 'status') + for i in ${L_SRV} ${C_SRV} ${M_SRV} + do + get_status ${i} + if [ ${PSRUN} ]; then echo "'${i}' is running p${PSRUN}"; else echo "'${i}' seem down"; fi + done +;; *) - echo "Usage: athena-start { start | stop | restart }" + echo "Usage: athena-start { start | stop | restart | status | watch }" ;; esac + + Index: function.sh --- function.sh No Base Revision +++ function.sh Locally New @@ -0,0 +1,26 @@ +L_SRV=login-server_sql +C_SRV=char-server_sql +M_SRV=map-server_sql +INST_PATH=/opt +PKG=rathena +PKG_PATH=$INST_PATH/$PKG + +check_files() { + for i in ${L_SRV} ${C_SRV} ${M_SRV} + do + if [ ! -f ./$i ]; then + echo "$i does not exist extiting" + exit 1; + fi + done +} + +check_inst_right(){ + if [ ! -w $INST_PATH ]; then echo "You must have sudo right to use this install (writte/read permission in /opt/ )" && exit; fi +} + +inst_launch_workaround(){ + if [ -d $PKG_PATH ]; then + if [ $(pwd) != $PKG_PATH ]; then cd $PKG_PATH; fi + fi +}