#!/bin/bash
#
# memcached    Startup script for the memcached Server
#
# chkconfig: - 85 65
# description: memcached is general purpose caching deamon
# processname: memcached
# config: /etc/sysconfig/memcached
# pidfile: /var/run/memcached.pid

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

if [ -f /etc/sysconfig/memcached ]; then
        . /etc/sysconfig/memcached
else
	OPTIONS="-d -m 512 -l 127.0.0.1 -p 11211 -u nobody"
fi

memcached=/usr/sbin/memcached
prog=memcached
pidfile=${PIDFILE-/var/run/memcached.pid}
lockfile=${LOCKFILE-/var/lock/subsys/memcached}
RETVAL=0

start() {
        echo -n $"Starting $prog: "
        daemon $memcached $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}

stop() {
	echo -n $"Stopping $prog: "
	killproc $memcached
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
	echo -n $"Reloading $prog: "
	killproc $memcached -HUP
	RETVAL=$?
	echo
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
        status $memcached
	RETVAL=$?
	;;
  restart)
	stop
	start
	;;
  *)
	echo $"Usage: $prog {start|stop|restart}"
	exit 1
esac

exit $RETVAL
