Created
July 9, 2013 13:14
-
-
Save mbopp/5957231 to your computer and use it in GitHub Desktop.
Multi Instance Configuration for Memcache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
### BEGIN INIT INFO | |
# Provides: memcached | |
# Required-Start: $syslog | |
# Required-Stop: $syslog | |
# Should-Start: $local_fs | |
# Should-Stop: $local_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: memcached - Memory caching daemon | |
# Description: memcached - Memory caching daemon | |
### END INIT INFO | |
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
DAEMON=/usr/bin/memcached | |
DAEMONBOOTSTRAP=/usr/share/memcached/scripts/start-memcached | |
DAEMONNAME=memcached | |
DESC=memcached | |
# PIDFILE=/var/run/$NAME.pid | |
test -x $DAEMON || exit 0 | |
test -x $DAEMONBOOTSTRAP || exit 0 | |
set -e | |
FILES=(/etc/memcached_*.conf); | |
# check for alternative config schema | |
if [ -r "${FILES[0]}" ]; then | |
CONFIGS=(); | |
for FILE in "${FILES[@]}"; | |
do | |
# remove prefix | |
NAME=${FILE#/etc/}; | |
# remove suffix | |
NAME=${NAME%.conf}; | |
# check optional second param | |
if [ $# -ne 2 ]; | |
then | |
# add to config array | |
CONFIGS+=($NAME); | |
elif [ "memcached_$2" == "$NAME" ]; | |
then | |
# use only one memcached | |
CONFIGS=($NAME); | |
break; | |
fi; | |
done; | |
if [ ${#CONFIGS[@]} == 0 ]; | |
then | |
echo "Config not exist for: $2" >&2; | |
exit 1; | |
fi; | |
else | |
CONFIGS=(memcached); | |
fi; | |
CONFIG_NUM=${#CONFIGS[@]}; | |
for ((i=0; i < $CONFIG_NUM; i++)); do | |
NAME=${CONFIGS[${i}]}; | |
PIDFILE="/var/run/${NAME}.pid"; | |
. /lib/lsb/init-functions | |
# Edit /etc/default/memcached to change this. | |
ENABLE_MEMCACHED=no | |
test -r /etc/default/memcached && . /etc/default/memcached | |
case "$1" in | |
start) | |
echo -n "Starting $DESC: " | |
if [ $ENABLE_MEMCACHED = yes ]; then | |
start-stop-daemon --start --quiet --exec "$DAEMONBOOTSTRAP" -- /etc/${NAME}.conf $PIDFILE | |
echo "$NAME." | |
else | |
echo "$NAME disabled in /etc/default/memcached." | |
fi | |
;; | |
stop) | |
echo -n "Stopping $DESC: " | |
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON | |
echo "$NAME." | |
rm -f $PIDFILE | |
;; | |
restart|force-reload) | |
# | |
# If the "reload" option is implemented, move the "force-reload" | |
# option to the "reload" entry above. If not, "force-reload" is | |
# just the same as "restart". | |
# | |
echo -n "Restarting $DESC: " | |
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE | |
rm -f $PIDFILE | |
sleep 1 | |
start-stop-daemon --start --quiet --exec "$DAEMONBOOTSTRAP" -- /etc/${NAME}.conf $PIDFILE | |
echo "$NAME." | |
;; | |
status) | |
status_of_proc $DAEMON $NAME | |
;; | |
*) | |
N=/etc/init.d/$DAEMONNAME | |
echo "Usage: $N {start|stop|restart|force-reload|status}" >&2 | |
exit 1 | |
;; | |
esac | |
done; | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# memcached default config file | |
# 2003 - Jay Bonci <[email protected]> | |
# This configuration file is read by the start-memcached script provided as | |
# part of the Debian GNU/Linux distribution. | |
# Run memcached as a daemon. This command is implied, and is not needed for the | |
# daemon to run. See the README.Debian that comes with this package for more | |
# information. | |
-d | |
# Log memcached's output to /var/log/memcached | |
logfile /var/log/memcached.log | |
# Be verbose | |
# -v | |
# Be even more verbose (print client commands as well) | |
# -vv | |
# Start with a cap of 64 megs of memory. It's reasonable, and the daemon default | |
# Note that the daemon will grow to this size, but does not start out holding this much | |
# memory | |
-m 64 | |
# Default connection port is 11211 | |
# -p 11211 | |
# Run the daemon as root. The start-memcached will default to running as root if no | |
# -u command is present in this config file | |
-u nobody | |
# Specify which IP address to listen on. The default is to listen on all IP addresses | |
# This parameter is one of the only security measures that memcached has, so make sure | |
# it's listening on a firewalled interface. | |
# -l 127.0.0.1 | |
# Limit the number of simultaneous incoming connections. The daemon default is 1024 | |
# -c 1024 | |
# Lock down all paged memory. Consult with the README and homepage before you do this | |
# -k | |
# Return error when memory is exhausted (rather than removing items) | |
# -M | |
# Maximize core file limit | |
# -r | |
-s /var/run/memcached/memcached.sock | |
# The name of the socket isn't important as long as you remember it for later. | |
# I just stick to the config file convention, replacing .conf with .sock as I then always | |
# know which socket belongs to which instance. | |
# Finally add the -a switch to specify the octal file mode of the socket when it is created: | |
-a 0766 | |
-f 1.07 | |
-n 512 | |
-L |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment