Memcahed服务sysvint开机自启动脚本

Memcahed服务sysvint开机自启动脚本

#!/bin/sh
#
# Memcached - Startup script for Memcached
# chkconfig: - 85 15
# description: Memcached server
# processname: Memcached
# pidfile: /var/run/memcached/memcached.pid

# Source function library.
. /etc/rc.d/init.d/functions

MEMCACHED="/usr/local/memcached/bin/memcached"
USERNAME="memcached"
PORT="11211"
MAXCONN="1024"
MAXSIZE="1G"
OPTIONS=""
RETVAL=0
prog=$(basename $MEMCACHED)
pidfile="/var/run/memcached/memcached.pid"
lockfile="/var/lock/subsys/memcached"

START() {
	if [[ -e ${lockfile} ]];then
		status $prog
	else
		[ -d "/var/run/memcached" ] || mkdir /var/run/memcached
		[ "$(stat -c %U /var/run/memcached)" != "$USERNAME" ] && chown $USERNAME /var/run/memcached
		echo -n $"Starting $prog: "
		daemon --pidfile ${pidfile} $MEMCACHED -d -p $PORT -u $USERNAME -m $MAXSIZE -c $MAXCONN -P ${pidfile} $OPTIONS
		RETVAL=$?
		echo
		[ $RETVAL -eq 0 ] && touch ${lockfile}
	fi
}

STOP() {
	echo -n $"Stopping $prog: "
	killproc -p ${pidfile} $MEMCACHED
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f ${lockfile} ${pidfile}
}

STATUS() {
	status $prog
}

# mian
case $1 in
	start)
		START
		;;
	stop)
		STOP
		;;
	restart)
		STOP
		sleep 2
		START
		;;
	status)
		STATUS
		;;
	*)
		echo $"Usage:$0{start|stop|restart|status}"
esac

exit $RETVAL