summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorGordon Franke <gordon.franke@web.de>2011-08-07 19:18:23 -0700
committerdormando <dormando@rydia.net>2011-08-10 08:44:52 -0700
commit1e52a2543fe02fc48e3396456d487e6a07065453 (patch)
treebe4104f9a398ee19a2805419762207d30125bf2b /scripts
parent8975fd491ad00e91353d5af45f6b3cdd0e722afc (diff)
downloadmemcached-1e52a2543fe02fc48e3396456d487e6a07065453.tar.gz
Allow memcached-init to start multiple instances
Patch by Gordon Franke. Whitespace fixes and comments added by Dormando. There are many better ways to do this, but it doesn't break the default and the "status" command never existed. Servers can be started and stopped individually, and people seem to like the idea.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/memcached-init76
-rwxr-xr-xscripts/start-memcached6
2 files changed, 64 insertions, 18 deletions
diff --git a/scripts/memcached-init b/scripts/memcached-init
index 1ee7118..ebe2ab0 100755
--- a/scripts/memcached-init
+++ b/scripts/memcached-init
@@ -1,41 +1,82 @@
-#! /bin/sh
-#
-# skeleton example file to build /etc/init.d/ scripts.
-# This file should be used to construct scripts for /etc/init.d.
-#
-# Written by Miquel van Smoorenburg <miquels@cistron.nl>.
-# Modified for Debian
-# by Ian Murdock <imurdock@gnu.ai.mit.edu>.
-#
-# Version: @(#)skeleton 1.9 26-Feb-2001 miquels@cistron.nl
-#
+#! /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: Start memcached daemon at boot time
-# Description: Enable memcached server
+# Short-Description: memcached - Memory caching daemon
+# Description: memcached - Memory caching daemon
### END INIT INFO
+# Usage:
+# cp /etc/memcached.conf /etc/memcached_server1.conf
+# cp /etc/memcached.conf /etc/memcached_server2.conf
+# start all instances:
+# /etc/init.d/memcached start
+# start one instance:
+# /etc/init.d/memcached start server1
+# stop all instances:
+# /etc/init.d/memcached stop
+# stop one instance:
+# /etc/init.d/memcached stop server1
+# There is no "status" command.
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/memcached
+DAEMONNAME=memcached
DAEMONBOOTSTRAP=/usr/share/memcached/scripts/start-memcached
-NAME=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"
+
case "$1" in
start)
echo -n "Starting $DESC: "
- start-stop-daemon --start --quiet --exec $DAEMONBOOTSTRAP
+ start-stop-daemon --start --quiet --exec "$DAEMONBOOTSTRAP" -- /etc/${NAME}.conf $PIDFILE
echo "$NAME."
;;
stop)
@@ -55,7 +96,7 @@ case "$1" in
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
rm -f $PIDFILE
sleep 1
- start-stop-daemon --start --quiet --exec $DAEMONBOOTSTRAP
+ start-stop-daemon --start --quiet --exec "$DAEMONBOOTSTRAP" -- /etc/${NAME}.conf $PIDFILE
echo "$NAME."
;;
*)
@@ -65,5 +106,6 @@ case "$1" in
exit 1
;;
esac
+done;
exit 0
diff --git a/scripts/start-memcached b/scripts/start-memcached
index 145a25a..e33b95c 100755
--- a/scripts/start-memcached
+++ b/scripts/start-memcached
@@ -23,6 +23,11 @@ my $params; my $etchandle; my $etcfile = "/etc/memcached.conf";
my $memcached = "/usr/bin/memcached";
my $pidfile = "/var/run/memcached.pid";
+if (scalar(@ARGV) == 2) {
+ $etcfile = shift(@ARGV);
+ $pidfile = shift(@ARGV);
+}
+
# If we don't get a valid logfile parameter in the /etc/memcached.conf file,
# we'll just throw away all of our in-daemon output. We need to re-tie it so
# that non-bash shells will not hang on logout. Thanks to Michael Renner for
@@ -114,4 +119,3 @@ if($pid == 0)
print STDERR "Can't write pidfile to $pidfile.\n";
}
}
-