From 3c720640dd38e660fd7975cb3e8e471387efd3b1 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 24 Feb 2015 23:59:06 +0100 Subject: [PATCH] start working on supporting different versions of consul-template Signed-off-by: Steven Armstrong --- .../files/versions/0.6.5/cksum | 1 + .../files/versions/0.6.5/source | 1 + cdist/conf/type/__consul_template/man.text | 19 ++++++- cdist/conf/type/__consul_template/manifest | 51 ++++++++++++++----- .../parameter/default/install-to | 1 + .../__consul_template/parameter/default/state | 1 + .../parameter/default/version | 1 + .../type/__consul_template/parameter/optional | 3 ++ cdist/conf/type/__consul_template/todo | 3 ++ 9 files changed, 65 insertions(+), 16 deletions(-) create mode 100644 cdist/conf/type/__consul_template/files/versions/0.6.5/cksum create mode 100644 cdist/conf/type/__consul_template/files/versions/0.6.5/source create mode 100644 cdist/conf/type/__consul_template/parameter/default/install-to create mode 100644 cdist/conf/type/__consul_template/parameter/default/state create mode 100644 cdist/conf/type/__consul_template/parameter/default/version create mode 100644 cdist/conf/type/__consul_template/todo diff --git a/cdist/conf/type/__consul_template/files/versions/0.6.5/cksum b/cdist/conf/type/__consul_template/files/versions/0.6.5/cksum new file mode 100644 index 00000000..2dcac994 --- /dev/null +++ b/cdist/conf/type/__consul_template/files/versions/0.6.5/cksum @@ -0,0 +1 @@ +1356006333 8496656 consul-template diff --git a/cdist/conf/type/__consul_template/files/versions/0.6.5/source b/cdist/conf/type/__consul_template/files/versions/0.6.5/source new file mode 100644 index 00000000..09a1ce3a --- /dev/null +++ b/cdist/conf/type/__consul_template/files/versions/0.6.5/source @@ -0,0 +1 @@ +https://github.com/hashicorp/consul-template/releases/download/v0.6.5/consul-template_0.6.5_linux_amd64.tar.gz diff --git a/cdist/conf/type/__consul_template/man.text b/cdist/conf/type/__consul_template/man.text index 26afd4f1..66d04457 100644 --- a/cdist/conf/type/__consul_template/man.text +++ b/cdist/conf/type/__consul_template/man.text @@ -10,8 +10,11 @@ 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. +Downloads and installs the consul-template binary from +https://github.com/hashicorp/consul-template/releases/download/. +Generates a global config file and creates directory for per template config files. +Note that the consul-template binary is downloaded on the server (the machine running +cdist) and then deployed to the target host using the __file type. REQUIRED PARAMETERS @@ -28,14 +31,21 @@ batch-size:: consul:: the location of the Consul instance to query (may be an IP address or FQDN) with port. Defaults to 'localhost:8500'. +install-to:: + where to install the binary. Defaults to /usr/local/bin/consul-template 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. +state:: + either 'present' or 'absent'. Defaults to 'present' token:: the Consul API token. +version:: + which version of consul-template to install. See ./files/versions for a list of + supported versions. Defaults to the latest known version. 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 @@ -57,6 +67,11 @@ EXAMPLES __consul_template \ --consul consul.service.consul:8500 \ --retry 30s + +# specific version +__consul_template \ + --version 0.6.5 \ + --retry 30s -------------------------------------------------------------------------------- diff --git a/cdist/conf/type/__consul_template/manifest b/cdist/conf/type/__consul_template/manifest index dba7e68e..aeee35bf 100755 --- a/cdist/conf/type/__consul_template/manifest +++ b/cdist/conf/type/__consul_template/manifest @@ -24,7 +24,10 @@ os=$(cat "$__global/explorer/os") case "$os" in centos|redhat) # whitelist safeguard - : + service_onchange='service consul-template status >/dev/null && service consul-template reload || true' \ + ;; + archlinux) + service_onchange="systemctl status consul-template >/dev/null && systemctl reload consul-template || true" ;; *) echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 @@ -33,7 +36,30 @@ case "$os" in ;; esac -state="present" +versions_dir="$__type/files/versions" +version="$(cat "$__object/parameter/version")" +version_dir="$versions_dir/$version" + +if [ ! -d "$version_dir" ]; then + echo "Unknown consul-template version '$version'. Expected one of:" >&2 + ls "$versions_dir" >&2 + exit 1 +fi + +state="$(cat "$__object/parameter/state")" +install_to="$(cat "$__object/parameter/install-to")" + +__staged_file "$install_to" \ + --source "$(cat "$version_dir/source")" \ + --cksum "$(cat "$version_dir/cksum")" \ + --fetch-command 'curl -s -L "%s"' \ + --prepare-command 'tar -xzf "%s"; cat consul-template_*/consul-template' \ + --state "$state" \ + --group root \ + --owner root \ + --mode 755 + + conf_dir="/etc/consul-template/conf.d" conf_file="config.hcl" template_dir="/etc/consul-template/template" @@ -48,17 +74,6 @@ require="__directory/etc/consul-template" \ --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 @@ -82,7 +97,7 @@ 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' \ + --onchange "$service_onchange" \ --source - @@ -118,4 +133,12 @@ case "$os" in export require="__file/etc/init/${service}.conf" __start_on_boot "$service" --state "$state" ;; + archlinux) + __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" + __start_on_boot "$service" --state "$state" + ;; esac diff --git a/cdist/conf/type/__consul_template/parameter/default/install-to b/cdist/conf/type/__consul_template/parameter/default/install-to new file mode 100644 index 00000000..8bd33a0a --- /dev/null +++ b/cdist/conf/type/__consul_template/parameter/default/install-to @@ -0,0 +1 @@ +/usr/local/bin/consul-template diff --git a/cdist/conf/type/__consul_template/parameter/default/state b/cdist/conf/type/__consul_template/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__consul_template/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__consul_template/parameter/default/version b/cdist/conf/type/__consul_template/parameter/default/version new file mode 100644 index 00000000..ef5e4454 --- /dev/null +++ b/cdist/conf/type/__consul_template/parameter/default/version @@ -0,0 +1 @@ +0.6.5 diff --git a/cdist/conf/type/__consul_template/parameter/optional b/cdist/conf/type/__consul_template/parameter/optional index 34c277b9..73c39582 100644 --- a/cdist/conf/type/__consul_template/parameter/optional +++ b/cdist/conf/type/__consul_template/parameter/optional @@ -1,7 +1,10 @@ auth batch-size consul +install-to max-stale retry +state token +version wait diff --git a/cdist/conf/type/__consul_template/todo b/cdist/conf/type/__consul_template/todo new file mode 100644 index 00000000..c09e09ac --- /dev/null +++ b/cdist/conf/type/__consul_template/todo @@ -0,0 +1,3 @@ +- add support for --install-to in init-system files/templates +- add support for latest version 0.7.0 + - config file format has changed