工作需求,需要自己写一个memcached的启动停止脚本,呕心沥血,终于完成,虽然很搓很搓,还是记录一下吧,废话不多说直接上脚本
#! /bin/sh
# ckconfig: - 55 45
# description: The memcached daemon is a network memory cache service.
# processname: memcached
# config: /etc/memcached.conf
# Source function library - for suse linux
. /lib/lsb/init-functions
PORT=11111
USER=memcache
#最大连接数,根据实际需求修改
MAXCONN=1024
#最大内存量,单位M
CACHESIZE=400
PID=`ps -ef|grep memcache|grep -v grep|awk '{print $2}'`
prog="Memcached"
PIDFILE="/tmp/memcache.pid"
DAEMON=/usr/bin/memcached
start () {
if [ ! -n "$PID" ]; then
echo -n -e $"\033[35mStarting $prog:\033[0m"
/usr/bin/memcached -m $CACHESIZE -l 127.0.0.1 -p $PORT -d -u $USER -c $MAXCONN -P /tmp/memcache.pid
if [ `echo $?` == 0 ];then
echo -e "\033[32mRun $prog Successful!\033[0m"
else
echo -e "\033[41;33mRun $prog Fail!\033[0m"
fi;
exit 1
else
echo -e "\033[41;37m$prog has been running!Don't repeat\033[0m"
exit 0
fi;
}
stop () {
if [ -n "$PID" ]; then
echo -n -e $"\033[35mStopping $prog:\033[0m"
#sudo kill $PID
start-stop-daemon --stop --quiet --oknodo --retry 5 --pidfile $PIDFILE --exec $DAEMON
if [ `echo $?` -eq 0 ] ; then
echo -e "\033[32mStop $prog Successfull!\033[0m"
else
echo -e "\033[41;33Stop $prog Fail!Please try again!\033[0m"
fi;
else
echo -e "\033[34m$prog Not Running!\033[0m"
fi;
}
restart () {
echo -n -e $"\033[35mStopping $prog:\033[0m"
start-stop-daemon --stop --quiet --oknodo --retry 5 --pidfile $PIDFILE --exec $DAEMON
if [ `echo $?` -eq 0 ] ; then
echo -e "\033[32mStop $prog Successfull!\033[0m"
else
echo -e "\033[41;33Stop $prog Fail!Please try again!\033[0m"
fi;
echo -n -e $"\033[35mStarting $prog:\033[0m"
/usr/bin/memcached -m $CACHESIZE -l 127.0.0.1 -p $PORT -d -u $USER -c $MAXCONN -P /tmp/memcache.pid
if [ `echo $?` == 0 ];then
echo -e "\033[32mRun $prog Successful!\033[0m"
else
echo -e "\033[41;33mRun $prog Fail!\033[0m"
fi;
exit 1
}
status () {
if [ ! -n "$PID" ]; then
echo -e "\033[32m$prog Stopped!\033[0m"
else
echo -e "\033[32m$prog Running!\033[0m"
fi;
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 1
esac
exit $?
阅读(3987) | 评论(1) | 转发(0) |