用过TT数据库的人都知道,启动tt服务的命令非常的复杂,一不小心可能出错,所以,自己编写了一个启动的脚本
[codesyntax lang=”text”]
#!/bin/bash
. /etc/init.d/functions
#directories & files
BASEDIR=/application/tokyotyrant
DATADIR=$BASEDIR/data/project1
FilterChar="project1"
PROG=$BASEDIR/bin/ttserver
PIDFILE=$DATADIR/ttserver.pid
ULOGDIR=$DATADIR/ulog
LOGFILE=$DATADIR/ttserver.log
RTSFILE=$DATADIR/ttserver.rts
DBFILE=$DATADIR/ttserver.tch
#option
DBPARAMS="#bnum=1999"
THNUM="-thnum 4"
MUL="-mul 4"
ULIM="-ulim 16m"
FLAGS="-le -uas"
PID="-pid $PIDFILE"
LOG="-log $LOGFILE"
RTS="-rts $RTSFILE"
ULOG="-ulog $ULOGDIR"
PORT="-port 14001"
SID="-sid 14001"
MHOST="-mhost 127.0.0.1"
MPORT="-mport 14001"
MASK=""
DMN="-dmn"
#startup
case $1 in
start)
?????? test -d $DATADIR || mkdir -p $DATADIR
?????? test -d $ULOGDIR || mkdir -p $ULOGDIR
?????? if [ `ps -ef|grep "$FilterChar"|grep -v grep|wc -l` -ge 1 ]
????????????? then
???????????????????? action "TTService $FilterChar is running..." /bin/true;
???????????????????? exit 1
????????????? else
???????????????????? $PROG $DMN $SID $HOST $PORT $PID $ULOG $LOG $RTS $THNUM $ULIM $MUL \
???????????????????? ? $MHOST $MPORT $MASK $FLAGS "$DBFILE${DBPARAMS}"
???????????????????? [ $? -eq 0 ] && action "TTServiece $FilterChar is started..." /bin/true
????????????? fi
????????????? ;;
stop)
?????? if [ `ps -ef|grep "$FilterChar"|grep -v grep|wc -l` -lt 1 ]
????????????? then
???????????????????? action "TTService $FilterChar is stopped" /bin/false;
??????????????????????? exit 1
????????????? else
???????????????????? test -f $PIDFILE && kill $(cat $PIDFILE)
???????????????????? [ $? -eq 0 ] && action "TTService $FilterChar is stopped..." /bin/true
????????????? fi
????????????? ;;
status)
?????? if test -f $PIDFILE && kill -s 0 $(cat $PIDFILE) >/dev/null 2>&1; then
????????????? action "TTService $FilterChar is running..." /bin/true
?????? else
????????????? action "TTService $FilterChar is stopped..." /bin/false
?????? fi
?????? ;;
*)
?????? echo "USAGE:$0 start|stop|status"
?????? exit 1
?????? ;;
esac
[/codesyntax]
看看效果
开发Tokyo Cabinet/Tyrant启动脚本

