2011-02-02

Tokyo Tyrant 起動スクリプト スレーブ

  1. #! /bin/sh  
  2. # chkconfig: 345 65 55  
  3. # description: Startup script for the server of Tokyo Tyrant For Session  
  4. # processname: tokyotyrant  
  5.   
  6. #----------------------------------------------------------------  
  7. # Startup script for the server of Tokyo Tyrant  
  8. #----------------------------------------------------------------  
  9.   
  10.   
  11. # configuration variables  
  12. prog="ttservctl"  
  13. cmd="ttserver"  
  14. basedir="/home/ttserver/data"  
  15. port="1978"  
  16. pidfile="$basedir/ttserver.pid"  
  17. logfile="$basedir/ttserver.log"  
  18. ulogdir="$basedir/ulog"  
  19. ulimsiz="256m"  
  20. sid=2  
  21. mhost="remotehost1"  
  22. mport="1978"  
  23. rtsfile="$basedir/ttserver.rts"  
  24. dbname="$basedir/session.tct#bnum=1000000#idx=x:dec#dfunit=8"  
  25. ext="/home/ttserver/ext/ttexpire.lua"  
  26. extpc="expire 1"  
  27. maxcon="65535"  
  28. retval=0  
  29.   
  30.   
  31. # setting environment variables  
  32. LANG=C  
  33. LC_ALL=C  
  34. PATH="$PATH:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/tokyotyrant/bin"  
  35. export LANG LC_ALL PATH  
  36.   
  37.   
  38. # start the server  
  39. start(){  
  40.   printf 'Starting the server of Tokyo Tyrant\n'  
  41.   mkdir -p "$basedir"  
  42.   if [ -z "$basedir" ] || [ -z "$port" ] || [ -z "$pidfile" ] || [ -z "$dbname" ] ; then  
  43.     printf 'Invalid configuration\n'  
  44.     retval=1  
  45.   elif ! [ -d "$basedir" ] ; then  
  46.     printf 'No such directory: %s\n' "$basedir"  
  47.     retval=1  
  48.   elif [ -f "$pidfile" ] ; then  
  49.     pid=`cat "$pidfile"`  
  50.     printf 'Existing process: %d\n' "$pid"  
  51.     retval=1  
  52.   else  
  53.     if [ -n "$maxcon" ] ; then  
  54.       ulimit -n "$maxcon" >/dev/null 2>&1  
  55.     fi  
  56.     cmd="$cmd -port $port -dmn -pid $pidfile"  
  57.     if [ -n "$logfile" ] ; then  
  58.       cmd="$cmd -log $logfile"  
  59.     fi  
  60.     if [ -n "$ulogdir" ] ; then  
  61.       mkdir -p "$ulogdir"  
  62.       cmd="$cmd -ulog $ulogdir"  
  63.     fi  
  64.     if [ -n "$ulimsiz" ] ; then  
  65.       cmd="$cmd -ulim $ulimsiz"  
  66.     fi  
  67.     if [ -n "$sid" ] ; then  
  68.       cmd="$cmd -sid $sid"  
  69.     fi  
  70.     if [ -n "$mhost" ] ; then  
  71.       cmd="$cmd -mhost $mhost"  
  72.     fi  
  73.     if [ -n "$mport" ] ; then  
  74.       cmd="$cmd -mport $mport"  
  75.     fi  
  76.     if [ -n "$rtsfile" ] ; then  
  77.       cmd="$cmd -rts $rtsfile"  
  78.     fi  
  79.     if [ -n "$ext" ] ; then  
  80.       cmd="$cmd -ext $ext"  
  81.     fi  
  82.     if [ -n "$extpc" ] ; then  
  83.       cmd="$cmd -extpc $extpc"  
  84.     fi  
  85.     printf "Executing: %s\n" "$cmd"  
  86.     cmd="$cmd $dbname"  
  87.     $cmd  
  88.     if [ "$?" -eq 0 ] ; then  
  89.       printf 'Done\n'  
  90.     else  
  91.       printf 'The server could not started\n'  
  92.       retval=1  
  93.     fi  
  94.   fi  
  95. }  
  96.   
  97.   
  98. # stop the server  
  99. stop(){  
  100.   printf 'Stopping the server of Tokyo Tyrant\n'  
  101.   if [ -f "$pidfile" ] ; then  
  102.     pid=`cat "$pidfile"`  
  103.     printf "Sending the terminal signal to the process: %s\n" "$pid"  
  104.     kill -TERM "$pid"  
  105.     c=0  
  106.     while true ; do  
  107.       sleep 0.1  
  108.       if [ -f "$pidfile" ] ; then  
  109.         c=`expr $c + 1`  
  110.         if [ "$c" -ge 100 ] ; then  
  111.           printf 'Hanging process: %d\n' "$pid"  
  112.           retval=1  
  113.           break  
  114.         fi  
  115.       else  
  116.         printf 'Done\n'  
  117.         break  
  118.       fi  
  119.     done  
  120.   else  
  121.     printf 'No process found\n'  
  122.     retval=1  
  123.   fi  
  124. }  
  125.   
  126.   
  127. # send HUP to the server for log rotation  
  128. hup(){  
  129.   printf 'Sending HUP signal to the server of Tokyo Tyrant\n'  
  130.   if [ -f "$pidfile" ] ; then  
  131.     pid=`cat "$pidfile"`  
  132.     printf "Sending the hangup signal to the process: %s\n" "$pid"  
  133.     kill -HUP "$pid"  
  134.     printf 'Done\n'  
  135.   else  
  136.     printf 'No process found\n'  
  137.     retval=1  
  138.   fi  
  139. }  
  140.   
  141.   
  142. # check permission  
  143. if [ -d "$basedir" ] && ! touch "$basedir/$$" >/dev/null 2>&1  
  144. then  
  145.   printf 'Permission denied\n'  
  146.   exit 1  
  147. fi  
  148. rm -f "$basedir/$$"  
  149.   
  150.   
  151. # dispatch the command  
  152. case "$1" in  
  153. start)  
  154.   start  
  155.   ;;  
  156. stop)  
  157.   stop  
  158.   ;;  
  159. restart)  
  160.   stop  
  161.   start  
  162.   ;;  
  163. hup)  
  164.   hup  
  165.   ;;  
  166. *)  
  167.   printf 'Usage: %s {start|stop|restart|hup}\n' "$prog"  
  168.   exit 1  
  169.   ;;  
  170. esac  
  171.   
  172.   
  173. # exit  
  174. exit "$retval"  
  175.   
  176.   
  177.   
  178. # END OF FILE  

0 件のコメント:

コメントを投稿