From 2c7ab566e10c138dfbf013bda78aaee4b3af0c95 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 24 Feb 2015 13:10:17 +0100 Subject: [PATCH] add new types to manage consul and friends Signed-off-by: Steven Armstrong --- cdist/conf/type/__consul/man.text | 71 +++++++ cdist/conf/type/__consul/manifest | 65 +++++++ .../__consul/parameter/default/install-from | 1 + .../__consul/parameter/default/install-to | 1 + .../type/__consul/parameter/default/state | 1 + cdist/conf/type/__consul/parameter/optional | 3 + cdist/conf/type/__consul/singleton | 0 .../type/__consul_agent/files/consul.systemd | 17 ++ .../type/__consul_agent/files/consul.sysv | 93 ++++++++++ .../type/__consul_agent/files/consul.upstart | 13 ++ cdist/conf/type/__consul_agent/gencode-remote | 31 ++++ cdist/conf/type/__consul_agent/man.text | 134 ++++++++++++++ cdist/conf/type/__consul_agent/manifest | 175 ++++++++++++++++++ .../type/__consul_agent/parameter/boolean | 8 + .../__consul_agent/parameter/default/group | 1 + .../__consul_agent/parameter/default/state | 1 + .../__consul_agent/parameter/default/user | 1 + .../type/__consul_agent/parameter/optional | 13 ++ .../parameter/optional_multiple | 1 + cdist/conf/type/__consul_agent/singleton | 0 cdist/conf/type/__consul_check/man.text | 68 +++++++ cdist/conf/type/__consul_check/manifest | 64 +++++++ .../__consul_check/parameter/default/state | 1 + .../type/__consul_check/parameter/optional | 7 + .../conf/type/__consul_reload/gencode-remote | 24 +++ cdist/conf/type/__consul_reload/man.text | 42 +++++ cdist/conf/type/__consul_reload/singleton | 0 cdist/conf/type/__consul_service/man.text | 71 +++++++ cdist/conf/type/__consul_service/manifest | 83 +++++++++ .../__consul_service/parameter/default/state | 1 + .../type/__consul_service/parameter/optional | 7 + .../parameter/optional_multiple | 1 + .../files/consul-template.systemd | 19 ++ .../files/consul-template.sysv | 89 +++++++++ .../files/consul-template.upstart | 12 ++ cdist/conf/type/__consul_template/man.text | 72 +++++++ cdist/conf/type/__consul_template/manifest | 121 ++++++++++++ .../type/__consul_template/parameter/boolean | 2 + .../parameter/default/consul | 1 + .../type/__consul_template/parameter/optional | 7 + cdist/conf/type/__consul_template/singleton | 0 .../type/__consul_template_template/man.text | 69 +++++++ .../type/__consul_template_template/manifest | 74 ++++++++ .../parameter/default/state | 1 + .../parameter/optional | 4 + .../parameter/required | 1 + .../conf/type/__consul_watch_checks/man.text | 64 +++++++ .../conf/type/__consul_watch_checks/manifest | 61 ++++++ .../parameter/default/state | 1 + .../__consul_watch_checks/parameter/optional | 5 + .../__consul_watch_checks/parameter/required | 1 + cdist/conf/type/__consul_watch_event/man.text | 58 ++++++ cdist/conf/type/__consul_watch_event/manifest | 51 +++++ .../parameter/default/state | 1 + .../__consul_watch_event/parameter/optional | 4 + .../__consul_watch_event/parameter/required | 1 + cdist/conf/type/__consul_watch_key/man.text | 55 ++++++ cdist/conf/type/__consul_watch_key/manifest | 51 +++++ .../parameter/default/state | 1 + .../__consul_watch_key/parameter/optional | 3 + .../__consul_watch_key/parameter/required | 2 + .../type/__consul_watch_keyprefix/man.text | 55 ++++++ .../type/__consul_watch_keyprefix/manifest | 51 +++++ .../parameter/default/state | 1 + .../parameter/optional | 3 + .../parameter/required | 2 + cdist/conf/type/__consul_watch_nodes/man.text | 52 ++++++ cdist/conf/type/__consul_watch_nodes/manifest | 51 +++++ .../parameter/default/state | 1 + .../__consul_watch_nodes/parameter/optional | 3 + .../__consul_watch_nodes/parameter/required | 1 + .../conf/type/__consul_watch_service/man.text | 74 ++++++++ .../conf/type/__consul_watch_service/manifest | 54 ++++++ .../__consul_watch_service/parameter/boolean | 1 + .../parameter/default/state | 1 + .../__consul_watch_service/parameter/optional | 4 + .../__consul_watch_service/parameter/required | 2 + .../type/__consul_watch_services/man.text | 52 ++++++ .../type/__consul_watch_services/manifest | 51 +++++ .../parameter/default/state | 1 + .../parameter/optional | 3 + .../parameter/required | 1 + docs/changelog | 14 ++ 83 files changed, 2308 insertions(+) create mode 100644 cdist/conf/type/__consul/man.text create mode 100755 cdist/conf/type/__consul/manifest create mode 100644 cdist/conf/type/__consul/parameter/default/install-from create mode 100644 cdist/conf/type/__consul/parameter/default/install-to create mode 100644 cdist/conf/type/__consul/parameter/default/state create mode 100644 cdist/conf/type/__consul/parameter/optional create mode 100644 cdist/conf/type/__consul/singleton create mode 100644 cdist/conf/type/__consul_agent/files/consul.systemd create mode 100644 cdist/conf/type/__consul_agent/files/consul.sysv create mode 100644 cdist/conf/type/__consul_agent/files/consul.upstart create mode 100755 cdist/conf/type/__consul_agent/gencode-remote create mode 100644 cdist/conf/type/__consul_agent/man.text create mode 100755 cdist/conf/type/__consul_agent/manifest create mode 100644 cdist/conf/type/__consul_agent/parameter/boolean create mode 100644 cdist/conf/type/__consul_agent/parameter/default/group create mode 100644 cdist/conf/type/__consul_agent/parameter/default/state create mode 100644 cdist/conf/type/__consul_agent/parameter/default/user create mode 100644 cdist/conf/type/__consul_agent/parameter/optional create mode 100644 cdist/conf/type/__consul_agent/parameter/optional_multiple create mode 100644 cdist/conf/type/__consul_agent/singleton create mode 100644 cdist/conf/type/__consul_check/man.text create mode 100755 cdist/conf/type/__consul_check/manifest create mode 100644 cdist/conf/type/__consul_check/parameter/default/state create mode 100644 cdist/conf/type/__consul_check/parameter/optional create mode 100755 cdist/conf/type/__consul_reload/gencode-remote create mode 100644 cdist/conf/type/__consul_reload/man.text create mode 100644 cdist/conf/type/__consul_reload/singleton create mode 100644 cdist/conf/type/__consul_service/man.text create mode 100755 cdist/conf/type/__consul_service/manifest create mode 100644 cdist/conf/type/__consul_service/parameter/default/state create mode 100644 cdist/conf/type/__consul_service/parameter/optional create mode 100644 cdist/conf/type/__consul_service/parameter/optional_multiple create mode 100644 cdist/conf/type/__consul_template/files/consul-template.systemd create mode 100644 cdist/conf/type/__consul_template/files/consul-template.sysv create mode 100644 cdist/conf/type/__consul_template/files/consul-template.upstart create mode 100644 cdist/conf/type/__consul_template/man.text create mode 100755 cdist/conf/type/__consul_template/manifest create mode 100644 cdist/conf/type/__consul_template/parameter/boolean create mode 100644 cdist/conf/type/__consul_template/parameter/default/consul create mode 100644 cdist/conf/type/__consul_template/parameter/optional create mode 100644 cdist/conf/type/__consul_template/singleton create mode 100644 cdist/conf/type/__consul_template_template/man.text create mode 100755 cdist/conf/type/__consul_template_template/manifest create mode 100644 cdist/conf/type/__consul_template_template/parameter/default/state create mode 100644 cdist/conf/type/__consul_template_template/parameter/optional create mode 100644 cdist/conf/type/__consul_template_template/parameter/required create mode 100644 cdist/conf/type/__consul_watch_checks/man.text create mode 100755 cdist/conf/type/__consul_watch_checks/manifest create mode 100644 cdist/conf/type/__consul_watch_checks/parameter/default/state create mode 100644 cdist/conf/type/__consul_watch_checks/parameter/optional create mode 100644 cdist/conf/type/__consul_watch_checks/parameter/required create mode 100644 cdist/conf/type/__consul_watch_event/man.text create mode 100755 cdist/conf/type/__consul_watch_event/manifest create mode 100644 cdist/conf/type/__consul_watch_event/parameter/default/state create mode 100644 cdist/conf/type/__consul_watch_event/parameter/optional create mode 100644 cdist/conf/type/__consul_watch_event/parameter/required create mode 100644 cdist/conf/type/__consul_watch_key/man.text create mode 100755 cdist/conf/type/__consul_watch_key/manifest create mode 100644 cdist/conf/type/__consul_watch_key/parameter/default/state create mode 100644 cdist/conf/type/__consul_watch_key/parameter/optional create mode 100644 cdist/conf/type/__consul_watch_key/parameter/required create mode 100644 cdist/conf/type/__consul_watch_keyprefix/man.text create mode 100755 cdist/conf/type/__consul_watch_keyprefix/manifest create mode 100644 cdist/conf/type/__consul_watch_keyprefix/parameter/default/state create mode 100644 cdist/conf/type/__consul_watch_keyprefix/parameter/optional create mode 100644 cdist/conf/type/__consul_watch_keyprefix/parameter/required create mode 100644 cdist/conf/type/__consul_watch_nodes/man.text create mode 100755 cdist/conf/type/__consul_watch_nodes/manifest create mode 100644 cdist/conf/type/__consul_watch_nodes/parameter/default/state create mode 100644 cdist/conf/type/__consul_watch_nodes/parameter/optional create mode 100644 cdist/conf/type/__consul_watch_nodes/parameter/required create mode 100644 cdist/conf/type/__consul_watch_service/man.text create mode 100755 cdist/conf/type/__consul_watch_service/manifest create mode 100644 cdist/conf/type/__consul_watch_service/parameter/boolean create mode 100644 cdist/conf/type/__consul_watch_service/parameter/default/state create mode 100644 cdist/conf/type/__consul_watch_service/parameter/optional create mode 100644 cdist/conf/type/__consul_watch_service/parameter/required create mode 100644 cdist/conf/type/__consul_watch_services/man.text create mode 100755 cdist/conf/type/__consul_watch_services/manifest create mode 100644 cdist/conf/type/__consul_watch_services/parameter/default/state create mode 100644 cdist/conf/type/__consul_watch_services/parameter/optional create mode 100644 cdist/conf/type/__consul_watch_services/parameter/required diff --git a/cdist/conf/type/__consul/man.text b/cdist/conf/type/__consul/man.text new file mode 100644 index 00000000..f91dcf5c --- /dev/null +++ b/cdist/conf/type/__consul/man.text @@ -0,0 +1,71 @@ +cdist-type__consul(7) +===================== +Steven Armstrong + + +NAME +---- +cdist-type__consul - install consul + + +DESCRIPTION +----------- +Quick and dirty installation of the consul binary. +Note that the consul binary is downloaded on the server and then deployed using +the __file type. + +Future ideas: +- get latest version info from https://checkpoint-api.hashicorp.com/v1/check/consul + - then download from + https://dl.bintray.com/mitchellh/consul/${current_version}_${os}_${arch}.zip +- install from given path to binary +- download from given url +- install from packet + + + +OPTIONAL PARAMETERS +------------------- +install-from:: + uri from where to download consul. This can be anything that curl understands. + If install-uri ends with .zip the downloaded file will be unziped and the + contained file deployed as the consul binary. If install-uri does not end in .zip + it is assumed to be the consul binary and will be deployed as is. + +install-to:: + where to install the binary. Defaults to /usr/local/bin/consul + +state:: + either 'present' or 'absent'. Defaults to 'present' + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +# just install using defaults +__consul + +# download on the machine running cdist, then unzip, then upload to the target host +__consul \ + --install-from https://dl.bintray.com/mitchellh/consul/0.4.1_linux_amd64.zip + +# take binary from local folder on the machine running cdist +__consul \ + --install-from file:///cluster/adm/software/consul/bin/consul + +# install the consul binary to a specific location +__consul \ + --install-to /somewhere/special/consul +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2015 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__consul/manifest b/cdist/conf/type/__consul/manifest new file mode 100755 index 00000000..321a3e4c --- /dev/null +++ b/cdist/conf/type/__consul/manifest @@ -0,0 +1,65 @@ +#!/bin/sh +# +# 2015 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + + +os=$(cat "$__global/explorer/os") + +case "$os" in + centos|redhat|ubuntu|debian|archlinux|gentoo) + # any linux should work + : + ;; + *) + echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 + echo "Please contribute an implementation for it if you can." >&2 + exit 1 + ;; +esac + + +state="$(cat "$__object/parameter/state")" +install_from="$(cat "$__object/parameter/install-from")" +install_to="$(cat "$__object/parameter/install-to")" + +if [ "$state" = "absent" ]; then + __file "$install_to" \ + --state absent + exit 0 +fi + +case "$install_from" in + /*|file://*) + source="${install_from#*file://}" + ;; + *.zip) + mkdir "$__object/files" + source="$__object/files/consul" + # FIXME: need some persistent place to cache downloaded files + curl -s "$install_from" | unzip -p > "$source" + ;; + *) + echo "Do not know how to install from: $install_from" >&2 + exit 1 + ;; +esac + +__file "$install_to" \ + --owner root --group root --mode 755 \ + --source "$source" diff --git a/cdist/conf/type/__consul/parameter/default/install-from b/cdist/conf/type/__consul/parameter/default/install-from new file mode 100644 index 00000000..b1e9908d --- /dev/null +++ b/cdist/conf/type/__consul/parameter/default/install-from @@ -0,0 +1 @@ +https://dl.bintray.com/mitchellh/consul/0.4.1_linux_amd64.zip diff --git a/cdist/conf/type/__consul/parameter/default/install-to b/cdist/conf/type/__consul/parameter/default/install-to new file mode 100644 index 00000000..f85c9e67 --- /dev/null +++ b/cdist/conf/type/__consul/parameter/default/install-to @@ -0,0 +1 @@ +/usr/local/bin/consul diff --git a/cdist/conf/type/__consul/parameter/default/state b/cdist/conf/type/__consul/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul/parameter/optional b/cdist/conf/type/__consul/parameter/optional new file mode 100644 index 00000000..480f1bcd --- /dev/null +++ b/cdist/conf/type/__consul/parameter/optional @@ -0,0 +1,3 @@ +install-from +install-to +state diff --git a/cdist/conf/type/__consul/singleton b/cdist/conf/type/__consul/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__consul_agent/files/consul.systemd b/cdist/conf/type/__consul_agent/files/consul.systemd new file mode 100644 index 00000000..db624fd1 --- /dev/null +++ b/cdist/conf/type/__consul_agent/files/consul.systemd @@ -0,0 +1,17 @@ +[Unit] +Description=Consul Agent +Wants=basic.target +After=basic.target network.target + +[Service] +User=consul +Group=consul +Environment="GOMAXPROCS=2" +ExecStart=/usr/local/bin/consul agent -config-dir /etc/consul/conf.d +ExecReload=/bin/kill -HUP $MAINPID +KillMode=process +Restart=on-failure +RestartSec=42s + +[Install] +WantedBy=multi-user.target diff --git a/cdist/conf/type/__consul_agent/files/consul.sysv b/cdist/conf/type/__consul_agent/files/consul.sysv new file mode 100644 index 00000000..9a2aaeb2 --- /dev/null +++ b/cdist/conf/type/__consul_agent/files/consul.sysv @@ -0,0 +1,93 @@ +#!/bin/bash +# +# /etc/rc.d/init.d/consul +# +# Daemonize the consul agent. +# +# chkconfig: 2345 95 95 +# description: Service discovery and configuration made easy. \ +# Distributed, highly available, and datacenter-aware. +# processname: consul +# pidfile: /var/run/consul/pidfile + +# Source function library. +. /etc/init.d/functions +NAME=consul +CONSUL=/usr/local/bin/consul +CONFIG=/etc/$NAME/conf.d +PID_FILE=/var/run/$NAME/pidfile +LOG_FILE=/var/log/$NAME + +[ -e /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME +export GOMAXPROCS=${GOMAXPROCS:-2} + +mkdir -p /var/run/$NAME +chown consul /var/run/$NAME + +start() { + echo -n "Starting $NAME: " + daemon --user=consul \ + --pidfile="$PID_FILE" \ + "$CONSUL" agent -pid-file="$PID_FILE" -config-dir "$CONFIG" >> "$LOG_FILE" & + retcode=$? + touch /var/lock/subsys/$NAME + return $retcode +} + +stop() { + echo -n "Shutting down $NAME: " + "$CONSUL" leave + retcode=$? + rm -f /var/lock/subsys/$NAME + return $retcode +} + +case "$1" in + start) + if $(status -p "$PID_FILE" $NAME >/dev/null); then + echo "$NAME already running" + else + start + fi + ;; + stop) + if $(status -p "$PID_FILE" $NAME >/dev/null); then + stop + else + echo "$NAME not running" + fi + ;; + info) + "$CONSUL" info + ;; + status) + status -p "$PID_FILE" $NAME + exit $? + ;; + restart) + if $(status -p "$PID_FILE" $NAME >/dev/null); then + stop + fi + start + ;; + reload) + if $(status -p "$PID_FILE" $NAME >/dev/null); then + kill -HUP `cat $PID_FILE` + else + echo "$NAME not running" + fi + ;; + condrestart) + if [ -f /var/lock/subsys/$NAME ]; then + if $(status -p "$PID_FILE" $NAME >/dev/null); then + stop + fi + start + fi + ;; + *) + echo "Usage: $NAME {start|stop|status|reload|restart}" + exit 1 + ;; +esac +exit $? diff --git a/cdist/conf/type/__consul_agent/files/consul.upstart b/cdist/conf/type/__consul_agent/files/consul.upstart new file mode 100644 index 00000000..ed0c7b8e --- /dev/null +++ b/cdist/conf/type/__consul_agent/files/consul.upstart @@ -0,0 +1,13 @@ +description "Consul Agent" +start on (local-filesystems and net-device-up IFACE!=lo) +stop on runlevel [06] + +setuid consul +setgid consul + +respawn +respawn limit 10 10 +kill timeout 10 + +exec /usr/local/bin/consul agent -config-dir /etc/consul/conf.d + diff --git a/cdist/conf/type/__consul_agent/gencode-remote b/cdist/conf/type/__consul_agent/gencode-remote new file mode 100755 index 00000000..04662967 --- /dev/null +++ b/cdist/conf/type/__consul_agent/gencode-remote @@ -0,0 +1,31 @@ +#!/bin/sh +# +# 2015 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +service="consul" +state="$(cat "$__object/parameter/state")" + +case "$state" in + present) + : + ;; + absent) + echo "service $service stop || true" + ;; +esac diff --git a/cdist/conf/type/__consul_agent/man.text b/cdist/conf/type/__consul_agent/man.text new file mode 100644 index 00000000..63337185 --- /dev/null +++ b/cdist/conf/type/__consul_agent/man.text @@ -0,0 +1,134 @@ +cdist-type__consul_agent(7) +=========================== +Steven Armstrong + + +NAME +---- +cdist-type__consul_agent - manage the consul agent + + +DESCRIPTION +----------- +Configure and manage the consul agent. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +bind-addr:: + sets the bind address for cluster communication +bootstrap-expect:: + sets server to expect bootstrap mode +ca-file-source:: + path to a PEM encoded certificate authority file which will be uploaded and + configure using the ca_file config option. +cert-file-source:: + path to a PEM encoded certificate file which will be uploaded and + configure using the cert_file config option. +client-addr:: + sets the address to bind for client access +datacenter:: + datacenter of the agent +encrypt:: + provides the gossip encryption key +group:: + the primary group for the agent +json-config:: + path to a partial json config file without leading { and trailing }. + If json-config is '-' (dash), take what was written to stdin as the file content. +key-file-source:: + path to a PEM encoded private key file which will be uploaded and + configure using the key_file config option. +node-name:: + name of this node. Must be unique in the cluster +retry-join:: + address to attempt joining every retry_interval until at least one join works. + Can be specified multiple times. +user:: + the user to run the agent as +state:: + if the agent is 'present' or 'absent'. Defaults to 'present'. + Currently state=absent is not working due to some dependency issues. + + +BOOLEAN PARAMETERS +------------------ +disable-remote-exec:: + disables support for remote execution. When set to true, the agent will ignore any incoming remote exec requests. +disable-update-check:: + disables automatic checking for security bulletins and new version releases +leave-on-terminate:: + gracefully leave cluster on SIGTERM +rejoin-after-leave:: + rejoin the cluster using the previous state after leaving +server:: + used to control if an agent is in server or client mode +syslog:: + enables logging to syslog +verify-incoming:: + enforce the use of TLS and verify a client's authenticity on incomming connections +verify-outgoing:: + enforce the use of TLS and verify the peers authenticity on outgoing connections + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +# configure as server, bootstrap and rejoin +hostname="$(cat "$__global/explorer/hostname")" +__consul_agent \ + --datacenter dc1 \ + --node-name "${hostname%%.*}" \ + --disable-update-check \ + --server \ + --rejoin-after-leave \ + --bootstrap-expect 3 \ + --retry-join consul-01 \ + --retry-join consul-02 \ + --retry-join consul-03 + +# configure as server, bootstrap and rejoin with ssl support +hostname="$(cat "$__global/explorer/hostname")" +__consul_agent \ + --datacenter dc1 \ + --node-name "${hostname%%.*}" \ + --disable-update-check \ + --server \ + --rejoin-after-leave \ + --bootstrap-expect 3 \ + --retry-join consul-01 \ + --retry-join consul-02 \ + --retry-join consul-03 \ + --ca-file-source /path/to/ca.pem \ + --cert-file-source /path/to/cert.pem \ + --key-file-source /path/to/key.pem \ + --verify-incoming \ + --verify-outgoing + +# configure as client and try joining existing cluster +__consul_agent \ + --datacenter dc1 \ + --node-name "${hostname%%.*}" \ + --disable-update-check \ + --retry-join consul-01 \ + --retry-join consul-02 \ + --retry-join consul-03 + +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2015 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__consul_agent/manifest b/cdist/conf/type/__consul_agent/manifest new file mode 100755 index 00000000..f9514755 --- /dev/null +++ b/cdist/conf/type/__consul_agent/manifest @@ -0,0 +1,175 @@ +#!/bin/sh +# +# 2015 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + + +os=$(cat "$__global/explorer/os") + +case "$os" in + centos|redhat) + # whitelist safeguard + : + ;; + *) + echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 + echo "Please contribute an implementation for it if you can." >&2 + exit 1 + ;; +esac + +state="$(cat "$__object/parameter/state")" +user="$(cat "$__object/parameter/user")" +group="$(cat "$__object/parameter/group")" +data_dir="/var/lib/consul" +conf_dir="/etc/consul/conf.d" +conf_file="config.json" + +# FIXME: there has got to be a better way to handle the dependencies in this case +case "$state" in + present) + __group "$group" --system --state "$state" + require="__group/$group" \ + __user "$user" --system --gid "$group" \ + --home "$data_dir" --state "$state" + export require="__user/consul" + ;; + absent) + echo "Sorry, state=absent currently not supported :-(" >&2 + exit 1 + require="$__object_name" \ + __user "$user" --system --gid "$group" --state "$state" + require="__user/$user" \ + __group "$group" --system --state "$state" + ;; +esac + +__directory /etc/consul \ + --owner root --group "$group" --mode 750 --state "$state" +require="__directory/etc/consul" \ + __directory "$conf_dir" \ + --owner root --group "$group" --mode 750 --state "$state" + +if [ -f "$__object/parameter/ca-file-source" -o -f "$__object/parameter/cert-file-source" -o -f "$__object/parameter/key-file-source" ]; then + # create directory for ssl certs + require="__directory/etc/consul" \ + __directory /etc/consul/ssl \ + --owner root --group "$group" --mode 750 --state "$state" +fi + +__directory "$data_dir" \ + --owner "$user" --group "$group" --mode 770 --state "$state" + + +# Generate json config file +( +echo "{" + +# parameters we define ourself +printf ' "data_dir": "%s"\n' "$data_dir" +printf ' ,"config_dir": "%s"\n' "$conf_dir" + +for param in $(ls "$__object/parameter/"); do + case "$param" in + state|user|group|json-config) continue ;; + ca-file-source|cert-file-source|key-file-source) + source="$(cat "$__object/parameter/$param")" + destination="/etc/consul/ssl/${source##*/}" + require="__directory/etc/consul/ssl" \ + __file "$destination" \ + --owner root --group consul --mode 640 \ + --source "$source" \ + --state "$state" + key="$(echo "${param%-*}" | tr '-' '_')" + printf ' ,"%s": "%s"\n' "$key" "$destination" + ;; + disable-remote-exec|disable-update-check|leave-on-terminate|rejoin-after-leave|server|syslog|verify-incoming|verify-outgoing) + # handle boolean parameters + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": true\n' "$key" + ;; + retry-join) + # join multiple parameters into json array + retry_join="$(awk '{printf "\""$1"\","}' "$__object/parameter/retry-join")" + # remove trailing , + printf ' ,"retry_join": [%s]\n' "${retry_join%*,}" + ;; + bootstrap-expect) + # integer key=value parameters + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": %s\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + *) + # string key=value parameters + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + esac +done +if [ -f "$__object/parameter/json-config" ]; then + json_config="$(cat "$__object/parameter/json-config")" + if [ "$json_config" = "-" ]; then + json_config="$__object/stdin" + fi + printf ',' + # remove trailing , + json=$(cat "$json_config") + echo "${json%*,}" +fi +echo "}" +) | \ +require="__directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group "$group" --mode 640 \ + --state "$state" \ + --onchange 'service consul status >/dev/null && service consul reload || true' \ + --source - + + +# Install init script to start on boot +case "$os" in + centos|redhat) + os_version="$(sed 's/[^0-9.]//g' "$__global/explorer/os_version")" + major_version="${os_version%%.*}" + case "$major_version" in + 7) + __file /lib/systemd/system/consul.service \ + --owner root --group root --mode 0555 \ + --state "$state" \ + --source "$__type/files/consul.systemd" + export require="__file/lib/systemd/system/consul.service" + ;; + *) + __file /etc/init.d/consul \ + --owner root --group root --mode 0555 \ + --state "$state" \ + --source "$__type/files/consul.sysv" + export require="__file/etc/init.d/consul" + ;; + esac + __start_on_boot consul --state "$state" + ;; + ubuntu) + __file /etc/init/consul.conf \ + --owner root --group root --mode 0644 \ + --state "$state" \ + --source "$__type/files/consul.upstart" + export require="__file/etc/init/consul.conf" + __start_on_boot consul --state "$state" + ;; +esac diff --git a/cdist/conf/type/__consul_agent/parameter/boolean b/cdist/conf/type/__consul_agent/parameter/boolean new file mode 100644 index 00000000..9efecf49 --- /dev/null +++ b/cdist/conf/type/__consul_agent/parameter/boolean @@ -0,0 +1,8 @@ +disable-remote-exec +disable-update-check +leave-on-terminate +rejoin-after-leave +server +syslog +verify-incoming +verify-outgoing diff --git a/cdist/conf/type/__consul_agent/parameter/default/group b/cdist/conf/type/__consul_agent/parameter/default/group new file mode 100644 index 00000000..7d22c92b --- /dev/null +++ b/cdist/conf/type/__consul_agent/parameter/default/group @@ -0,0 +1 @@ +consul diff --git a/cdist/conf/type/__consul_agent/parameter/default/state b/cdist/conf/type/__consul_agent/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_agent/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_agent/parameter/default/user b/cdist/conf/type/__consul_agent/parameter/default/user new file mode 100644 index 00000000..7d22c92b --- /dev/null +++ b/cdist/conf/type/__consul_agent/parameter/default/user @@ -0,0 +1 @@ +consul diff --git a/cdist/conf/type/__consul_agent/parameter/optional b/cdist/conf/type/__consul_agent/parameter/optional new file mode 100644 index 00000000..bceaf060 --- /dev/null +++ b/cdist/conf/type/__consul_agent/parameter/optional @@ -0,0 +1,13 @@ +bind-addr +bootstrap-expect +ca-file-source +cert-file-source +client-addr +datacenter +encrypt +group +json-config +key-file-source +node-name +user +state diff --git a/cdist/conf/type/__consul_agent/parameter/optional_multiple b/cdist/conf/type/__consul_agent/parameter/optional_multiple new file mode 100644 index 00000000..12cd064c --- /dev/null +++ b/cdist/conf/type/__consul_agent/parameter/optional_multiple @@ -0,0 +1 @@ +retry-join diff --git a/cdist/conf/type/__consul_agent/singleton b/cdist/conf/type/__consul_agent/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__consul_check/man.text b/cdist/conf/type/__consul_check/man.text new file mode 100644 index 00000000..18eaf638 --- /dev/null +++ b/cdist/conf/type/__consul_check/man.text @@ -0,0 +1,68 @@ +cdist-type__consul_check(7) +============================= +Steven Armstrong + + +NAME +---- +cdist-type__consul_check - manages consul checks + + +DESCRIPTION +----------- +Generate and deploy check definitions for a consul agent. +See http://www.consul.io/docs/agent/checks.html for parameter documentation. + +Use either script toghether with interval, or use ttl. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +interval:: + the interval in which the script given with --script should be run +script:: + the shell command to run every --interval +ttl:: + how long a check is considered healthy without being updated through the + HTTP interfave +id:: + Defaults to --name +name:: + The name of this check. Defaults to __object_id +notes:: + human readable description +state:: + if this check is 'present' or 'absent'. Defaults to 'present'. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__consul_check redis \ + --script /usr/local/bin/check_redis.py \ + --interval 10s + +__consul_check some-object-id \ + --id web-app \ + --name "Web App Status" \ + --notes "Web app does a curl internally every 10 seconds" \ + --ttl 30s +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- cdist-type__consul_agent(7) + + +COPYING +------- +Copyright \(C) 2015 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__consul_check/manifest b/cdist/conf/type/__consul_check/manifest new file mode 100755 index 00000000..3004f319 --- /dev/null +++ b/cdist/conf/type/__consul_check/manifest @@ -0,0 +1,64 @@ +#!/bin/sh +# +# 2015 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +name="$(cat "$__object/parameter/name" 2>/dev/null || echo "$__object_id")" +conf_dir="/etc/consul/conf.d" +conf_file="check_${name}.json" +state="$(cat "$__object/parameter/state")" + +# Sanity checks +if [ -f "$__object/parameter/script" -a -f "$__object/parameter/ttl" ]; then + echo "Use either --script together with --interval OR --ttl, but not both" >&2 + exit 1 +fi +if [ -f "$__object/parameter/script" -a ! -f "$__object/parameter/interval" ]; then + echo "When using --script you must also define --interval" >&2 + exit 1 +fi + +# Generate json config file +( +echo "{" +printf ' "check": {\n' +printf ' "name": "%s"\n' "$name" +for param in $(ls "$__object/parameter/"); do + case "$param" in + state|name|interval) continue ;; + script) + printf ' ,"script": "%s"\n' "$(cat "$__object/parameter/script")" + printf ' ,"interval": "%s"\n' "$(cat "$__object/parameter/interval")" + ;; + *) + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + esac +done +# end check +echo " }" +# end json file +echo "}" +) | \ +require="__directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group consul --mode 640 \ + --state "$state" \ + --onchange 'service consul status >/dev/null && service consul reload || true' \ + --source - diff --git a/cdist/conf/type/__consul_check/parameter/default/state b/cdist/conf/type/__consul_check/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_check/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_check/parameter/optional b/cdist/conf/type/__consul_check/parameter/optional new file mode 100644 index 00000000..f6c3a6e4 --- /dev/null +++ b/cdist/conf/type/__consul_check/parameter/optional @@ -0,0 +1,7 @@ +id +interval +name +notes +script +state +ttl diff --git a/cdist/conf/type/__consul_reload/gencode-remote b/cdist/conf/type/__consul_reload/gencode-remote new file mode 100755 index 00000000..9369db73 --- /dev/null +++ b/cdist/conf/type/__consul_reload/gencode-remote @@ -0,0 +1,24 @@ +#!/bin/sh +# +# 2015 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +service="consul" +if grep -q "^__file/etc/consul/conf.d/" "$__messages_in"; then + echo "service $service status && service $service reload || true" +fi diff --git a/cdist/conf/type/__consul_reload/man.text b/cdist/conf/type/__consul_reload/man.text new file mode 100644 index 00000000..8dd045cf --- /dev/null +++ b/cdist/conf/type/__consul_reload/man.text @@ -0,0 +1,42 @@ +cdist-type__consul_reload(7) +============================ +Steven Armstrong + + +NAME +---- +cdist-type__consul_reload - reload consul + + +DESCRIPTION +----------- +Reload consul after configuration changes. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +None. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__consul_reload +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2015 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__consul_reload/singleton b/cdist/conf/type/__consul_reload/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__consul_service/man.text b/cdist/conf/type/__consul_service/man.text new file mode 100644 index 00000000..6bb024b1 --- /dev/null +++ b/cdist/conf/type/__consul_service/man.text @@ -0,0 +1,71 @@ +cdist-type__consul_service(7) +============================= +Steven Armstrong + + +NAME +---- +cdist-type__consul_service - manages consul services + + +DESCRIPTION +----------- +Generate and deploy service definitions for a consul agent. +See http://www.consul.io/docs/agent/services.html for parameter documentation. + +Use either script together with interval, or use ttl. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +check-interval:: + the interval in which the script given with --check-script should be run +check-script:: + the shell command to run every --check-interval +check-ttl:: + how long a service is considered healthy without being updated through the + HTTP interfave +id:: + Defaults to --name +name:: + The name of this service. Defaults to __object_id +port:: + the port at which this service can be reached +state:: + if this service is 'present' or 'absent'. Defaults to 'present'. +tag:: + a tag to add to this service. Can be specified multiple times. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__consul_service redis \ + --tag master \ + --tag production \ + --port 8000 \ + --check-script /usr/local/bin/check_redis.py \ + --check-interval 10s + +__consul_service webapp \ + --port 80 \ + --check-ttl 10s +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- cdist-type__consul_agent(7) + + +COPYING +------- +Copyright \(C) 2015 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__consul_service/manifest b/cdist/conf/type/__consul_service/manifest new file mode 100755 index 00000000..9ba64141 --- /dev/null +++ b/cdist/conf/type/__consul_service/manifest @@ -0,0 +1,83 @@ +#!/bin/sh +# +# 2015 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +name="$(cat "$__object/parameter/name" 2>/dev/null || echo "$__object_id")" +conf_dir="/etc/consul/conf.d" +conf_file="service_${name}.json" +state="$(cat "$__object/parameter/state")" + +# Sanity checks +if [ -f "$__object/parameter/check-script" -a -f "$__object/parameter/check-ttl" ]; then + echo "Use either --check-script together with --check-interval OR --check-ttl, but not both" >&2 + exit 1 +fi +if [ -f "$__object/parameter/check-script" -a ! -f "$__object/parameter/check-interval" ]; then + echo "When using --check-script you must also define --check-interval" >&2 + exit 1 +fi + +# Generate json config file +( +echo "{" +printf ' "service": {\n' +printf ' "name": "%s"\n' "$name" +for param in $(ls "$__object/parameter/"); do + case "$param" in + state|name|check-interval) continue ;; + check-script) + printf ' ,"check": {\n' + printf ' "script": "%s"\n' "$(cat "$__object/parameter/check-script")" + printf ' ,"interval": "%s"\n' "$(cat "$__object/parameter/check-interval")" + printf ' }\n' + ;; + check-ttl) + printf ' ,"check": {\n' + printf ' "ttl": "%s"\n' "$(cat "$__object/parameter/check-ttl")" + printf ' }\n' + ;; + tag) + # create json array from newline delimited file + tags="$(awk '{printf "\""$1"\","}' "$__object/parameter/tag")" + # remove trailing , + printf ' ,"tags": [%s]\n' "${tags%*,}" + ;; + port) + # integer key=value parameters + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": %s\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + *) + # string key=value parameters + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + esac +done +# end service +echo " }" +# end json file +echo "}" +) | \ +require="__directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group consul --mode 640 \ + --state "$state" \ + --onchange 'service consul status >/dev/null && service consul reload || true' \ + --source - diff --git a/cdist/conf/type/__consul_service/parameter/default/state b/cdist/conf/type/__consul_service/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_service/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_service/parameter/optional b/cdist/conf/type/__consul_service/parameter/optional new file mode 100644 index 00000000..496e31a3 --- /dev/null +++ b/cdist/conf/type/__consul_service/parameter/optional @@ -0,0 +1,7 @@ +check-interval +check-script +check-ttl +id +name +port +state diff --git a/cdist/conf/type/__consul_service/parameter/optional_multiple b/cdist/conf/type/__consul_service/parameter/optional_multiple new file mode 100644 index 00000000..42c7c82c --- /dev/null +++ b/cdist/conf/type/__consul_service/parameter/optional_multiple @@ -0,0 +1 @@ +tag diff --git a/cdist/conf/type/__consul_template/files/consul-template.systemd b/cdist/conf/type/__consul_template/files/consul-template.systemd new file mode 100644 index 00000000..c67eaab5 --- /dev/null +++ b/cdist/conf/type/__consul_template/files/consul-template.systemd @@ -0,0 +1,19 @@ +[Unit] +Description=Consul-Template Daemon +Wants=basic.target +After=basic.target network.target + +[Service] +User=root +Group=root +Environment="CONSUL_TEMPLATE_LOG=info" +Environment="GOMAXPROCS=2" +ExecStart=/usr/local/bin/consul-template -config /etc/consul-template/conf.d +ExecReload=/bin/kill -HUP $MAINPID +KillMode=process +Restart=on-failure +RestartSec=10s +LimitNOFILE=4096 + +[Install] +WantedBy=multi-user.target diff --git a/cdist/conf/type/__consul_template/files/consul-template.sysv b/cdist/conf/type/__consul_template/files/consul-template.sysv new file mode 100644 index 00000000..0a463020 --- /dev/null +++ b/cdist/conf/type/__consul_template/files/consul-template.sysv @@ -0,0 +1,89 @@ +#!/bin/bash +# +# /etc/rc.d/init.d/consul-template +# +# Daemonize the consul-template agent. +# +# chkconfig: 2345 95 95 +# description: Generic template rendering and notifications with Consul +# processname: consul-template +# pidfile: /var/run/consul-template/pidfile + +# Source function library. +. /etc/init.d/functions +NAME=consul-template +CONSUL_TEMPLATE=/usr/local/bin/consul-template +CONFIG=/etc/$NAME/conf.d +PID_FILE=/var/run/$NAME/pidfile +LOG_FILE=/var/log/$NAME + +[ -e /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME +export CONSUL_TEMPLATE_LOG=${CONSUL_TEMPLATE_LOG:-info} +export GOMAXPROCS=${GOMAXPROCS:-2} + +mkdir -p /var/run/$NAME + +start() { + echo -n "Starting $NAME: " + daemon --pidfile="$PID_FILE" \ + "$CONSUL_TEMPLATE" -config "$CONFIG" >> "$LOG_FILE" 2>&1 & + echo $! > "$PID_FILE" + retcode=$? + touch /var/lock/subsys/$NAME + return $retcode +} + +stop() { + echo -n "Shutting down $NAME: " + killproc -p $PID_FILE $CONSUL_TEMPLATE + retcode=$? + rm -f /var/lock/subsys/$NAME + return $retcode +} + +case "$1" in + start) + if $(status -p "$PID_FILE" $NAME >/dev/null); then + echo "$NAME already running" + else + start + fi + ;; + stop) + if $(status -p "$PID_FILE" $NAME >/dev/null); then + stop + else + echo "$NAME not running" + fi + ;; + status) + status -p "$PID_FILE" $NAME + exit $? + ;; + restart) + if $(status -p "$PID_FILE" $NAME >/dev/null); then + stop + fi + start + ;; + reload) + if $(status -p "$PID_FILE" $NAME >/dev/null); then + kill -HUP `cat $PID_FILE` + else + echo "$NAME not running" + fi + ;; + condrestart) + if [ -f /var/lock/subsys/$NAME ]; then + if $(status -p "$PID_FILE" $NAME >/dev/null); then + stop + fi + start + fi + ;; + *) + echo "Usage: $NAME {start|stop|status|reload|restart}" + exit 1 + ;; +esac +exit $? diff --git a/cdist/conf/type/__consul_template/files/consul-template.upstart b/cdist/conf/type/__consul_template/files/consul-template.upstart new file mode 100644 index 00000000..b81a2818 --- /dev/null +++ b/cdist/conf/type/__consul_template/files/consul-template.upstart @@ -0,0 +1,12 @@ +description "Consul-Template Daemon" +start on (local-filesystems and net-device-up IFACE!=lo) +stop on runlevel [06] + +env CONSUL_TEMPLATE_LOG=info +env GOMAXPROCS=${GOMAXPROCS} + +exec /usr/local/bin/consul-template -config /etc/consul-template/conf.d >> /var/log/consul-template 2>&1 + +respawn +respawn limit 10 10 +kill timeout 10 diff --git a/cdist/conf/type/__consul_template/man.text b/cdist/conf/type/__consul_template/man.text new file mode 100644 index 00000000..26afd4f1 --- /dev/null +++ b/cdist/conf/type/__consul_template/man.text @@ -0,0 +1,72 @@ +cdist-type__consul_template(7) +============================== +Steven Armstrong + + +NAME +---- +cdist-type__consul_template - manage the consul-template service + + +DESCRIPTION +----------- +Installs consul-template, generates a global config file and creates directory +for per template config files. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +auth:: + specify a username (and password) for basic authentication. +batch-size:: + the size of the batch when polling multiple dependencies. +consul:: + the location of the Consul instance to query (may be an IP address or FQDN) with port. + Defaults to 'localhost:8500'. +max-stale:: + the maximum staleness of a query. If specified, Consul will distribute work among all + servers instead of just the leader. +retry:: + the amount of time to wait if Consul returns an error when communicating + with the API. +token:: + the Consul API token. +wait:: + the minimum(:maximum) to wait before rendering a new template to disk and + triggering a command, separated by a colon (:). If the optional maximum + value is omitted, it is assumed to be 4x the required minimum value. + + +BOOLEAN PARAMETERS +------------------ +ssl:: + use HTTPS while talking to Consul. Requires the Consul server to be configured to serve secure connections. +ssl-no-verify:: + ignore certificate warnings. Only used if ssl is enabled. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__consul_template \ + --consul consul.service.consul:8500 \ + --retry 30s +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- https://github.com/hashicorp/consul-template + + +COPYING +------- +Copyright \(C) 2015 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__consul_template/manifest b/cdist/conf/type/__consul_template/manifest new file mode 100755 index 00000000..dba7e68e --- /dev/null +++ b/cdist/conf/type/__consul_template/manifest @@ -0,0 +1,121 @@ +#!/bin/sh +# +# 2015 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + + +os=$(cat "$__global/explorer/os") + +case "$os" in + centos|redhat) + # whitelist safeguard + : + ;; + *) + echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 + echo "Please contribute an implementation for it if you can." >&2 + exit 1 + ;; +esac + +state="present" +conf_dir="/etc/consul-template/conf.d" +conf_file="config.hcl" +template_dir="/etc/consul-template/template" + +__directory /etc/consul-template \ + --owner root --group root --mode 750 +require="__directory/etc/consul-template" \ + __directory "$conf_dir" \ + --owner root --group root --mode 750 +require="__directory/etc/consul-template" \ + __directory "$template_dir" \ + --owner root --group root --mode 750 + + +__staged_file /usr/local/bin/consul-template \ + --source https://github.com/hashicorp/consul-template/releases/download/v0.6.5/consul-template_0.6.5_linux_amd64.tar.gz \ + --cksum '1356006333 8496656 consul-template' \ + --fetch-command 'curl -s -L "%s"' \ + --prepare-command 'tar -xzf "%s"; cat consul-template_*/consul-template' \ + --state present \ + --group root \ + --owner root \ + --mode 755 + + +# Generate hcl config file +( +for param in $(ls "$__object/parameter/"); do + case "$param" in + ssl|ssl-no-verify) # boolean + key="$(echo "$param" | tr '-' '_')" + printf '%s = true\n' "$key" + ;; + auth|batch-size|consul|max-stale|retry|token|wait) + key="$(echo "$param" | tr '-' '_')" + printf '%s = "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + *) + # ignore unknown parameters + : + ;; + esac +done +) | \ +require="__directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group root --mode 640 \ + --state "$state" \ + --onchange 'service consul-template status >/dev/null && service consul-template reload || true' \ + --source - + + +# Install init script to start on boot +service="consul-template" +case "$os" in + centos|redhat) + os_version="$(sed 's/[^0-9.]//g' "$__global/explorer/os_version")" + major_version="${os_version%%.*}" + case "$major_version" in + 7) + __file "/lib/systemd/system/${service}.service" \ + --owner root --group root --mode 0555 \ + --state "$state" \ + --source "$__type/files/${service}.systemd" + export require="__file/lib/systemd/system/${service}.service" + ;; + *) + __file "/etc/init.d/${service}" \ + --owner root --group root --mode 0555 \ + --state "$state" \ + --source "$__type/files/${service}.sysv" + export require="__file/etc/init.d/${service}" + ;; + esac + __start_on_boot "$service" --state "$state" + ;; + ubuntu) + __file "/etc/init/${service}.conf" \ + --owner root --group root --mode 0644 \ + --state "$state" \ + --source "$__type/files/${service}.upstart" + export require="__file/etc/init/${service}.conf" + __start_on_boot "$service" --state "$state" + ;; +esac diff --git a/cdist/conf/type/__consul_template/parameter/boolean b/cdist/conf/type/__consul_template/parameter/boolean new file mode 100644 index 00000000..5e17dcd7 --- /dev/null +++ b/cdist/conf/type/__consul_template/parameter/boolean @@ -0,0 +1,2 @@ +ssl +ssl-no-verify diff --git a/cdist/conf/type/__consul_template/parameter/default/consul b/cdist/conf/type/__consul_template/parameter/default/consul new file mode 100644 index 00000000..42dfa616 --- /dev/null +++ b/cdist/conf/type/__consul_template/parameter/default/consul @@ -0,0 +1 @@ +localhost:8500 diff --git a/cdist/conf/type/__consul_template/parameter/optional b/cdist/conf/type/__consul_template/parameter/optional new file mode 100644 index 00000000..34c277b9 --- /dev/null +++ b/cdist/conf/type/__consul_template/parameter/optional @@ -0,0 +1,7 @@ +auth +batch-size +consul +max-stale +retry +token +wait diff --git a/cdist/conf/type/__consul_template/singleton b/cdist/conf/type/__consul_template/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__consul_template_template/man.text b/cdist/conf/type/__consul_template_template/man.text new file mode 100644 index 00000000..159a63fb --- /dev/null +++ b/cdist/conf/type/__consul_template_template/man.text @@ -0,0 +1,69 @@ +cdist-type__consul_template_template(7) +======================================= +Steven Armstrong + + +NAME +---- +cdist-type__consul_template_template - manage consul-template templates + + +DESCRIPTION +----------- +Generate and deploy template definitions for a consul-template. +See https://github.com/hashicorp/consul-template#examples for documentation. +Templates are written in the Go template format. +Either the --source or the --source-file parameter must be given. + + +REQUIRED PARAMETERS +------------------- +destination:: + the destination where the generated file should go. + + +OPTIONAL PARAMETERS +------------------- +command:: + an optional command to run after rendering the template to its destination. +source:: + path to the template source. Conflicts --source-file. +source-file:: + path to a local file which is uploaded using the __file type and configured + as the source. + If source is '-' (dash), take what was written to stdin as the file content. + Conflicts --source. +state:: + if this template is 'present' or 'absent'. Defaults to 'present'. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +# configure template on the target +__consul_template_template nginx \ + --source /etc/my-consul-templates/nginx.ctmpl \ + --destination /etc/nginx/nginx.conf \ + --command 'service nginx restart' + + +# upload a local file to the target and configure it +__consul_template_template nginx \ + --source-file "$__manifest/files/nginx.ctmpl" \ + --destination /etc/nginx/nginx.conf \ + --command 'service nginx restart' +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- cdist-type__consul_template(7) +- cdist-type__consul_template_config(7) + + +COPYING +------- +Copyright \(C) 2015 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__consul_template_template/manifest b/cdist/conf/type/__consul_template_template/manifest new file mode 100755 index 00000000..c997a2c8 --- /dev/null +++ b/cdist/conf/type/__consul_template_template/manifest @@ -0,0 +1,74 @@ +#!/bin/sh +# +# 2015 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +name="$(cat "$__object/parameter/name" 2>/dev/null || echo "$__object_id")" +state="$(cat "$__object/parameter/state")" +conf_dir="/etc/consul-template/conf.d" +conf_file="template_${name}.hcl" +template_dir="/etc/consul-template/template" +require="" + +# Sanity checks +if [ -f "$__object/parameter/source" -a -f "$__object/parameter/source-file" ]; then + echo "Use either --source OR --source-file, but not both." >&2 + exit 1 +fi +if [ ! -f "$__object/parameter/source" -a ! -f "$__object/parameter/source-file" ]; then + echo "Either --source OR --source-file must be given." >&2 + exit 1 +fi + +# Generate hcl config file +( +printf 'template {\n' +for param in $(ls "$__object/parameter/"); do + case "$param" in + source-file) + source="$(cat "$__object/parameter/$param")" + if [ "$source" = "-" ]; then + source="$__object/stdin" + fi + destination="${template_dir}/${name}" + require="__directory${template_dir}" \ + __file "$destination" \ + --owner root --group root --mode 640 \ + --source "$source" \ + --state "$state" + export require="__file${destination}" + printf ' source = "%s"\n' "$destination" + + ;; + source|destination|command) + printf ' %s = "%s"\n' "$param" "$(cat "$__object/parameter/$param")" + ;; + *) + # ignore unknown parameters + : + ;; + esac +done +printf '}\n' +) | \ +require="$require __directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group root --mode 640 \ + --state "$state" \ + --onchange 'service consul-template status >/dev/null && service consul-template reload || true' \ + --source - diff --git a/cdist/conf/type/__consul_template_template/parameter/default/state b/cdist/conf/type/__consul_template_template/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_template_template/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_template_template/parameter/optional b/cdist/conf/type/__consul_template_template/parameter/optional new file mode 100644 index 00000000..229f6c89 --- /dev/null +++ b/cdist/conf/type/__consul_template_template/parameter/optional @@ -0,0 +1,4 @@ +command +source +source-file +state diff --git a/cdist/conf/type/__consul_template_template/parameter/required b/cdist/conf/type/__consul_template_template/parameter/required new file mode 100644 index 00000000..ac459b09 --- /dev/null +++ b/cdist/conf/type/__consul_template_template/parameter/required @@ -0,0 +1 @@ +destination diff --git a/cdist/conf/type/__consul_watch_checks/man.text b/cdist/conf/type/__consul_watch_checks/man.text new file mode 100644 index 00000000..75c42fc2 --- /dev/null +++ b/cdist/conf/type/__consul_watch_checks/man.text @@ -0,0 +1,64 @@ +cdist-type__consul_watch_checks(7) +================================== +Steven Armstrong + + +NAME +---- +cdist-type__consul_watch_checks - manages consul checks watches + + +DESCRIPTION +----------- +Generate and deploy watch definitions of type 'checks' for a consul agent. +See http://www.consul.io/docs/agent/watches.html for parameter documentation. + + +REQUIRED PARAMETERS +------------------- +handler:: + the handler to invoke when the data view updates + + +OPTIONAL PARAMETERS +------------------- +datacenter:: + can be provided to override the agent's default datacenter +filter-service:: + filter to a specific service. Conflicts with --filter-state. +filter-state:: + filter to a specific state. Conflicts with --filter-service. +state:: + if this watch is 'present' or 'absent'. Defaults to 'present'. +token:: + can be provided to override the agent's default ACL token + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__consul_watch_checks some-id \ + --handler /usr/bin/my-handler.sh + +__consul_watch_checks some-id \ + --filter-service consul \ + --handler /usr/bin/my-handler.sh + +__consul_watch_checks some-id \ + --filter-state passing \ + --handler /usr/bin/my-handler.sh +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- cdist-type__consul_agent(7) +- http://www.consul.io/docs/agent/watches.html + + +COPYING +------- +Copyright \(C) 2015 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__consul_watch_checks/manifest b/cdist/conf/type/__consul_watch_checks/manifest new file mode 100755 index 00000000..c05ae9eb --- /dev/null +++ b/cdist/conf/type/__consul_watch_checks/manifest @@ -0,0 +1,61 @@ +#!/bin/sh +# +# 2015 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +cdist_type="${__type##*/}" +watch_type="${cdist_type##*_}" +conf_dir="/etc/consul/conf.d" +conf_file="watch_${watch_type}_${__object_id}.json" +state="$(cat "$__object/parameter/state")" + +# Sanity checks +if [ -f "$__object/parameter/filter-service" -a -f "$__object/parameter/filter-state" ]; then + echo "Use either --filter-service or --filter-state but not both." >&2 + exit 1 +fi + +# Generate json config file +( +echo "{" +printf ' "watches": [{\n' +printf ' "type": "%s"\n' "$watch_type" +for param in $(ls "$__object/parameter/"); do + case "$param" in + state) continue ;; + filter-*) + key="${param##*-}" + printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + *) + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + esac +done +# end watches +echo " }]" +# end json file +echo "}" +) | \ +require="__directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group consul --mode 640 \ + --state "$state" \ + --onchange 'service consul status >/dev/null && service consul reload || true' \ + --source - diff --git a/cdist/conf/type/__consul_watch_checks/parameter/default/state b/cdist/conf/type/__consul_watch_checks/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_watch_checks/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_watch_checks/parameter/optional b/cdist/conf/type/__consul_watch_checks/parameter/optional new file mode 100644 index 00000000..d37fd557 --- /dev/null +++ b/cdist/conf/type/__consul_watch_checks/parameter/optional @@ -0,0 +1,5 @@ +datacenter +filter-service +filter-state +state +token diff --git a/cdist/conf/type/__consul_watch_checks/parameter/required b/cdist/conf/type/__consul_watch_checks/parameter/required new file mode 100644 index 00000000..64b916c1 --- /dev/null +++ b/cdist/conf/type/__consul_watch_checks/parameter/required @@ -0,0 +1 @@ +handler diff --git a/cdist/conf/type/__consul_watch_event/man.text b/cdist/conf/type/__consul_watch_event/man.text new file mode 100644 index 00000000..3b393241 --- /dev/null +++ b/cdist/conf/type/__consul_watch_event/man.text @@ -0,0 +1,58 @@ +cdist-type__consul_watch_event(7) +================================= +Steven Armstrong + + +NAME +---- +cdist-type__consul_watch_event - manages consul event watches + + +DESCRIPTION +----------- +Generate and deploy watch definitions of type 'event' for a consul agent. +See http://www.consul.io/docs/agent/watches.html for parameter documentation. + + +REQUIRED PARAMETERS +------------------- +handler:: + the handler to invoke when the data view updates + + +OPTIONAL PARAMETERS +------------------- +datacenter:: + can be provided to override the agent's default datacenter +name:: + restrict the watch to only events with the given name +state:: + if this watch is 'present' or 'absent'. Defaults to 'present'. +token:: + can be provided to override the agent's default ACL token + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__consul_watch_event some-id \ + --handler /usr/bin/my-handler.sh + +__consul_watch_event some-id \ + --name web-deploy \ + --handler /usr/bin/my-handler.sh +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- cdist-type__consul_agent(7) +- http://www.consul.io/docs/agent/watches.html + + +COPYING +------- +Copyright \(C) 2015 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__consul_watch_event/manifest b/cdist/conf/type/__consul_watch_event/manifest new file mode 100755 index 00000000..4e36a10d --- /dev/null +++ b/cdist/conf/type/__consul_watch_event/manifest @@ -0,0 +1,51 @@ +#!/bin/sh +# +# 2015 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +cdist_type="${__type##*/}" +watch_type="${cdist_type##*_}" +conf_dir="/etc/consul/conf.d" +conf_file="watch_${watch_type}_${__object_id}.json" +state="$(cat "$__object/parameter/state")" + +# Generate json config file +( +echo "{" +printf ' "watches": [{\n' +printf ' "type": "%s"\n' "$watch_type" +for param in $(ls "$__object/parameter/"); do + case "$param" in + state) continue ;; + *) + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + esac +done +# end watches +echo " }]" +# end json file +echo "}" +) | \ +require="__directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group consul --mode 640 \ + --state "$state" \ + --onchange 'service consul status >/dev/null && service consul reload || true' \ + --source - diff --git a/cdist/conf/type/__consul_watch_event/parameter/default/state b/cdist/conf/type/__consul_watch_event/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_watch_event/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_watch_event/parameter/optional b/cdist/conf/type/__consul_watch_event/parameter/optional new file mode 100644 index 00000000..ac808c47 --- /dev/null +++ b/cdist/conf/type/__consul_watch_event/parameter/optional @@ -0,0 +1,4 @@ +datacenter +name +state +token diff --git a/cdist/conf/type/__consul_watch_event/parameter/required b/cdist/conf/type/__consul_watch_event/parameter/required new file mode 100644 index 00000000..64b916c1 --- /dev/null +++ b/cdist/conf/type/__consul_watch_event/parameter/required @@ -0,0 +1 @@ +handler diff --git a/cdist/conf/type/__consul_watch_key/man.text b/cdist/conf/type/__consul_watch_key/man.text new file mode 100644 index 00000000..5d8381cb --- /dev/null +++ b/cdist/conf/type/__consul_watch_key/man.text @@ -0,0 +1,55 @@ +cdist-type__consul_watch_key(7) +=============================== +Steven Armstrong + + +NAME +---- +cdist-type__consul_watch_key - manages consul key watches + + +DESCRIPTION +----------- +Generate and deploy watch definitions of type 'key' for a consul agent. +See http://www.consul.io/docs/agent/watches.html for parameter documentation. + + +REQUIRED PARAMETERS +------------------- +handler:: + the handler to invoke when the data view updates +key:: + the key to watch for changes + + +OPTIONAL PARAMETERS +------------------- +datacenter:: + can be provided to override the agent's default datacenter +state:: + if this watch is 'present' or 'absent'. Defaults to 'present'. +token:: + can be provided to override the agent's default ACL token + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__consul_watch_key some-id \ + --key foo/bar/baz \ + --handler /usr/bin/my-key-handler.sh +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- cdist-type__consul_agent(7) +- http://www.consul.io/docs/agent/watches.html + + +COPYING +------- +Copyright \(C) 2015 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__consul_watch_key/manifest b/cdist/conf/type/__consul_watch_key/manifest new file mode 100755 index 00000000..4e36a10d --- /dev/null +++ b/cdist/conf/type/__consul_watch_key/manifest @@ -0,0 +1,51 @@ +#!/bin/sh +# +# 2015 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +cdist_type="${__type##*/}" +watch_type="${cdist_type##*_}" +conf_dir="/etc/consul/conf.d" +conf_file="watch_${watch_type}_${__object_id}.json" +state="$(cat "$__object/parameter/state")" + +# Generate json config file +( +echo "{" +printf ' "watches": [{\n' +printf ' "type": "%s"\n' "$watch_type" +for param in $(ls "$__object/parameter/"); do + case "$param" in + state) continue ;; + *) + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + esac +done +# end watches +echo " }]" +# end json file +echo "}" +) | \ +require="__directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group consul --mode 640 \ + --state "$state" \ + --onchange 'service consul status >/dev/null && service consul reload || true' \ + --source - diff --git a/cdist/conf/type/__consul_watch_key/parameter/default/state b/cdist/conf/type/__consul_watch_key/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_watch_key/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_watch_key/parameter/optional b/cdist/conf/type/__consul_watch_key/parameter/optional new file mode 100644 index 00000000..bfce8305 --- /dev/null +++ b/cdist/conf/type/__consul_watch_key/parameter/optional @@ -0,0 +1,3 @@ +datacenter +state +token diff --git a/cdist/conf/type/__consul_watch_key/parameter/required b/cdist/conf/type/__consul_watch_key/parameter/required new file mode 100644 index 00000000..a7ae5b65 --- /dev/null +++ b/cdist/conf/type/__consul_watch_key/parameter/required @@ -0,0 +1,2 @@ +handler +key diff --git a/cdist/conf/type/__consul_watch_keyprefix/man.text b/cdist/conf/type/__consul_watch_keyprefix/man.text new file mode 100644 index 00000000..e2f05de2 --- /dev/null +++ b/cdist/conf/type/__consul_watch_keyprefix/man.text @@ -0,0 +1,55 @@ +cdist-type__consul_watch_keyprefix(7) +===================================== +Steven Armstrong + + +NAME +---- +cdist-type__consul_watch_keyprefix - manages consul keyprefix watches + + +DESCRIPTION +----------- +Generate and deploy watch definitions of type 'keyprefix' for a consul agent. +See http://www.consul.io/docs/agent/watches.html for parameter documentation. + + +REQUIRED PARAMETERS +------------------- +handler:: + the handler to invoke when the data view updates +prefix:: + the prefix of keys to watch for changes + + +OPTIONAL PARAMETERS +------------------- +datacenter:: + can be provided to override the agent's default datacenter +state:: + if this watch is 'present' or 'absent'. Defaults to 'present'. +token:: + can be provided to override the agent's default ACL token + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__consul_watch_keyprefix some-id \ + --prefix foo/ \ + --handler /usr/bin/my-prefix-handler.sh +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- cdist-type__consul_agent(7) +- http://www.consul.io/docs/agent/watches.html + + +COPYING +------- +Copyright \(C) 2015 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__consul_watch_keyprefix/manifest b/cdist/conf/type/__consul_watch_keyprefix/manifest new file mode 100755 index 00000000..4e36a10d --- /dev/null +++ b/cdist/conf/type/__consul_watch_keyprefix/manifest @@ -0,0 +1,51 @@ +#!/bin/sh +# +# 2015 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +cdist_type="${__type##*/}" +watch_type="${cdist_type##*_}" +conf_dir="/etc/consul/conf.d" +conf_file="watch_${watch_type}_${__object_id}.json" +state="$(cat "$__object/parameter/state")" + +# Generate json config file +( +echo "{" +printf ' "watches": [{\n' +printf ' "type": "%s"\n' "$watch_type" +for param in $(ls "$__object/parameter/"); do + case "$param" in + state) continue ;; + *) + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + esac +done +# end watches +echo " }]" +# end json file +echo "}" +) | \ +require="__directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group consul --mode 640 \ + --state "$state" \ + --onchange 'service consul status >/dev/null && service consul reload || true' \ + --source - diff --git a/cdist/conf/type/__consul_watch_keyprefix/parameter/default/state b/cdist/conf/type/__consul_watch_keyprefix/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_watch_keyprefix/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_watch_keyprefix/parameter/optional b/cdist/conf/type/__consul_watch_keyprefix/parameter/optional new file mode 100644 index 00000000..bfce8305 --- /dev/null +++ b/cdist/conf/type/__consul_watch_keyprefix/parameter/optional @@ -0,0 +1,3 @@ +datacenter +state +token diff --git a/cdist/conf/type/__consul_watch_keyprefix/parameter/required b/cdist/conf/type/__consul_watch_keyprefix/parameter/required new file mode 100644 index 00000000..6223b4de --- /dev/null +++ b/cdist/conf/type/__consul_watch_keyprefix/parameter/required @@ -0,0 +1,2 @@ +handler +keyprefix diff --git a/cdist/conf/type/__consul_watch_nodes/man.text b/cdist/conf/type/__consul_watch_nodes/man.text new file mode 100644 index 00000000..70b83e92 --- /dev/null +++ b/cdist/conf/type/__consul_watch_nodes/man.text @@ -0,0 +1,52 @@ +cdist-type__consul_watch_nodes(7) +================================= +Steven Armstrong + + +NAME +---- +cdist-type__consul_watch_nodes - manages consul nodes watches + + +DESCRIPTION +----------- +Generate and deploy watch definitions of type 'nodes' for a consul agent. +See http://www.consul.io/docs/agent/watches.html for parameter documentation. + + +REQUIRED PARAMETERS +------------------- +handler:: + the handler to invoke when the data view updates + + +OPTIONAL PARAMETERS +------------------- +datacenter:: + can be provided to override the agent's default datacenter +state:: + if this watch is 'present' or 'absent'. Defaults to 'present'. +token:: + can be provided to override the agent's default ACL token + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__consul_watch_nodes some-id \ + --handler /usr/bin/my-key-handler.sh +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- cdist-type__consul_agent(7) +- http://www.consul.io/docs/agent/watches.html + + +COPYING +------- +Copyright \(C) 2015 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__consul_watch_nodes/manifest b/cdist/conf/type/__consul_watch_nodes/manifest new file mode 100755 index 00000000..4e36a10d --- /dev/null +++ b/cdist/conf/type/__consul_watch_nodes/manifest @@ -0,0 +1,51 @@ +#!/bin/sh +# +# 2015 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +cdist_type="${__type##*/}" +watch_type="${cdist_type##*_}" +conf_dir="/etc/consul/conf.d" +conf_file="watch_${watch_type}_${__object_id}.json" +state="$(cat "$__object/parameter/state")" + +# Generate json config file +( +echo "{" +printf ' "watches": [{\n' +printf ' "type": "%s"\n' "$watch_type" +for param in $(ls "$__object/parameter/"); do + case "$param" in + state) continue ;; + *) + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + esac +done +# end watches +echo " }]" +# end json file +echo "}" +) | \ +require="__directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group consul --mode 640 \ + --state "$state" \ + --onchange 'service consul status >/dev/null && service consul reload || true' \ + --source - diff --git a/cdist/conf/type/__consul_watch_nodes/parameter/default/state b/cdist/conf/type/__consul_watch_nodes/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_watch_nodes/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_watch_nodes/parameter/optional b/cdist/conf/type/__consul_watch_nodes/parameter/optional new file mode 100644 index 00000000..bfce8305 --- /dev/null +++ b/cdist/conf/type/__consul_watch_nodes/parameter/optional @@ -0,0 +1,3 @@ +datacenter +state +token diff --git a/cdist/conf/type/__consul_watch_nodes/parameter/required b/cdist/conf/type/__consul_watch_nodes/parameter/required new file mode 100644 index 00000000..64b916c1 --- /dev/null +++ b/cdist/conf/type/__consul_watch_nodes/parameter/required @@ -0,0 +1 @@ +handler diff --git a/cdist/conf/type/__consul_watch_service/man.text b/cdist/conf/type/__consul_watch_service/man.text new file mode 100644 index 00000000..c7731a97 --- /dev/null +++ b/cdist/conf/type/__consul_watch_service/man.text @@ -0,0 +1,74 @@ +cdist-type__consul_watch_service(7) +=================================== +Steven Armstrong + + +NAME +---- +cdist-type__consul_watch_service - manages consul service watches + + +DESCRIPTION +----------- +Generate and deploy watch definitions of type 'service' for a consul agent. +See http://www.consul.io/docs/agent/watches.html for parameter documentation. + + +REQUIRED PARAMETERS +------------------- +handler:: + the handler to invoke when the data view updates +service:: + the service to watch for changes + + +OPTIONAL PARAMETERS +------------------- +datacenter:: + can be provided to override the agent's default datacenter +state:: + if this watch is 'present' or 'absent'. Defaults to 'present'. +token:: + can be provided to override the agent's default ACL token +tag:: + filter by tag + + +BOOLEAN PARAMETERS +------------------ +passingonly:: + specifies if only hosts passing all checks are displayed + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__consul_watch_service some-id \ + --service consul \ + --handler /usr/bin/my-handler.sh + +__consul_watch_service some-id \ + --service redis \ + --tag production \ + --handler /usr/bin/my-handler.sh + +__consul_watch_service some-id \ + --service redis \ + --tag production \ + --passingonly \ + --handler /usr/bin/my-handler.sh +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- cdist-type__consul_agent(7) +- http://www.consul.io/docs/agent/watches.html + + +COPYING +------- +Copyright \(C) 2015 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__consul_watch_service/manifest b/cdist/conf/type/__consul_watch_service/manifest new file mode 100755 index 00000000..6011e288 --- /dev/null +++ b/cdist/conf/type/__consul_watch_service/manifest @@ -0,0 +1,54 @@ +#!/bin/sh +# +# 2015 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +cdist_type="${__type##*/}" +watch_type="${cdist_type##*_}" +conf_dir="/etc/consul/conf.d" +conf_file="watch_${watch_type}_${__object_id}.json" +state="$(cat "$__object/parameter/state")" + +# Generate json config file +( +echo "{" +printf ' "watches": [{\n' +printf ' "type": "%s"\n' "$watch_type" +for param in $(ls "$__object/parameter/"); do + case "$param" in + state) continue ;; + passingonly) + printf ' ,"passingonly": true\n' + ;; + *) + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + esac +done +# end watches +echo " }]" +# end json file +echo "}" +) | \ +require="__directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group consul --mode 640 \ + --state "$state" \ + --onchange 'service consul status >/dev/null && service consul reload || true' \ + --source - diff --git a/cdist/conf/type/__consul_watch_service/parameter/boolean b/cdist/conf/type/__consul_watch_service/parameter/boolean new file mode 100644 index 00000000..4c1e4b3f --- /dev/null +++ b/cdist/conf/type/__consul_watch_service/parameter/boolean @@ -0,0 +1 @@ +passingonly diff --git a/cdist/conf/type/__consul_watch_service/parameter/default/state b/cdist/conf/type/__consul_watch_service/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_watch_service/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_watch_service/parameter/optional b/cdist/conf/type/__consul_watch_service/parameter/optional new file mode 100644 index 00000000..a81860ac --- /dev/null +++ b/cdist/conf/type/__consul_watch_service/parameter/optional @@ -0,0 +1,4 @@ +datacenter +state +tag +token diff --git a/cdist/conf/type/__consul_watch_service/parameter/required b/cdist/conf/type/__consul_watch_service/parameter/required new file mode 100644 index 00000000..e1ffa4d6 --- /dev/null +++ b/cdist/conf/type/__consul_watch_service/parameter/required @@ -0,0 +1,2 @@ +handler +service diff --git a/cdist/conf/type/__consul_watch_services/man.text b/cdist/conf/type/__consul_watch_services/man.text new file mode 100644 index 00000000..bc489493 --- /dev/null +++ b/cdist/conf/type/__consul_watch_services/man.text @@ -0,0 +1,52 @@ +cdist-type__consul_watch_services(7) +==================================== +Steven Armstrong + + +NAME +---- +cdist-type__consul_watch_services - manages consul services watches + + +DESCRIPTION +----------- +Generate and deploy watch definitions of type 'services' for a consul agent. +See http://www.consul.io/docs/agent/watches.html for parameter documentation. + + +REQUIRED PARAMETERS +------------------- +handler:: + the handler to invoke when the data view updates + + +OPTIONAL PARAMETERS +------------------- +datacenter:: + can be provided to override the agent's default datacenter +state:: + if this watch is 'present' or 'absent'. Defaults to 'present'. +token:: + can be provided to override the agent's default ACL token + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__consul_watch_services some-id \ + --handler /usr/bin/my-key-handler.sh +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- cdist-type__consul_agent(7) +- http://www.consul.io/docs/agent/watches.html + + +COPYING +------- +Copyright \(C) 2015 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__consul_watch_services/manifest b/cdist/conf/type/__consul_watch_services/manifest new file mode 100755 index 00000000..4e36a10d --- /dev/null +++ b/cdist/conf/type/__consul_watch_services/manifest @@ -0,0 +1,51 @@ +#!/bin/sh +# +# 2015 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +cdist_type="${__type##*/}" +watch_type="${cdist_type##*_}" +conf_dir="/etc/consul/conf.d" +conf_file="watch_${watch_type}_${__object_id}.json" +state="$(cat "$__object/parameter/state")" + +# Generate json config file +( +echo "{" +printf ' "watches": [{\n' +printf ' "type": "%s"\n' "$watch_type" +for param in $(ls "$__object/parameter/"); do + case "$param" in + state) continue ;; + *) + key="$(echo "$param" | tr '-' '_')" + printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" + ;; + esac +done +# end watches +echo " }]" +# end json file +echo "}" +) | \ +require="__directory${conf_dir}" \ + __config_file "${conf_dir}/${conf_file}" \ + --owner root --group consul --mode 640 \ + --state "$state" \ + --onchange 'service consul status >/dev/null && service consul reload || true' \ + --source - diff --git a/cdist/conf/type/__consul_watch_services/parameter/default/state b/cdist/conf/type/__consul_watch_services/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_watch_services/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_watch_services/parameter/optional b/cdist/conf/type/__consul_watch_services/parameter/optional new file mode 100644 index 00000000..bfce8305 --- /dev/null +++ b/cdist/conf/type/__consul_watch_services/parameter/optional @@ -0,0 +1,3 @@ +datacenter +state +token diff --git a/cdist/conf/type/__consul_watch_services/parameter/required b/cdist/conf/type/__consul_watch_services/parameter/required new file mode 100644 index 00000000..64b916c1 --- /dev/null +++ b/cdist/conf/type/__consul_watch_services/parameter/required @@ -0,0 +1 @@ +handler diff --git a/docs/changelog b/docs/changelog index 9017f526..a9b64ca1 100644 --- a/docs/changelog +++ b/docs/changelog @@ -7,6 +7,20 @@ Changelog next: * New type __staged_file: Manage staged files * New type __config_file: Manage configuration files and run code on change + * New type __consul: install consul + * New type __consul_agent: manage the consul agent + * New type __consul_check: manages consul checks + * New type __consul_reload: reload consul + * New type __consul_service: manages consul services + * New type __consul_template: manage the consul-template service + * New type __consul_template_template: manage consul-template templates + * New type __consul_watch_checks: manages consul checks watches + * New type __consul_watch_event: manages consul event watches + * New type __consul_watch_key: manages consul key watches + * New type __consul_watch_keyprefix: manages consul keyprefix watches + * New type __consul_watch_nodes: manages consul nodes watches + * New type __consul_watch_service: manages consul service watches + * New type __consul_watch_services: manages consul services watches 3.1.11: * Type __start_on_boot: Support Ubuntu upstart