Skip to content
This repository has been archived by the owner on Dec 2, 2018. It is now read-only.

Commit

Permalink
Re-join cluster when starting
Browse files Browse the repository at this point in the history
Preserve the cluster server members on stop and use them to join on
start.

Work-around for hashicorp/consul#110
  • Loading branch information
blalor committed May 3, 2014
1 parent dc54ca8 commit 337e19a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions sources/consul/sysvinit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ lockfile="/var/lock/subsys/$prog"
logfile="/var/log/$prog"
conffile="/etc/consul.conf"
confdir="/etc/consul.d"
membersfile="/var/lib/consul/server_members"

# pull in sysconfig settings
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
Expand Down Expand Up @@ -64,12 +65,42 @@ start() {

[ $RETVAL -eq 0 ] && touch $lockfile

if [ -e $membersfile ]; then
echo -n $"Re-joining cluster: "

## allow time to launch
sleep 5

## I think I want to iterate through every entry in $membersfile and
## return success if any are successfully joined…
cat $membersfile | xargs $exec join &>> /dev/null

RETVAL=$?

if [ $RETVAL -eq 0 ]; then
success

rm -f $membersfile
else
failure
fi

echo
fi

return $RETVAL
}

stop() {
echo -n $"Shutting down $prog: "

## store current server members so we can re-join later. exclude ourselves.
our_ip=$( ip addr show dev eth0 | awk '/inet / { split($2, cidr, "/"); print cidr[1]; }' )
consul members -status=alive -role=consul \
| awk '{ split($2, addr, ":"); print addr[1] }' \
| fgrep -v $our_ip \
> $membersfile

## graceful shutdown with leave
$exec leave &> /dev/null

Expand Down

0 comments on commit 337e19a

Please sign in to comment.