If memcached has been installed in Linux and is deployed to the/usr/local/memcached path, next we will begin to install service management scripts for it to start and stop.
First of all, through VI in the/ETC/RC.D/INIT.D path to create a new script file named memcached, the command is as follows:
| The code is as follows |
Copy Code |
|
Vi/etc/rc.d/init.d/memcached |
Then, write the shell script to it as follows:
| The code is as follows |
Copy Code |
|
#!/bin/sh
#
# chkconfig:2345 90 50
# description:memcached Service Daemon
#
# processname:memcached
#
# Source function library.
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
#[${networking} = ' No '] && exit 0
#[-r/etc/sysconfig/dund] | | Exit 0
#. /etc/sysconfig/dund
#[-Z "$DUNDARGS"] && exit 0
Memcached= "/usr/local/memcached/bin/memcached"
Start ()
{
Echo-n $ "Starting Memcached:"
Daemon $MEMCACHED-u daemon-d-M 32-l 127.0.0.1-p 11211-c 256-p/tmp/memcached.pid
Echo
}
Stop ()
{
Echo-n $ "Shutting down Memcached:"
Killproc memcached
Echo
}
[f $MEMCACHED] | | Exit 1
# How we were called.
Case "$" in
Start
Start
;;
Stop
Stop
;;
Restart)
Stop
Sleep 3
Start
;;
*)
echo $ "Usage: $ {Start|stop|restart}"
Exit 1
Esac
Exit 0 |
After saving exit VI, execute the following command to install the script
| The code is as follows |
Copy Code |
|
chmod 777/etc/rc.d/init.d/memcached
Chkconfig--add memcached
Chkconfig--level 235 memcached on |
You can then check to see if the installation was successful by using the following command
| code is as follows |
copy code |
|
Chkconfig- List | grep memcached
Service memcached start
Service memcached Stop
Service memcached restart |