memcached在centos下自启动脚本

脚本内容如下

脚本内变量memchached port user mem根据个人需求自己修改

sh#!/bin/sh
#
# memcached Startup script for memcached processes
#
# chkconfig: - 90 10
# description: Memcache provides fast memory based storage.
# processname: memcached
[ -f memcached ] || exit 0
memcached="/data/soft/memcached/bin/memcached"
prog=$(basename $memcached)
port=11211
user=nobody
# memory use
mem=64
start() {
 echo -n $"Starting $prog "
 # Starting memcached with 64MB memory on port 11211 as deamon and user nobody
 $memcached -m $mem -p $port -d -u $user
 RETVAL=$?
 echo
 return $RETVAL
}
stop() {
 if test "x`pidof memcached`" != x; then
 echo -n $"Stopping $prog "
 killall memcached
 echo
 fi
 RETVAL=$?
 return $RETVAL
}
case "$1" in
 start)
 start
 ;;
 stop)
 stop
 ;;
 restart)
 stop
 start
 ;;
 condrestart)
 if test "x`pidof memcached`" != x; then
 stop
 start
 fi
 ;;
 *)
 echo $"Usage: $0 {start|stop|restart|condrestart}"
 exit 1
esac
exit $RETVAL

将脚本保存在 /etc/init.d/目录下,如/etc/init.d/memcached
执行如下命令

shchmod +x /etc/init.d/memcached
chkconfig memcached on
service memcached start
作者:luxixing原文地址:https://segmentfault.com/a/1190000002623193

%s 个评论

要回复文章请先登录注册