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