首页 > 代码库 > ubuntu下memcached启动停止脚本
ubuntu下memcached启动停止脚本
工作需求,需要自己写一个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 $?
本文出自 “风之别鹤” 博客,请务必保留此出处http://addam.blog.51cto.com/5041993/1408514
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。