Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to run multiple instances of memcached. #54

Merged
merged 1 commit into from
May 25, 2015

Conversation

dansajner
Copy link

Hi. I have the same needs as discussed in #18 so here's a PR to cover it.

I run rhel/centos servers so that is the only platform that I functionally tested. I took a look at the startup scripts in the Debian package and it looks like this implementation should work, but its worth someone testing. The difference as far as I can tell is that Debian will only have 1 service definition which manages all of the memcached instances whereas the other OS's have a service def for each instance.

For this implementation I removed the ability to specify the logfile, pidfile, and user. It was necessary for the changes here and I don't feel like this will cause people major issues. If you disagree perhaps we can come up with a middle ground solution.

@@ -0,0 +1,91 @@
#! /bin/sh

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello !

The default Debian 7 Memcached init script already handle multiple instances :

#! /bin/bash
### BEGIN INIT INFO
# Provides:            memcached
# Required-Start:      $remote_fs $syslog
# Required-Stop:       $remote_fs $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
# Description:         Start up memcached, a high-performance 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
DESC=memcached

test -x $DAEMON || exit 0
test -x $DAEMONBOOTSTRAP || exit 0

set -e

. /lib/lsb/init-functions

# Edit /etc/default/memcached to change this.
ENABLE_MEMCACHED=no
test -r /etc/default/memcached && . /etc/default/memcached


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: "
       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 --retry 5 --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 --retry 5 --pidfile $PIDFILE
       rm -f $PIDFILE
       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
       ;;
  status)
       status_of_proc -p $PIDFILE $DAEMON $NAME  && exit 0 || exit $?
       ;;
  *)
    N=/etc/init.d/$NAME
    echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
    exit 1
    ;;
esac
done;

exit 0

@bdossantos
Copy link

👍

@dansajner
Copy link
Author

Any thoughts on this PR?

@dansajner
Copy link
Author

Hi. Can I get a status on this PR?

@saz
Copy link
Owner

saz commented Mar 28, 2015

Looks good to me. Please rebase your pull request and I'll be happy to merge it.

@dansajner
Copy link
Author

Rebase complete @saz

@dansajner
Copy link
Author

@saz any updates?

@dansajner
Copy link
Author

@saz what is going on with this PR? Please see your comment from March 28. If there is an issue with this change set please let me know, otherwise please merge this already!

saz added a commit that referenced this pull request May 25, 2015
Updates to run multiple instances of memcached.
@saz saz merged commit b8375f9 into saz:master May 25, 2015
saz added a commit that referenced this pull request May 25, 2015
This reverts commit b8375f9, reversing
changes made to e0e9c02.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants