Memcached – Multiple Server /etc/init.d Startup Script for CentOS

centosmemcachememcached

I install memcached server via source and can get standard start up script installed for 1 memcached server instance, but trying several scripts via google, can't find one that works to manager auto start up on boot for multiple memcached server instances. I've tried both these scripts and both don't work, service memcached start just returns to command prompt with no memcached server instances started

  • lullabot.com/articles/installing-memcached-redhat-or-centos
  • addmoremem.blogspot.com/2010/09/running-multiple-instances-of-memcached.html

However this bash script works but doesn't start up memcached instances at start up though ?

#!/bin/sh
case "$1" in
start)
/usr/local/bin/memcached -d -m 16 -p 11211 -u nobody
/usr/local/bin/memcached -d -m 16 -p 11212 -u nobody
;;
stop) killall memcached
;;
esac

OS: Centos 5.5 64bit
Memcached = v1.4.5
Memcache = v2.2.5

Anyone can point me to a working /etc/init.d/ startup script to manage multiple memcached servers ? Thanks

edit: Thanks mat, this is code that ended up working

#!/bin/sh
# chkconfig: - 80 12
# description:  The memcached daemon is a network memory cache service.
# processname: memcached
BIN=/usr/local/bin/memcached
USER=nobody
CON=2048
THREADS=4

$BIN -d -m 16 -p 11211 -c $CON -t $THREADS -u $USER
$BIN -d -m 16 -p 11212 -c $CON -t $THREADS -u $USER

case "$1" in
start)
$BIN -d -m 16 -p 11211 -c $CON -t $THREADS -u $USER
$BIN -d -m 16 -p 11212 -c $CON -t $THREADS -u $USER
;;
stop) killall $BIN
;;
esac

Best Answer

To add a service to chkconfig you will normally need a couple of special comments below the shebang of a shell script:

#!/bin/sh
# chkconfig: - 55 45
# description:  The memcached daemon is a network memory cache service.
# processname: memcached

After adding the lines to /etc/init.d/memcached you can then issue

chkconfig --add memcached

There are of course additional run levels a process can start at so to check that you would issue

chkconfig --list | grep "memcached"

A common run level for memcached would be

chkconfig --level 345 memcached on
Related Topic