閱讀362 返回首頁    go 阿裏雲 go 技術社區[雲棲]


分享Memcached shell啟動停止腳本

 注意:要使用這個shell,必須先成功建立memcache環境
1》建立memcached文件和權限
[root@luozhonghua ~]# touch /etc/init.d/memcached
[root@luozhonghua ~]# chmod +x /etc/init.d/memcached
2》編寫Memcached shell管理腳本  vi  /etc/init.d/memcached
#!/bin/bash
# memcached  - This shell script takes care of starting and stopping memcached.
#
# chkconfig: - 90 10
# description: Memcache provides fast memory based storage.
# processname: memcached


memcached_path="/usr/local/bin/memcached"
memcached_p
memcached_memory="1024"


# Source function library.
. /etc/rc.d/init.d/functions


[ -x $memcached_path ] || exit 0


RETVAL=0
prog="memcached"


# Start daemons.
start() {
    if [ -e $memcached_pid -a ! -z $memcached_pid ];then
        echo $prog" already running...."
        exit 1
    fi


    echo -n $"Starting $prog "
    # Single instance for all caches
    $memcached_path -m $memcached_memory -l 0.0.0.0 -p 11211 -u root -d -P $memcached_pid
    RETVAL=$?
    [ $RETVAL -eq 0 ] && {
        touch /var/lock/subsys/$prog
        success $"$prog"
    }
    echo
    return $RETVAL
}




# Stop daemons.
stop() {
    echo -n $"Stopping $prog "
    killproc -d 10 $memcached_path
    echo
    [ $RETVAL = 0 ] && rm -f $memcached_pid /var/lock/subsys/$prog


    RETVAL=$?
    return $RETVAL
}


# See how we were called.
case "$1" in
        start)
            start
            ;;
        stop)
            stop
            ;;
        status)
            status $prog
            RETVAL=$?
            ;;
        restart)
            stop
            start
            ;;
        *)
            echo $"Usage: $0 {start|stop|status|restart}"
            exit 1
esac
exit $RETVAL
##############本腳本中的下麵二個配置可根據實際而配置############
#memcached_path="/usr/local/bin/memcached" 
#memcached_memory="1024"


3》 追究該腳本為係統服務
chkconfig --add memcached  
chkconfig memcached on

4》測試(試試手啊)
<p>service memcached start|stop|status|restart </p>

最後更新:2017-04-03 05:39:17

  上一篇:go 計算機常識--框架、編程語言篇
  下一篇:go memcached安裝和驗證