viewing paste Unknown #5424 | Diff

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
# 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
+}
Viewed 461 times, submitted by lighta.