Skip to content

Instantly share code, notes, and snippets.

@rakotomandimby
Created February 5, 2014 13:05
Show Gist options
  • Save rakotomandimby/8823198 to your computer and use it in GitHub Desktop.
Save rakotomandimby/8823198 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
# pidfile: /var/run/memcached/memcached.pid
# Standard LSB functions
#. /lib/lsb/init-functions
# Source function library.
. /etc/init.d/functions
PORT_01=11211
PORT_02=11212
USER=memcached
MAXCONN=1024
CACHESIZE_01=64
CACHESIZE_02=128
OPTIONS=""
RETVAL=0
prog="memcached"
pidfile_01=${PIDFILE_01-/var/run/memcached/memcached_01.pid}
lockfile_01=${LOCKFILE_01-/var/lock/subsys/memcached_01}
pidfile_02=${PIDFILE_02-/var/run/memcached/memcached_02.pid}
lockfile_02=${LOCKFILE_02-/var/lock/subsys/memcached_02}
start () {
echo -n $"Starting $prog: "
# Ensure that /var/run/memcached has proper permissions
if [ "`stat -c %U /var/run/memcached`" != "$USER" ]; then
chown $USER /var/run/memcached
fi
daemon --pidfile ${pidfile_01} memcached -d -p $PORT_01 -u $USER -m $CACHESIZE_01 -c $MAXCONN -P ${pidfile_01} $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch ${lockfile_01}
daemon --pidfile ${pidfile_02} memcached -d -p $PORT_02 -u $USER -m $CACHESIZE_02 -c $MAXCONN -P ${pidfile_02} $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch ${lockfile_02}
}
stop () {
echo -n $"Stopping $prog: "
killproc -p ${pidfile_01} /usr/bin/memcached
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
rm -f ${lockfile_01} ${pidfile_01}
fi
killproc -p ${pidfile_02} /usr/bin/memcached
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
rm -f ${lockfile_02} ${pidfile_02}
fi
}
restart () {
stop
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile_01} memcached
status -p ${pidfile_02} memcached
RETVAL=$?
;;
restart|reload|force-reload)
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|force-reload}"
RETVAL=2
;;
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment