Memcached service start-up and boot

Source: Internet
Author: User

memcached Startup scripts

In the previous blog "redhat Linux installation memcached" , we have described how to install memcached. This article will focus on how to start the memcached as a system service and boot up.

According to the previous blog, " know Linux system Services (daemons)," to start memcached as a system service, you need to create a new script in the/etc/init.d/directory, named: memcached. The contents are as follows:

#! /bin/bash## memcached start/stop The memcached daemon## chkconfig:35-70# description:memcached is a memory cache Server. #prog = "memcached" exec=/usr/local/memcached/bin/memcachedlockfile=/var/lock/subsys/memcached# source function library.        /etc/rc.d/init.d/functionsstart () {if [$UID-ne 0]; then the 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 Insufficien        T 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 Determi NE If the service is running or use generic status status $prog}rh_status_q () {rh_status >/dev/null 2>&1}case "$" in "start")    Rh_status_q && exit 0 $;; "Stop") rh_status_q | |    Exit 0 $;; "Restart") rh_status_q | |    Exit 7 $;;    "Status") rh_status;; *) echo $ "Usage: $ Start|stop|status|restart}" exit 2;; Esacexit $?

This script uses the functions in the functions file, so it needs to be loaded in.

Because you want to determine the running state of the memcached service, the pid file parameter is passed when the memcached program is called. The PID file is used to determine the running state and to stop the memcached service in this script.

As can be seen from the above script, four actions are provided: Start, stop, status, restart.

Memcached Service Start-up

The memcached service can be started by executing the following command:

[[Email protected] init.d]# service memcached startstarting memcached:                                        [  OK  ]

Or

[Email protected] init.d]#/memcached startstarting memcached:                                        [  OK  ]
memcached Service boot up

To see if the memcached service is in the Chkconfig management list:

[Email protected] init.d]# chkconfig--list memcachedservice memcached supports Chkconfig, but isn't referenced in any R Unlevel (Run ' chkconfig--add memcached ')

As can be seen from the hint message, memcached has not joined Chkconfig management to add it to chkconfig management:

<p><pre class= "plain" name= "code" >[[email protected] init.d]# chkconfig--add memcached

Check again to see that the memcached service is managed:

[Email protected] init.d]# chkconfig--list memcachedmemcached       0:off   1:off   2:off    3:on 4:off   5:on    6:off

As you can see, at run Level 3, 5, the memcached service has been set to boot up. This setting is set in the shell script (line fifth above):

# CHKCONFIG:35 80 70









Memcached service start-up and boot

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.