Replacement Init Script for memcached on Debian or Ubuntu
This script is a modification of the one for CentOS 5. It starts several instances of memcached listing on a set of sequential ports; the memcached instances started here, and their ports, must be matched in the configuration in settings.php in Drupal / Pressflow.
/etc/init.d/memcached
#! /bin/sh
#
PORT=11211
USER=nobody
MAXCONN=1024
OPTIONS=""
DAEMON=/usr/bin/memcached
RETVAL=0
prog="memcached"
start_instance() {
echo -n $"Starting $prog ($1): "
start-stop-daemon --start --quiet --pidfile /var/run/memcached/memcached.$1
.pid --exec $DAEMON -- -d -p $PORT -u $USER -m $2 -c $MAXCONN -P /var/run/memcache
d/memcached.$1.pid $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/memcached.$1
PORT=`expr $PORT + 1`
}
stop_instance() {
echo -n $"Stopping $prog ($1): "
start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/memcached/memc
ached.$1.pid --exec $DAEMON
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
rm -f /var/lock/memcached.$1
rm -f /var/run/memcached/memcached.$1.pid
fi
}
start () {
# insure that /var/run/memcached has proper permissions
mkdir -p /var/run/memcached
if [ "`stat -c %U /var/run/memcached`" != "$USER" ]; then
chown $USER /var/run/memcached
fi
start_instance default 64;
start_instance block 16;
start_instance content 128;
start_instance filter 128;
start_instance form 32;
start_instance menu 16;
start_instance page 8;
start_instance update 8;
start_instance views 8;
}
stop () {
stop_instance default;
stop_instance block;
stop_instance content;
stop_instance filter;
stop_instance form;
stop_instance menu;
stop_instance page;
stop_instance update;
stop_instance views;
}
restart () {
stop
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status memcached
;;
restart|reload|force-reload)
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|force-reload}"
exit 1
esac
exit $?
Is this behaviour correct? After stopping the doemons, they're still "LISTENING" or "CONNECTED" on ports 11211 to 11219:
/etc/init.d/memcached stop
Stopping memcached (default):
Stopping memcached (block):
Stopping memcached (content):
Stopping memcached (filter):
Stopping memcached (form):
Stopping memcached (menu):
Stopping memcached (page):
Stopping memcached (update):
Stopping memcached (views):
netstat -n -p -t -a | grep memcached
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 25549/memcached
tcp 0 0 0.0.0.0:11212 0.0.0.0:* LISTEN 25553/memcached
tcp 0 0 0.0.0.0:11213 0.0.0.0:* LISTEN 25557/memcached
tcp 0 0 0.0.0.0:11214 0.0.0.0:* LISTEN 25561/memcached
tcp 0 0 0.0.0.0:11215 0.0.0.0:* LISTEN 25565/memcached
tcp 0 0 0.0.0.0:11216 0.0.0.0:* LISTEN 25569/memcached
tcp 0 0 0.0.0.0:11217 0.0.0.0:* LISTEN 25573/memcached
tcp 0 0 0.0.0.0:11218 0.0.0.0:* LISTEN 25577/memcached
tcp 0 0 0.0.0.0:11219 0.0.0.0:* LISTEN 25581/memcached
tcp 0 0 127.0.0.1:11211 127.0.0.1:44136 CONNECTED 25549/memcached
tcp 0 0 127.0.0.1:11211 127.0.0.1:44134 CONNECTED 25549/memcached
tcp 0 0 127.0.0.1:11211 127.0.0.1:44126 CONNECTED 25549/memcached
tcp 0 0 127.0.0.1:11211 127.0.0.1:44145 CONNECTED 25549/memcached
(Debian GNU/Linux "Lenny")
Regards, -asb