memcached在centos下自启动脚本

来源:互联网 发布:中央财经大学命案知乎 编辑:程序博客网 时间:2024/04/30 07:04

转自:http://segmentfault.com/a/1190000002623193


#!/bin/sh

#
# memcached    Startup script for memcached processes
#
# chkconfig: - 90 10
# description: Memcache provides fast memory based storage.
# processname: memcached


[ -f memcached ] || exit 0


memcached="/data/soft/memcached/bin/memcached"
prog=$(basename  $memcached)
port=11211
user=nobody
# memory use
mem=64


start() {
    echo -n $"Starting $prog "
    # Starting memcached with 64MB memory on port 11211 as deamon and user nobody
    $memcached -m $mem -p $port -d -u $user


    RETVAL=$?
    echo
    return $RETVAL
}


stop() {
    if test "x`pidof memcached`" != x; then
        echo -n $"Stopping $prog "
        killall memcached
        echo
    fi
    RETVAL=$?
    return $RETVAL
}


case "$1" in
        start)
            start
            ;;


        stop)
            stop
            ;;


        restart)
            stop
            start
            ;;
        condrestart)
            if test "x`pidof memcached`" != x; then
                stop
                start
            fi
            ;;


        *)
            echo $"Usage: $0 {start|stop|restart|condrestart}"
            exit 1


esac


exit $RETVAL



将脚本保存在 /etc/init.d/目录下,如/etc/init.d/memcached
执行如下命令

chmod +x /etc/init.d/memcachedchkconfig memcached onservice memcached start



0 0
原创粉丝点击