Skip to content

Commit

Permalink
Use pifpaf to setup daemons
Browse files Browse the repository at this point in the history
Depends-On: Id3e6b694bb186724517599cd9875ad80ceeee053
Change-Id: I2265b4b83f136f2eeb21e86cda1c7ec36401d0a8
  • Loading branch information
jd committed Jun 9, 2016
1 parent 6daa485 commit 4906e72
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 385 deletions.
125 changes: 22 additions & 103 deletions setup-consul-env.sh
Original file line number Diff line number Diff line change
@@ -1,108 +1,27 @@
#!/bin/bash

set -x
set -e

CONSUL_DOWN_DIR=`mktemp -d`
CONSUL_BIN_DIR=`mktemp -d`
CONSUL_TMP_DATA_DIR=`mktemp -d`
CONSUL_VERSION="0.6.3"
CONSUL_RELEASE_URL="https://releases.hashicorp.com/consul"

if [ ! -d "$CONSUL_DOWN_DIR" ]; then
mkdir -p $CONSUL_DOWN_DIR
fi
if [ ! -d "$CONSUL_BIN_DIR" ]; then
mkdir -p $CONSUL_BIN_DIR
fi
if [ ! -d "$CONSUL_TMP_DATA_DIR" ]; then
mkdir -p $CONSUL_TMP_DATA_DIR
fi

function clean_exit(){
local error_code="$?"
local spawned=$(jobs -p)
if [ -n "$spawned" ]; then
kill $spawned
fi
rm -rf $CONSUL_TMP_DATA_DIR
rm -rf $CONSUL_BIN_DIR
rm -rf $CONSUL_DOWN_DIR
return $error_code
}

function get_leader(){
local leader=""
leader=$(curl -s http://127.0.0.1:8500/v1/status/leader)
if [ $? -ne 0 ]; then
return 1
else
echo $leader | python -c "import sys;\
import json;\
print(json.loads(sys.stdin.read()))"
return 0
fi
}

function wait_until_up(){
local leader=`get_leader`
while [ -z "$leader" ]; do
echo "Waiting for consul to respond to a leader http request"
sleep 1
leader=`get_leader`
done
}

function download_and_expand_consul() {
if [ "$(uname)" == "Darwin" ]; then
local consul_file="consul_${CONSUL_VERSION}_darwin_amd64.zip"
elif [ "$(uname -a | cut -d" " -f1)" == "Linux" ]; then
local consul_file="consul_${CONSUL_VERSION}_linux_amd64.zip"
else
echo "Unknown operating system '$(uname -a)'"
exit 1
fi
wget $CONSUL_RELEASE_URL/$CONSUL_VERSION/$consul_file \
--directory-prefix $CONSUL_DOWN_DIR
if [ $? -ne 0 ]; then
echo "Unable to download consul"
exit 1
fi
unzip $CONSUL_DOWN_DIR/$consul_file -d $CONSUL_BIN_DIR
}

function get_consul_version() {
local consul_bin="$1"
local consul_version=`$consul_bin --version | \
head -n1 | cut -d" " -f2 | \
cut -d"v" -f2`
echo $consul_version
}

trap "clean_exit" EXIT

CONSUL_BIN=`which consul || true`
if [ -z "$CONSUL_BIN" ]; then
echo "Downloading consul $CONSUL_VERSION"
download_and_expand_consul
CONSUL_BIN=$CONSUL_BIN_DIR/consul
if [ ! -e "$CONSUL_BIN" ]; then
echo "Consul executable does not exist (even after downloading it)"
exit 1
fi
else
CONSUL_VERSION=`get_consul_version "$CONSUL_BIN"`
echo "Consul $CONSUL_VERSION is already installed"
set -eux

if [ -z "$(which consul)" ]; then
CONSUL_VERSION=0.6.3
CONSUL_RELEASE_URL=https://releases.hashicorp.com/consul
case `uname -s` in
Darwin)
consul_file="consul_${CONSUL_VERSION}_darwin_amd64.zip"
;;
Linux)
consul_file="consul_${CONSUL_VERSION}_linux_amd64.zip"
;;
*)
echo "Unknown operating system"
exit 1
;;
esac
consul_dir=`basename $consul_file .zip`
mkdir -p $consul_dir
curl -L $CONSUL_RELEASE_URL/$CONSUL_VERSION/$consul_file > $consul_dir/$consul_file
unzip $consul_dir/$consul_file -d $consul_dir
export PATH=$PATH:$consul_dir
fi

$CONSUL_BIN agent -server -bootstrap-expect 1 -data-dir $CONSUL_TMP_DATA_DIR -node=agent-one -bind=127.0.0.1 &

# Give some time for the agent to elect a leader, and startup...
# TODO(harlowja): there has to be a better way to do this, there doesn't
# seem
wait_until_up

export TOOZ_TEST_CONSUL_URL="consul://localhost:8500/v1"

# Yield execution to venv command
$*
16 changes: 2 additions & 14 deletions setup-etcd-env.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
#!/bin/bash
set -eux

clean_exit() {
local error_code="$?"
kill $(jobs -p)
return $error_code
}

trap clean_exit EXIT
if [ -n "$(which etcd)" ]; then
etcd &
else
if [ -z "$(which etcd)" ]; then
ETCD_VERSION=2.2.2
case `uname -s` in
Darwin)
Expand All @@ -35,9 +25,7 @@ else
esac
TARBALL_NAME=etcd-v${ETCD_VERSION}-$OS-$MACHINE
test ! -d "$TARBALL_NAME" && curl -L https://github.com/coreos/etcd/releases/download/v${ETCD_VERSION}/${TARBALL_NAME}.${SUFFIX} | tar xz
$TARBALL_NAME/etcd &
export PATH=$PATH:$TARBALL_NAME
fi

export TOOZ_TEST_ETCD_URL="etcd://localhost:4001"
# Yield execution to venv command
$*
22 changes: 0 additions & 22 deletions setup-memcached-env.sh

This file was deleted.

49 changes: 0 additions & 49 deletions setup-mysql-env.sh

This file was deleted.

23 changes: 0 additions & 23 deletions setup-postgresql-env.sh

This file was deleted.

22 changes: 0 additions & 22 deletions setup-redis-env.sh

This file was deleted.

56 changes: 0 additions & 56 deletions setup-sentinel-env.sh

This file was deleted.

55 changes: 0 additions & 55 deletions setup-zookeeper-env.sh

This file was deleted.

Loading

0 comments on commit 4906e72

Please sign in to comment.