用户登录
用户注册

分享至

memcached启动参数

  • 作者: 人间哪有真情在4764797
  • 来源: 51数据库
  • 2020-10-18

要将memcached作为系统服务启动,需要在/etc/init.d/目录下新建一个脚本,名称为:memcached。内容如下:

[plain] view plain copy 

#! /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  


start() {  

    if [ $UID -ne 0 ]; then  

        echo "User has insufficient privilege."  

        exit 4  

    fi  

    [ -x $exec ] || exit 5  

    echo -n $"starting $prog: "  

    daemon $exec -u root -d -P /var/run/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  

exit $?  

    此脚本使用了functions文件里的函数,因此需要将其加载进来。

    因为要判断memcached服务的运行状态,所以在调用memcached程序时,传递了pid文件参数。因为在此脚本中判断运行状态以及停止memcached服务时,是使用pid文件来进行的。

    由上面的脚本可以看出,提供了四个动作:start、stop、status、restart。

memcached服务的启动

    通过执行以下命令可以使memcached服务启动:

[plain] view plain copy 

[root@rhl6 init.d]# service memcached start  

starting memcached:                                        [  OK  ]  

    或

[plain] view plain copy 

[root@rhl6 init.d]# ./memcached start  

starting memcached:                                        [  OK  ]  

memcached服务开机启动

    查看memcached服务是否在chkconfig管理列表:

[plain] view plain copy 

[root@rhl6 init.d]# chkconfig --list memcached  

service memcached supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add memcached')  

    由提示信息可以看出,memcached还没有加入chkconfig管理,将其加入chkconfig管理:

[plain] view plain copy 

[root@rhl6 init.d]# chkconfig --add memcached  


再次查看memcached服务被管理:

[plain] view plain copy 

[root@rhl6 init.d]# chkconfig --list memcached  

memcached       0:off   1:off   2:off   3:on    4:off   5:on    6:off  

    可以看到,在运行级别3、5上,memcached服务已经设置为开机启动了。这个设置是在shell脚本中设置的(上面脚本第五行):


[plain] view plain copy 

# chkconfig: 35 80 70  


软件
前端设计
程序设计
Java相关