#!/bin/bash
#
# memcached This shell script takes care of starting and stopping
# the MemcacheD service (memcached).
#
# chkconfig: - 60 30
# description: MemcacheD server.
# processname: memcached
# pidfile: /var/run/memcached/memcached.pid
# Source function library.
. /etc/rc.d/init.d/functions
prog=/usr/local/bin/memcached
username=memcached # Avoid running as root
memory_max=256 # Default 64 MB
port=11211
host=127.0.0.1
# Values based on CentOS 5.x
PID=/var/run/memcached/memcached.pid
LOCK=/var/lock/subsys/memcached
start(){
$prog -d -l $host -u $username -m $memory_max -P $PID > /dev/null 2>&1 &
ret=$?
if [ $ret -eq 0 ] && touch $LOCK;
then
action $"Starting $prog: " /bin/true
else
ret=1
action $"Startng $prog: " /bin/false
fi
return $ret
}
stop(){
MEMCACHEDPID=$(cat "$PID" 2>/dev/null)
if [ -n "$MEMCACHEDPID" ]; then
/bin/kill "$MEMCACHEDPID" > /dev/null 2>&1
ret=$?
if [ $ret -eq 0 ]; then
STOPTIMEOUT=60
while [ $STOPTIMEOUT -gt 0 ]; do
/bin/kill -0 "$MEMCACHEDPID" > /dev/null 2>&1 || break
sleep 1
let STOPTIMEOUT=${STOPTIMEOUT}-1
done
if [ $STOPTIMEOUT -eq 0 ]; then
echo "Timeout error occurred trying to stop MemcacheD Daemon."
ret=1
action $"Stopping $prog: " /bin/false
else
rm -f $LOCK
action $"Stopping $prog: " /bin/true
fi
else
action $"Stopping $prog: " /bin/false
fi
else
ret=1
action $"Stopping $prog: " /bin/false
fi
return $ret
}
restart(){
start
stop
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status memcached
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 1
esac
exit $?