From e8e60cae3b715ea3243357d8a421a5c7fa68c3f5 Mon Sep 17 00:00:00 2001 From: Vasily Ostanin Date: Sat, 31 Dec 2016 14:06:01 +0500 Subject: [PATCH] - upgrade to consul 0.7.2 - upgrade to Ubuntu 16.04 - remove consul-template - remove collectd --- Dockerfile | 28 ++++-------- README.md | 4 -- config/collectd/collectd.conf | 75 --------------------------------- init.d/01_consul.sh | 23 ---------- init.d/{00_env.sh => 10_env.sh} | 2 - init.d/999_consul.sh | 48 +++++++++++++++++++++ services/collectd.sh | 8 ---- 7 files changed, 57 insertions(+), 131 deletions(-) delete mode 100644 config/collectd/collectd.conf delete mode 100755 init.d/01_consul.sh rename init.d/{00_env.sh => 10_env.sh} (60%) create mode 100755 init.d/999_consul.sh delete mode 100755 services/collectd.sh diff --git a/Dockerfile b/Dockerfile index 33fcf20..4947ab8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,40 +4,30 @@ MAINTAINER Alex Salt RUN apt-get update -qq && apt-get install -y --no-install-recommends \ ca-certificates bind9-host \ htop apt-transport-https unzip nano \ - collectd + collectd dnsutils iproute # do locales RUN locale-gen ru_RU.UTF-8 COPY config/locale /etc/default/locale # envplate -RUN curl -L https://github.com/kreuzwerker/envplate/releases/download/v0.0.8/ep-linux -o /usr/local/bin/ep && chmod +x /usr/local/bin/ep +RUN curl -Ls https://github.com/kreuzwerker/envplate/releases/download/v0.0.8/ep-linux -o /usr/local/bin/ep && \ + chmod +x /usr/local/bin/ep # consul -RUN curl https://releases.hashicorp.com/consul/0.6.3/consul_0.6.3_linux_amd64.zip > /tmp/consul.zip -RUN unzip /tmp/consul.zip -RUN mv consul /usr/local/bin/ -RUN mkdir -p /etc/consul/conf.d -ADD config/consul.json /etc/consul/consul.json - -# consul template -RUN curl -L -s https://github.com/hashicorp/consul-template/releases/download/v0.10.0/consul-template_0.10.0_linux_amd64.tar.gz | \ - tar -C /usr/local/bin --strip-components 1 -zxf - - -# Setup Consul Template Files -RUN mkdir /etc/consul-templates +RUN curl -Ls https://releases.hashicorp.com/consul/0.7.2/consul_0.7.2_linux_amd64.zip -o /tmp/consul.zip && \ + unzip /tmp/consul.zip -d /usr/local/bin/ && rm /tmp/consul.zip && \ + mkdir -p /etc/consul/conf.d -# collectd -RUN mkdir /etc/collectd/conf.d -RUN touch /etc/collectd/types.db -ADD config/collectd/collectd.conf /etc/collectd/ +ADD config/consul.json /etc/consul/consul.json # install init scripts ADD init.d/ /etc/my_init.d/ # install services ADD services/consul.sh /etc/service/consul/run -ADD services/collectd.sh /etc/service/collectd/run + +EXPOSE 8300 8301 8301/udp 8302 8302/udp 8400 8500 8600 8600/udp # Clean up APT when done. RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* diff --git a/README.md b/README.md index 3105362..10529b3 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,3 @@ CONSUL ------ Consul host resolved either from `CONSUL_HOST` env var or default gateway Put your .json configuration files to `/etc/consul/conf.d/` - -COLLECTD --------- -Put your collectd config to /etc/collectd/collectd.conf.d/ diff --git a/config/collectd/collectd.conf b/config/collectd/collectd.conf deleted file mode 100644 index beebd37..0000000 --- a/config/collectd/collectd.conf +++ /dev/null @@ -1,75 +0,0 @@ -# Config file for collectd(1). -# -# Some plugins need additional configuration and are disabled by default. -# Please read collectd.conf(5) for details. -# -# You should also read /usr/share/doc/collectd-core/README.Debian.plugins -# before enabling any more plugins. - -# Hostname "redismaster" -FQDNLookup true -#BaseDir "/var/lib/collectd" -#PluginDir "/usr/lib/collectd" -TypesDB "/usr/share/collectd/types.db" "/etc/collectd/types.db" -Interval 5 -#Timeout 2 -#ReadThreads 5 - -LoadPlugin logfile -LoadPlugin syslog - - - LogLevel "info" - File "/var/log/collectd.log" - Timestamp true - PrintSeverity false - - - - LogLevel info - - -#LoadPlugin cpu -#LoadPlugin df -#LoadPlugin disk -#LoadPlugin ethstat -LoadPlugin exec -LoadPlugin interface -#LoadPlugin irq -LoadPlugin load -LoadPlugin memory -#LoadPlugin numa -#LoadPlugin processes -LoadPlugin swap -#LoadPlugin users -LoadPlugin write_graphite -LoadPlugin tail - - - - - Host "${MONITORING_HOST}" - Port "2003" - StoreRates true - EscapeCharacter "_" - - - - - Globals true - - -LoadPlugin "network" - - Listen "127.0.0.1" "25826" - - -LoadPlugin "statsd" - - Host "127.0.0.1" - Port "8125" - DeleteSets true - TimerPercentile 90.0 - - -Include "/etc/collectd/collectd.conf.d/*.conf" diff --git a/init.d/01_consul.sh b/init.d/01_consul.sh deleted file mode 100755 index 79c964f..0000000 --- a/init.d/01_consul.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh - -if [ -z $CONSUL_HOST ]; then - echo "CONSUL_HOST not set, discovering from route" - CONSUL_HOST=$(ip route show 0.0.0.0/0 | grep -Eo 'via \S+' | awk '{ print $2 }') - if [ $CONSUL_HOST = "" ]; then - echo "CONSUL_HOST discovery from ip route failed. Quitting.." - exit 1 - fi - echo $CONSUL_HOST > /etc/container_environment/CONSUL_HOST -fi - -echo "Consul host is: $CONSUL_HOST" -PAIR=$(curl -s http://$CONSUL_HOST:8500/v1/agent/self | python3 -c 'import json,sys;obj=json.load(sys.stdin);print ("%s %s" % (obj["Config"]["Datacenter"], obj["Config"]["Domain"]))' 2> /dev/null) -if [ "$PAIR" = "" ]; then - echo "Consul DC and domain discovery failed. Quitting.." - exit 1 -fi - -DC=$(echo $PAIR | cut -f1 -d " ") -DOMAIN=$(echo $PAIR | cut -f2 -d " ") -echo $DC > /etc/container_environment/CONSUL_DC -echo $DOMAIN > /etc/container_environment/CONSUL_DOMAIN diff --git a/init.d/00_env.sh b/init.d/10_env.sh similarity index 60% rename from init.d/00_env.sh rename to init.d/10_env.sh index 7e6cb5d..b725807 100755 --- a/init.d/00_env.sh +++ b/init.d/10_env.sh @@ -2,5 +2,3 @@ ep /etc/collectd/collectd.conf ep /etc/collectd/collectd.conf.d/* -ep /etc/consul/conf.d/* -ep /etc/consul/consul.json diff --git a/init.d/999_consul.sh b/init.d/999_consul.sh new file mode 100755 index 0000000..11de295 --- /dev/null +++ b/init.d/999_consul.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +if [ -z $CONSUL_HOST ]; then + echo "CONSUL_HOST not set, discovering from route" + CONSUL_HOST=$(ip route show 0.0.0.0/0 | grep -Eo 'via \S+' | awk '{ print $2 }') + if [ $CONSUL_HOST = "" ]; then + echo "CONSUL_HOST discovery from ip route failed. Quitting.." + exit 1 + fi + echo $CONSUL_HOST > /etc/container_environment/CONSUL_HOST +fi + +echo "Consul host is: $CONSUL_HOST" +PAIR=$(curl -s http://$CONSUL_HOST:8500/v1/agent/self | jq '.Config| .Datacenter + " " + .Domain') +if [ "$PAIR" = "" ]; then + echo "Consul DC and domain discovery failed. Quitting.." + exit 1 +fi + +CONSUL_DC=$(echo $PAIR | cut -f1 -d " ") +CONSUL_DOMAIN=$(echo $PAIR | cut -f2 -d " ") +echo $CONSUL_DC > /etc/container_environment/CONSUL_DC +echo $CONSUL_DOMAIN > /etc/container_environment/CONSUL_DOMAIN + +NETS=$(ip a | grep "scope global") +NETS_COUNT=$(ip a | grep "scope global" | wc -l) +if [ -z $ADVERTISE ] && [ $NETS_COUNT -gt 1 ]; then + if [ ! -z $ADVERTISE_INTERFACE ]; then + ADDR=$(ip addr show dev ethwe | grep "inet " | grep -E -o '[0-9a-f]+[\.:][0-9a-f\.:]+[^/]') + if [ $ADDR ]; then + ADVERTISE=$ADDR + fi + fi + if [ -z $ADVERTISE ]; then + echo "No ADVERTISE or ADVERTISE_INTERFACE adress set, and more than 2 global scope networks available, trying to detect." + ADVERTISE=127.0.0.1 + + CONSUL_IP=$(getent hosts $CONSUL_HOST | awk '{print $1}') + ADVERTISE=$(ip -o route get $CONSUL_IP | grep -oE 'src ([^\s]*)' | awk '{print $2}') + + echo "Using default route to consul interface: $ADVERTISE" + fi + + echo "{\"advertise_addr\": \"$ADVERTISE\"}" > /etc/consul/conf.d/advertise.json +fi + +ep /etc/consul/conf.d/* +ep /etc/consul/consul.json diff --git a/services/collectd.sh b/services/collectd.sh deleted file mode 100755 index 059fdc8..0000000 --- a/services/collectd.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -if [ "$START_COLLECTD" != "1" ]; then - sv down collectd - exit 0 -fi - -exec collectd -f -C /etc/collectd/collectd.conf