Skip to content

Instantly share code, notes, and snippets.

@keithpitt
Created July 28, 2010 01:49
Show Gist options
  • Save keithpitt/493174 to your computer and use it in GitHub Desktop.
Save keithpitt/493174 to your computer and use it in GitHub Desktop.
#! /bin/sh
#
# chkconfig: - 55 45
# description: The memcached daemon is a network memory cache service.
# processname: memcached
# config: /etc/sysconfig/memcached
# Standard LSB functions
#. /lib/lsb/init-functions
# Source function library.
. /etc/init.d/functions
PORT1=11211
PORT2=11212
PORT3=11213
USER=nobody
MAXCONN=1024
MEM=512
OPTIONS=""
if [ -f /etc/sysconfig/memcached ];then
. /etc/sysconfig/memcached
fi
# Check that networking is up.
if [ "$NETWORKING" = "no" ]
then
exit 0
fi
RETVAL=0
prog="memcached"
# This init script has been edited by Rackspace
pidfile1=/var/run/memcached/memcached1.pid
pidfile2=/var/run/memcached/memcached2.pid
pidfile3=/var/run/memcached/memcached3.pid
redhat_version=`awk '{print $7}' /etc/redhat-release`
if [ $redhat_version = 3 -o $redhat_version = 4 ]; then
startopts1=
startopts2=
startopts3=
stopopts1=
stopopts2=
stopopts3=
else
startopts1="--pidfile $pidfile1"
startopts2="--pidfile $pidfile2"
startopts3="--pidfile $pidfile3"
stopopts1="-p $pidfile1"
stopopts2="-p $pidfile2"
stopopts3="-p $pidfile3"
fi
if [ -z $ADDRESS ]; then
ADDRESS=127.0.0.1
fi
start () {
echo -n $"Starting $prog: "
# insure that /var/run/memcached has proper permissions
chown $USER /var/run/memcached
daemon $startopts1 memcached -d -l $ADDRESS -p $PORT1 -u $USER -m $MEM -c $MAXCONN -P $pidfile1 $OPTIONS
daemon $startopts2 memcached -d -l $ADDRESS -p $PORT2 -u $USER -m $MEM -c $MAXCONN -P $pidfile2 $OPTIONS
daemon $startopts3 memcached -d -l $ADDRESS -p $PORT3 -u $USER -m $MEM -c $MAXCONN -P $pidfile3 $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached
}
stop () {
echo -n $"Stopping $prog: "
killproc $stopopts1 /usr/bin/memcached
killproc $stopopts2 /usr/bin/memcached
killproc $stopopts3 /usr/bin/memcached
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
rm -f /var/lock/subsys/memcached
rm -f /var/run/memcached1.pid
rm -f /var/run/memcached2.pid
rm -f /var/run/memcached3.pid
fi
}
restart () {
stop
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status memcached
;;
restart|reload|force-reload)
restart
;;
condrestart)
[ -f /var/lock/subsys/memcached ] && restart || :
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
exit 1
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment