分享Memcachedshell启动停止脚本

WBOY
Lepaskan: 2016-06-07 15:58:38
asal
1010 orang telah melayarinya

注意:要使用这个shell,必须先成功建立memcache环境1》建立memcached文件和权限[root@luozhonghua ~]# touch /etc/init.d/memcached[root@luozhonghua ~]# chmod +x /etc/init.d/memcached2》编写Memcached shell管理脚本 vi /etc/init.d/memcached#!/bin/b

注意:要使用这个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_pid="/var/run/memcached.pid"
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
Salin selepas log masuk
4》测试(试试手啊)
Salin selepas log masuk
<p>service memcached start|stop|status|restart </p>
Salin selepas log masuk
Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan