Created
August 9, 2016 10:34
-
-
Save double-z/5e29c0a3c4f628f11ff6416406c6852c to your computer and use it in GitHub Desktop.
Plan to configure Consul with habitat.
This file contains hidden or 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/sh | |
# | |
# Consul Health Check for Habitat | |
echo "health_check..." | |
echo "" | |
# The health_check script must return a valid exit code from the list below. | |
# 0 - ok | |
# 1 - warning | |
# 2 - critical | |
# 3 - unknown | |
# default return code is 3 (Unknown) | |
rc=3 | |
ip={{svc.me.ip}} | |
# Use wget because its a part of BusyBox | |
status=$(wget -qO - $ip:8080/v1/status/leader) | |
leader=$(echo $status | awk '{print $4}') | |
case $status in | |
0) | |
rc=1 ;; | |
3) | |
rc=0 ;; | |
4) | |
rc=2 ;; | |
*) | |
rc=3 ;; | |
esac | |
echo $status | |
exit $rc |
This file contains hidden or 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/sh | |
echo "init..." | |
echo "" |
This file contains hidden or 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/sh | |
echo "hooks_reconfigure..." | |
echo "" | |
{{~#each svc.members}} | |
echo "Joining {{hostname}}..." | |
echo "" | |
{{pkg.path}}/bin/consul \ | |
-join {{hostname}} | |
{{~/each}} |
This file contains hidden or 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/sh | |
echo "run..." | |
echo "" | |
IP={{svc.me.ip}} | |
HOST={{svc.me.hostname}} | |
DATA_DIR={{pkg.svc_data_path}} | |
echo "Starting consul on ${IP}..." | |
echo "" | |
{{pkg.path}}/bin/consul \ | |
-data-dir ${DATA_DIR} \ | |
-bootstrap-expect 3 \ | |
-advertise ${IP} \ | |
-client ${IP} \ | |
-node ${HOST} \ | |
-server \ | |
2>&1 |
This file contains hidden or 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
pkg_name=consul | |
pkg_origin=hashicorp | |
pkg_version=0.6.4 | |
pkg_description="Consul is a tool for service discovery, monitoring and configuration." | |
pkg_upstream_url=https://www.consul.io/ | |
pkg_license=('mpl2') | |
pkg_maintainer="Jason Riddle <[email protected]>" | |
pkg_source=https://releases.hashicorp.com/${pkg_name}/${pkg_version}/${pkg_name}_${pkg_version}_linux_amd64.zip | |
pkg_shasum=abdf0e1856292468e2c9971420d73b805e93888e006c76324ae39416edcf0627 | |
pkg_bin_dirs=(bin) | |
pkg_expose=(8300 8301 8301/udp 8302 8302/udp 8400 8500 8600 8600/udp) | |
pkg_svc_run="bin/consul agent -dev" | |
# pkg_svc_run="bin/consul agent -config-dir $pkg_svc_config_path/ -data-dir /tmp" | |
# pkg_svc_user="hab" | |
do_build() { | |
return 0 | |
} | |
do_install() { | |
mkdir -p $pkg_prefix/bin | |
cp $HAB_CACHE_SRC_PATH/consul $pkg_prefix/bin | |
} |
This file contains hidden or 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
pkg_name=consul | |
pkg_origin=hashicorp | |
pkg_version=0.6.4 | |
pkg_description="Consul is a tool for service discovery, monitoring and configuration." | |
pkg_upstream_url=https://www.consul.io/ | |
pkg_license=('mpl2') | |
pkg_maintainer="Jason Riddle <[email protected]>" | |
pkg_source=https://github.com/${pkg_origin}/${pkg_name}/archive/v${pkg_version}.tar.gz | |
pkg_shasum=327c72211af1d6613477856c15bf7bcfc3c80d23542fcffe535d30d09347e08b | |
pkg_interpreters=(bin/bash) | |
pkg_deps=(core/coreutils core/go/1.6.3/20160728163358) | |
pkg_build_deps=(core/git core/make) | |
pkg_bin_dirs=(bin) | |
pkg_expose=(8300 8301 8301/udp 8302 8302/udp 8400 8500 8600 8600/udp) | |
do_prepare() { | |
export GOPATH=${pkg_prefix} | |
git init | |
fix_interpreter "scripts/*.sh" core/coreutils bin/env | |
} | |
do_build() { | |
make | |
} | |
do_strip() { | |
return 0 | |
} | |
do_install() { | |
cp bin/consul $pkg_prefix/bin | |
} |
This file contains hidden or 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
# Install habitat | |
brew install Caskroom/cask/hab --force | |
# Setup, use 'myorigin' for origin | |
hab setup | |
# Enter the docker-linux machine, must have docker running | |
hab studio enter | |
# Edit your plan.sh | |
$EDITOR plan.sh | |
# Build your plan.sh | |
build | |
# Create hab user and group | |
# sudo useradd hab -u 42 -g 42 -d / -s /bin/sh -r | |
# sudo groupadd -og 42 hab | |
# Start your habitat binary | |
hab start puu562/consul --topology initializer --group consul.production | |
hab start puu562/consul --topology initializer --group consul.production --peer 172.17.0.2 | |
# You can also export to a docker image | |
hab pkg export docker puu562/consul | |
# Clean up your docker studio container | |
hab studio rm | |
## TODO | |
hab origin key generate originname |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment