2013年3月31日星期日

twemproxy deployment


更新autoconf 
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.68.tar.xz
xz -d autoconf-2.68.tar.xz
tar -xf autoconf-2.68.tar
cd autoconf-2.68
./configure && make && make install
 
wget https://github.com/twitter/twemproxy/zipball/master --no-check-certificate
unzip master
cd twitter-twemproxy
/usr/local/bin/autoreconf -fiv  #autoreconf 版本要是前面装的版本,不是系统默认版本太旧不支持。
./configure --prefix=/home/twemproxy --enable-debug=log
make && make install
cp -R conf /home/twemproxy/
 
启动脚本(start script):
 
#! /bin/sh
 
nutcracker_BIN=/home/twemproxy/bin/nutcracker
nutcracker_CONF=/home/twemproxy/conf/nutcracker.yml
nutcracker_PID=/home/twemproxy/nutcracker.pid
 
nutcracker_opts="-d -o /home/twemproxy/nut.log -s 22120 -c $nutcracker_CONF -p $nutcracker_PID -v 5 -m 512"
 
 
wait_for_pid () {
        try=0
 
        while test $try -lt 35 ; do
 
                case "$1" in
                        'created')
                        if [ -f "$2" ] ; then
                                try=''
                                break
                        fi
                        ;;
 
                        'removed')
                        if [ ! -f "$2" ] ; then
                                try=''
                                break
                        fi
                        ;;
                esac
 
                echo -n .
                try=`expr $try + 1`
                sleep 1
 
        done
 
}
 
case "$1" in
        start)
                echo -n "Starting nutcracker "
 
                $nutcracker_BIN $nutcracker_opts
 
                if [ "$?" != 0 ] ; then
                        echo " failed"
                        exit 1
                fi
 
                wait_for_pid created $nutcracker_PID
 
                if [ -n "$try" ] ; then
                        echo " failed"
                        exit 1
                else
                        echo " done"
                fi
        ;;
 
        stop)
                echo -n "Gracefully shutting down nutcracker "
 
                if [ ! -r $nutcracker_PID ] ; then
                        echo "warning, no pid file found - nutcracker is not running ?"
                        exit 1
                fi
 
                kill -QUIT `cat $nutcracker_PID` && rm -rf $nutcracker_PID
 
                wait_for_pid removed $nutcracker_PID
 
                if [ -n "$try" ] ; then
                        echo " Stop failed. "
                        exit 1
                else
                        echo " done"
                fi
        ;;
 
        restart)
                $0 stop
                $0 start
        ;;
 
        reload)
 
                echo -n "Reload service nutcracker "
 
                if [ ! -r $nutcracker_PID ] ; then
                        echo "warning, no pid file found - nutcracker is not running ?"
                        exit 1
                fi
 
                kill -USR2 `cat $nutcracker_PID` && rm -rf $nutcracker_PID
 
                echo " done"
        ;;
 
        *)
                echo "Usage: $0 {start|stop|restart|reload}"
                exit 1
        ;;
 
esac
 

没有评论:

发表评论