Chinaunix首页 | 论坛 | 博客
  • 博客访问: 332046
  • 博文数量: 53
  • 博客积分: 1132
  • 博客等级: 少尉
  • 技术积分: 451
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-18 14:22
文章分类

全部博文(53)

文章存档

2014年(1)

2013年(11)

2012年(17)

2011年(16)

2010年(8)

分类: LINUX

2011-07-18 08:32:20

Tokyo Tyrant 启动脚本,mhost、mport 为可选参数,如果要使用双机主辅模式就得启用这两个参数

  1. #!/bin/bash
  2. #
  3. # chkconfig: - 90 90
  4. # description: The Tokyo Tyrant daemon is a network memory cache service.
  5. # processname: ttserver
  6. #----------------------------------------------------------------
  7. # Startup script for the server of Tokyo Tyrant
  8. #----------------------------------------------------------------

  9. # source function library
  10. . /etc/rc.d/init.d/functions

  11. # configuration variables
  12. prog="ttservctl"
  13. cmd="/usr/local/bin/ttserver"
  14. basedir="/data/ttserver"
  15. host="192.168.11.126"
  16. port="11211"
  17. thnum="8"
  18. pidfile="/tmp/ttserver.pid"
  19. logfile="/var/log/ttserver.log"
  20. ulogdir="/data/ttserver"
  21. ulimsiz="128m"
  22. sid=20
  23. #mhost="192.168.11.88"
  24. mhost=""
  25. mport=""
  26. #mport="11211"
  27. rtsfile="$basedir/ttserver.rts"
  28. dbname="$basedir/database.tch"
  29. maxcon="65535"
  30. retval=0

  31. # setting environment variables
  32. LANG=C
  33. LC_ALL=C
  34. PATH="$PATH:/sbin:/usr/sbin:/usr/local/sbin"
  35. export LANG LC_ALL PATH

  36. # start the server
  37. start(){
  38.     printf 'Starting the server of Tokyo Tyrant\n'
  39.     /bin/mkdir -p "$basedir"
  40.     if [[ -z "$basedir" ]] || [[ -z "$port" ]] || [[ -z "$pidfile" ]] || [[ -z "$dbname" ]];then
  41.         printf 'Invalid configuration\n'
  42.         retval=1
  43.     elif [[ ! -d "$basedir" ]];then
  44.         printf 'No such directory: %s\n' "$basedir"
  45.         retval=1
  46.     elif [[ -f "$pidfile" ]];then
  47.         pid=$(/bin/cat $pidfile)
  48.         printf 'Existing process: %d\n' "$pid"
  49.         printf "Please delete $pidfile!\n"
  50.         retval=1
  51.     else
  52.         if [[ -n "$maxcon" ]];then
  53.             ulimit -n "$maxcon" > /dev/null 2>&1
  54.         fi
  55.             cmd="$cmd -host $host -port $port -thnum $thnum -dmn -pid $pidfile"
  56.         if [[ -n "$logfile" ]];then
  57.             cmd="$cmd -log $logfile -le"
  58.         fi
  59.         if [[ -n "$ulogdir" ]];then
  60.             cmd="$cmd -ulog $ulogdir"
  61.         fi
  62.         if [[ -n "$ulimsiz" ]];then
  63.             cmd="$cmd -ulim $ulimsiz"
  64.         fi
  65.         if [[ -n "$sid" ]];then
  66.             cmd="$cmd -sid $sid"
  67.         fi
  68.         if [[ -n "$mhost" ]];then
  69.             cmd="$cmd -mhost $mhost"
  70.         fi
  71.         if [[ -n "$mport" ]];then
  72.             cmd="$cmd -mport $mport"
  73.         fi
  74.         if [[ -n "$rtsfile" ]];then
  75.             cmd="$cmd -rts $rtsfile"
  76.         fi
  77.             printf "Executing: %s\n" "$cmd"
  78.             cmd="$cmd $dbname"
  79.         $cmd
  80.         RETVAL=$?
  81.         if [[ "$RETVAL" -eq 0 ]];then
  82.             /bin/touch /var/lock/subsys/ttserver
  83.             printf 'Done\n'
  84.         else
  85.             printf 'The server could not started\n'
  86.             retval=1
  87.         fi
  88.     fi
  89. }

  90. # stop the server
  91. stop(){
  92.     printf 'Stopping the server of Tokyo Tyrant\n'
  93.     if [[ -f "$pidfile" ]];then
  94.         pid=$(/bin/cat "$pidfile")
  95.         printf "Sending the terminal signal to the process: %s\n" "$pid"
  96.         /bin/kill -TERM "$pid"
  97.         c=0
  98.         while true ; do
  99.             /bin/sleep 1
  100.             if [[ -f "$pidfile" ]];then
  101.                 c=$(expr $c + 1)
  102.                 if [[ "$c" -ge 100 ]];then
  103.                     printf 'Hanging process: %d\n' "$pid"
  104.                     retval=1
  105.                     break
  106.                 fi
  107.             else
  108.                 /bin/rm -f /var/lock/subsys/ttserver
  109.                 printf 'Done\n'
  110.                 break
  111.             fi
  112.         done
  113.     else
  114.         printf 'No process found\n'
  115.         retval=1
  116.     fi
  117. }

  118. # send HUP to the server for log rotation
  119. hup(){
  120.     printf 'Sending HUP signal to the server of Tokyo Tyrant\n'
  121.     if [[ -f "$pidfile" ]];then
  122.         pid=$(cat "$pidfile")
  123.         printf "Sending the hangup signal to the process: %s\n" "$pid"
  124.         kill -HUP "$pid"
  125.         printf 'Done\n'
  126.     else
  127.         printf 'No process found\n'
  128.         retval=1
  129.     fi
  130. }


  131. # check permission
  132. if [[ -d "$basedir" && ! $(/bin/touch "$basedir/$$" >/dev/null 2>&1) ]];then
  133.     /bin/rm -f "$basedir/$$"
  134. else
  135.     printf 'Permission denied\n'
  136. exit 1
  137. fi

  138. # dispatch the command
  139. case "$1" in
  140.     start)
  141.         start
  142.         ;;
  143.     stop)
  144.         stop
  145.         ;;
  146.     restart)
  147.         stop
  148.         start
  149.         ;;
  150.     status)
  151.         status -p $pidfile ttserver
  152.         retval=$?
  153.         ;;
  154.     hup)
  155.         hup
  156.         ;;
  157.     *)
  158.         printf 'Usage: %s {start|stop|restart|hup}\n' "$prog"
  159.         exit 1
  160.         ;;
  161. esac

  162. exit "$retval"

阅读(1302) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~