memcachedサーバを起動してから起動するように設定します。

2044 ワード

参考:http://www.phperz.com/article/14/1130/38438.html
#! /bin/bash  
#  
# memcached     start/stop the memcached daemon  
#  
# chkconfig: 35 80 70  
# description: memcached is a memory cache server.  
#  
 
prog="memcached"  
exec=/usr/local/memcached/bin/memcached  
lockfile=/var/lock/subsys/memcached  
 
# source function library.  
. /etc/rc.d/init.d/functions  
 
# Source networking configuration.
. /etc/sysconfig/network
 
[ "$NETWORKING" = "no" ] && exit 0
 
start() {  
    if [ $UID -ne 0 ]; then  
        echo "User has insufficient privilege."  
        exit 4  
    fi  
    [ -x $exec ] || exit 5  
    echo -n $"starting $prog: "  
    daemon $exec -d -m 512 -u root -p 11211 -c 1024 -P /tmp/memcached.pid
    retval=$?  
    echo  
    [ $retval -eq 0 ] && touch $lockfile  
}  
 
stop() {  
    if [ $UID -ne 0 ]; then  
        echo "User has insufficient privilege."  
        exit 4  
    fi  
    echo -n $"Stopping $prog: "  
        if [ -n "`pidfileofproc $exec`" ]; then  
                killproc $exec  
 
        else  
                failure $"stopping $prog"  
        fi  
    retval=$?  
    echo  
    [ $retval -eq 0 ] && rm -f $lockfile  
}  
 
restart() {  
    stop  
    start  
}  
 
rh_status() {  
    # run checks to determine if the service is running or use generic status  
    status $prog  
}  
 
rh_status_q() {  
    rh_status >/dev/null 2>&1  
}  
 
case "$1" in  
    "start")  
        rh_status_q && exit 0  
        $1  
        ;;  
    "stop")  
        rh_status_q || exit 0  
        $1  
        ;;  
    "restart")  
        rh_status_q || exit 7  
        $1  
        ;;  
    "status")  
        rh_status  
        ;;  
    *)  
        echo $"Usage: $0 {start|stop|status|restart}"  
        exit 2  
        ;;  
esac
chmod+x/etc/init.d/memcached
chkconfig  --level 235  memcached  オン