From 4a7823d9b5d804b9e50bb7c12d39f2493d8ec3fa Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 22 Jun 2016 23:54:58 +0200 Subject: [PATCH 1/7] new consul-template version Signed-off-by: Steven Armstrong --- cdist/conf/type/__consul_template/files/versions/0.15.0/cksum | 1 + cdist/conf/type/__consul_template/files/versions/0.15.0/source | 1 + 2 files changed, 2 insertions(+) create mode 100644 cdist/conf/type/__consul_template/files/versions/0.15.0/cksum create mode 100644 cdist/conf/type/__consul_template/files/versions/0.15.0/source diff --git a/cdist/conf/type/__consul_template/files/versions/0.15.0/cksum b/cdist/conf/type/__consul_template/files/versions/0.15.0/cksum new file mode 100644 index 00000000..426338bd --- /dev/null +++ b/cdist/conf/type/__consul_template/files/versions/0.15.0/cksum @@ -0,0 +1 @@ +2643547924 12487232 consul-template diff --git a/cdist/conf/type/__consul_template/files/versions/0.15.0/source b/cdist/conf/type/__consul_template/files/versions/0.15.0/source new file mode 100644 index 00000000..fdf1fccf --- /dev/null +++ b/cdist/conf/type/__consul_template/files/versions/0.15.0/source @@ -0,0 +1 @@ +https://releases.hashicorp.com/consul-template/0.15.0/consul-template_0.15.0_linux_amd64.zip From 1ed0d6bbe3eaf76f280aabc86dc629c71ab7be80 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 22 Jun 2016 23:55:20 +0200 Subject: [PATCH 2/7] source for old consul-template versions have changed Signed-off-by: Steven Armstrong --- cdist/conf/type/__consul_template/files/versions/0.10.0/source | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__consul_template/files/versions/0.10.0/source b/cdist/conf/type/__consul_template/files/versions/0.10.0/source index 7fa074b5..031b1155 100644 --- a/cdist/conf/type/__consul_template/files/versions/0.10.0/source +++ b/cdist/conf/type/__consul_template/files/versions/0.10.0/source @@ -1 +1 @@ -https://github.com/hashicorp/consul-template/releases/download/v0.10.0/consul-template_0.10.0_linux_amd64.tar.gz +https://releases.hashicorp.com/consul-template/0.10.0/consul-template_0.10.0_linux_amd64.zip From 96b49f4e9921f8468f2ff20a85ebcbc8b5d8a50e Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 22 Jun 2016 23:56:27 +0200 Subject: [PATCH 3/7] consul-template is no longer distributed as a tar. it is now a zip archive Signed-off-by: Steven Armstrong --- cdist/conf/type/__consul_template/manifest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__consul_template/manifest b/cdist/conf/type/__consul_template/manifest index cedcb413..83d2aae4 100755 --- a/cdist/conf/type/__consul_template/manifest +++ b/cdist/conf/type/__consul_template/manifest @@ -52,7 +52,7 @@ __staged_file /usr/local/bin/consul-template \ --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' \ + --prepare-command 'unzip -p "%s"' \ --state "$state" \ --group root \ --owner root \ From 75b32328b63624c717bccdef04349547c8054212 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 22 Jun 2016 23:56:57 +0200 Subject: [PATCH 4/7] use latest consul-template version by default Signed-off-by: Steven Armstrong --- cdist/conf/type/__consul_template/parameter/default/version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__consul_template/parameter/default/version b/cdist/conf/type/__consul_template/parameter/default/version index 78bc1abd..a5510516 100644 --- a/cdist/conf/type/__consul_template/parameter/default/version +++ b/cdist/conf/type/__consul_template/parameter/default/version @@ -1 +1 @@ -0.10.0 +0.15.0 From 6944998a193261a1083ce38b13282f6564e2877c Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 22 Jun 2016 23:57:25 +0200 Subject: [PATCH 5/7] add new --wait parameter for consul-template Signed-off-by: Steven Armstrong --- cdist/conf/type/__consul_template_template/man.rst | 11 ++++++++++- cdist/conf/type/__consul_template_template/manifest | 2 +- .../__consul_template_template/parameter/optional | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__consul_template_template/man.rst b/cdist/conf/type/__consul_template_template/man.rst index 20d0a619..6264f696 100644 --- a/cdist/conf/type/__consul_template_template/man.rst +++ b/cdist/conf/type/__consul_template_template/man.rst @@ -36,6 +36,14 @@ source-file state if this template is 'present' or 'absent'. Defaults to 'present'. +wait + The `minimum(:maximum)` time 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. + This is a numeric time with a unit suffix ("5s"). There is no default value. + The wait value for a template takes precedence over any globally-configured + wait. + EXAMPLES -------- @@ -51,6 +59,7 @@ EXAMPLES # upload a local file to the target and configure it __consul_template_template nginx \ + --wait '2s:6s' \ --source-file "$__manifest/files/nginx.ctmpl" \ --destination /etc/nginx/nginx.conf \ --command 'service nginx restart' @@ -65,5 +74,5 @@ SEE ALSO COPYING ------- -Copyright \(C) 2015 Steven Armstrong. Free use of this software is +Copyright \(C) 2015-2016 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 index c997a2c8..b832075d 100755 --- a/cdist/conf/type/__consul_template_template/manifest +++ b/cdist/conf/type/__consul_template_template/manifest @@ -55,7 +55,7 @@ for param in $(ls "$__object/parameter/"); do printf ' source = "%s"\n' "$destination" ;; - source|destination|command) + source|destination|command|wait) printf ' %s = "%s"\n' "$param" "$(cat "$__object/parameter/$param")" ;; *) diff --git a/cdist/conf/type/__consul_template_template/parameter/optional b/cdist/conf/type/__consul_template_template/parameter/optional index 229f6c89..3e55fbb7 100644 --- a/cdist/conf/type/__consul_template_template/parameter/optional +++ b/cdist/conf/type/__consul_template_template/parameter/optional @@ -2,3 +2,4 @@ command source source-file state +wait From ce26deb706ef5419cd9aeb2e543f235642a0e1ea Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 22 Jun 2016 23:58:14 +0200 Subject: [PATCH 6/7] add support for new check types Signed-off-by: Steven Armstrong --- cdist/conf/type/__consul_check/man.rst | 44 ++++++++++++++----- cdist/conf/type/__consul_check/manifest | 30 ++++++++----- .../type/__consul_check/parameter/optional | 8 ++++ 3 files changed, 61 insertions(+), 21 deletions(-) diff --git a/cdist/conf/type/__consul_check/man.rst b/cdist/conf/type/__consul_check/man.rst index 1de65358..e12d9ca8 100644 --- a/cdist/conf/type/__consul_check/man.rst +++ b/cdist/conf/type/__consul_check/man.rst @@ -20,18 +20,17 @@ None. OPTIONAL PARAMETERS ------------------- -interval - the interval in which the script given with --script should be run +docker-container-id + the id of the docker container to run -script - the shell command to run every --interval - -ttl - how long a check is considered healthy without being updated through the - HTTP interfave +http + the url to check id - Defaults to --name + The id of this check. + +interval + the interval in which the check should run name The name of this check. Defaults to __object_id @@ -39,9 +38,34 @@ name notes human readable description +script + the shell command to run + +service-id + the id of the service this check is bound to + +shell + the shell to run inside the docker container + state if this check is 'present' or 'absent'. Defaults to 'present'. +status + specify the initial state of this health check + +tcp + the host and port to check + +timeout + after how long to timeout checks which take to long + +token + ACL token to use for interacting with the catalog + +ttl + how long a TTL check is considered healthy without being updated through the + HTTP interface + EXAMPLES -------- @@ -67,5 +91,5 @@ SEE ALSO COPYING ------- -Copyright \(C) 2015 Steven Armstrong. Free use of this software is +Copyright \(C) 2015-2016 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 index 3004f319..658e2598 100755 --- a/cdist/conf/type/__consul_check/manifest +++ b/cdist/conf/type/__consul_check/manifest @@ -1,6 +1,6 @@ #!/bin/sh # -# 2015 Steven Armstrong (steven-cdist at armstrong.cc) +# 2015-2016 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -24,12 +24,24 @@ 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 +if [ -f "$__object/parameter/ttl" ]; then + for conflicts_ttl in 'docker-container-id' 'http' 'script' 'tcp' 'timeout'; do + if [ -f "$__object/parameter/${conflicts_ttl}" ]; then + echo "Can not use --ttl together with --${conflicts_ttl}." >&2 + exit 1 + fi + done fi -if [ -f "$__object/parameter/script" -a ! -f "$__object/parameter/interval" ]; then - echo "When using --script you must also define --interval" >&2 +if [ ! -f "$__object/parameter/interval" ]; then + for requires_interval in 'docker-id' 'http' 'script' 'tcp'; do + if [ -f "$__object/parameter/${requires_interval}" ]; then + echo "When using --${requires_interval} you must also define --interval." >&2 + exit 1 + fi + done +fi +if [ -f "$__object/parameter/docker-container-id" -a ! -f "$__object/parameter/script" ]; then + echo "When using --docker-container-id you must also define --script." >&2 exit 1 fi @@ -40,11 +52,7 @@ 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")" - ;; + state|name) continue ;; *) key="$(echo "$param" | tr '-' '_')" printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" diff --git a/cdist/conf/type/__consul_check/parameter/optional b/cdist/conf/type/__consul_check/parameter/optional index f6c3a6e4..0e392956 100644 --- a/cdist/conf/type/__consul_check/parameter/optional +++ b/cdist/conf/type/__consul_check/parameter/optional @@ -1,7 +1,15 @@ +docker-container-id +http id interval name notes script +service-id +shell state +status +tcp +timeout +token ttl From 13d315d718af95c5371b3a6f0a5485fb5bd1e499 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 7 Jul 2016 14:38:36 +0200 Subject: [PATCH 7/7] do not assume target_host is anything that can be used as a directory name Signed-off-by: Steven Armstrong --- cdist/exec/local.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/cdist/exec/local.py b/cdist/exec/local.py index c0554831..64593235 100644 --- a/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -29,6 +29,7 @@ import subprocess import shutil import logging import tempfile +import hashlib import cdist import cdist.message @@ -55,8 +56,10 @@ class Local(object): base_path_parent = base_path else: base_path_parent = tempfile.mkdtemp() - import atexit - atexit.register(lambda: shutil.rmtree(base_path_parent)) + # TODO: the below atexit hook nukes any debug info we would have + # if cdist exits with error. + #import atexit + #atexit.register(lambda: shutil.rmtree(base_path_parent)) self.hostdir = self._hostdir() self.base_path = os.path.join(base_path_parent, self.hostdir) @@ -89,11 +92,9 @@ class Local(object): return None def _hostdir(self): - if os.path.isabs(self.target_host): - hostdir = self.target_host[1:] - else: - hostdir = self.target_host - return hostdir + # Do not assume target_host is anything that can be used as a directory name. + # Instead use a hash, which is know to work as directory name. + return hashlib.md5(self.target_host.encode('utf-8')).hexdigest() def _init_log(self): self.log = logging.getLogger(self.target_host) @@ -227,7 +228,7 @@ class Local(object): def save_cache(self): - destination = os.path.join(self.cache_path, self.hostdir) + destination = os.path.join(self.cache_path, self.target_host) self.log.debug("Saving " + self.base_path + " to " + destination) try: