From cf0ab2a5bdcd68e1804dd9270f55bd91bd5184e8 Mon Sep 17 00:00:00 2001 From: Kamila Souckova Date: Mon, 29 May 2017 16:23:24 +0200 Subject: [PATCH 01/12] new type: __daemontools_service --- .../conf/type/__daemontools_service/manifest | 31 +++++++++++++++++++ .../parameter/default/log-run | 1 + .../parameter/default/run | 0 .../parameter/default/run-file | 0 .../parameter/default/servicedir | 1 + .../__daemontools_service/parameter/optional | 4 +++ 6 files changed, 37 insertions(+) create mode 100644 cdist/conf/type/__daemontools_service/manifest create mode 100644 cdist/conf/type/__daemontools_service/parameter/default/log-run create mode 100644 cdist/conf/type/__daemontools_service/parameter/default/run create mode 100644 cdist/conf/type/__daemontools_service/parameter/default/run-file create mode 100644 cdist/conf/type/__daemontools_service/parameter/default/servicedir create mode 100644 cdist/conf/type/__daemontools_service/parameter/optional diff --git a/cdist/conf/type/__daemontools_service/manifest b/cdist/conf/type/__daemontools_service/manifest new file mode 100644 index 00000000..34f45545 --- /dev/null +++ b/cdist/conf/type/__daemontools_service/manifest @@ -0,0 +1,31 @@ +#!/bin/sh + +RUN_PREFIX="#!/bin/sh +exec 2>&1 +exec " # mind the space :D + +name=$__object_id +servicedir=$(cat "$__object/parameter/servicedir") +run=$(cat "$__object/parameter/run") +runfile=$(cat "$__object/parameter/run-file") +logrun=$(cat "$__object/parameter/log-run") + +badusage() { + echo "__daemontools_service/$__object_id: exactly one of --run, --run-file must be set" >&2 + exit 1 +} + +[ -z "$run$runfile" ] && badusage +[ -n "$run" ] && [ -n "$runfile" ] && badusage + +__directory $servicedir/$name/log/main --parents + +echo "$RUN_PREFIX$run" | require="__directory/$servicedir/$name/log/main" __config_file "$servicedir/$name/run" \ + --onchange "svc -t '$servicedir/$name' 2>/dev/null" \ + --mode 755 \ + --source "${runfile:--}" + +echo "$RUN_PREFIX$logrun" | require="__directory/$servicedir/$name/log/main" __config_file $servicedir/$name/log/run \ + --onchange "svc -t '$servicedir/$name/log' 2>/dev/null" \ + --mode 755 \ + --source "-" diff --git a/cdist/conf/type/__daemontools_service/parameter/default/log-run b/cdist/conf/type/__daemontools_service/parameter/default/log-run new file mode 100644 index 00000000..80d57a74 --- /dev/null +++ b/cdist/conf/type/__daemontools_service/parameter/default/log-run @@ -0,0 +1 @@ +multilog t ./main diff --git a/cdist/conf/type/__daemontools_service/parameter/default/run b/cdist/conf/type/__daemontools_service/parameter/default/run new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__daemontools_service/parameter/default/run-file b/cdist/conf/type/__daemontools_service/parameter/default/run-file new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__daemontools_service/parameter/default/servicedir b/cdist/conf/type/__daemontools_service/parameter/default/servicedir new file mode 100644 index 00000000..b74e27f6 --- /dev/null +++ b/cdist/conf/type/__daemontools_service/parameter/default/servicedir @@ -0,0 +1 @@ +/service diff --git a/cdist/conf/type/__daemontools_service/parameter/optional b/cdist/conf/type/__daemontools_service/parameter/optional new file mode 100644 index 00000000..7e54985f --- /dev/null +++ b/cdist/conf/type/__daemontools_service/parameter/optional @@ -0,0 +1,4 @@ +log-run +run +run-file +servicedir From 29bebc4af4944348e4c332b1acb6397e26a36e84 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Wed, 31 May 2017 09:55:33 +0200 Subject: [PATCH 02/12] Shorten ssh control path. On macos the path is too long due to long default TMP dir. --- cdist/config.py | 17 ++++++++++++----- docs/changelog | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cdist/config.py b/cdist/config.py index 6b57e7bf..c25c029b 100644 --- a/cdist/config.py +++ b/cdist/config.py @@ -27,6 +27,8 @@ import time import itertools import tempfile import socket +import atexit +import shutil import cdist import cdist.hostsource @@ -92,7 +94,6 @@ class Config(object): "failed: %s" % e)) args.manifest = initial_manifest_temp_path - import atexit atexit.register(lambda: os.remove(initial_manifest_temp_path)) # default remote cmd patterns @@ -176,8 +177,15 @@ class Config(object): " ".join(failed_hosts)) @classmethod - def _resolve_remote_cmds(cls, args, host_base_path): - control_path = os.path.join(host_base_path, "ssh-control-path") + def _resolve_ssh_control_path(cls): + base_path = tempfile.mkdtemp() + control_path = os.path.join(base_path, "s") + atexit.register(lambda: shutil.rmtree(base_path)) + return control_path + + @classmethod + def _resolve_remote_cmds(cls, args): + control_path = cls._resolve_ssh_control_path() # If we constructed patterns for remote commands then there is # placeholder for ssh ControlPath, format it and we have unique # ControlPath for each host. @@ -200,8 +208,7 @@ class Config(object): log = logging.getLogger(host) try: - remote_exec, remote_copy = cls._resolve_remote_cmds( - args, host_base_path) + remote_exec, remote_copy = cls._resolve_remote_cmds(args) log.debug("remote_exec for host \"{}\": {}".format( host, remote_exec)) log.debug("remote_copy for host \"{}\": {}".format( diff --git a/docs/changelog b/docs/changelog index 524257a7..be0ed2e3 100644 --- a/docs/changelog +++ b/docs/changelog @@ -6,6 +6,7 @@ next: * Type __go_get: Install go packages using go get (Kamila Součková) * Explorer kernel_name: uname -s (Kamila Součková) * Type __sysctl: Add devuan support (Nico Schottelius) + * Core: Shorten ssh control path (Darko Poljak) 4.4.2: 2017-03-08 * Core: Fix suppression of manifests' outputs (Darko Poljak) From 5ec8ac90d9f8e5dd2cafb003e86db9f804863c8a Mon Sep 17 00:00:00 2001 From: Kamila Souckova Date: Wed, 31 May 2017 18:21:24 +0200 Subject: [PATCH 03/12] consul: add http check; add new version --- cdist/conf/type/__consul/files/versions/0.8.1/cksum | 1 + cdist/conf/type/__consul/files/versions/0.8.1/source | 1 + cdist/conf/type/__consul/manifest | 2 +- cdist/conf/type/__consul_agent/manifest | 12 ++++++++---- cdist/conf/type/__consul_service/manifest | 10 ++++++++++ cdist/conf/type/__consul_service/parameter/optional | 1 + 6 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 cdist/conf/type/__consul/files/versions/0.8.1/cksum create mode 100644 cdist/conf/type/__consul/files/versions/0.8.1/source diff --git a/cdist/conf/type/__consul/files/versions/0.8.1/cksum b/cdist/conf/type/__consul/files/versions/0.8.1/cksum new file mode 100644 index 00000000..9125cc8f --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.8.1/cksum @@ -0,0 +1 @@ +283033689 36101209 consul diff --git a/cdist/conf/type/__consul/files/versions/0.8.1/source b/cdist/conf/type/__consul/files/versions/0.8.1/source new file mode 100644 index 00000000..92386c7c --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.8.1/source @@ -0,0 +1 @@ +https://releases.hashicorp.com/consul/0.8.1/consul_0.8.1_linux_amd64.zip diff --git a/cdist/conf/type/__consul/manifest b/cdist/conf/type/__consul/manifest index b16c5749..7d0e73c5 100755 --- a/cdist/conf/type/__consul/manifest +++ b/cdist/conf/type/__consul/manifest @@ -23,7 +23,7 @@ os=$(cat "$__global/explorer/os") case "$os" in - scientific|centos|redhat|ubuntu|debian|archlinux|gentoo) + scientific|centos|redhat|ubuntu|debian|devuan|archlinux|gentoo) # any linux should work : ;; diff --git a/cdist/conf/type/__consul_agent/manifest b/cdist/conf/type/__consul_agent/manifest index 07bf3b26..64efd366 100755 --- a/cdist/conf/type/__consul_agent/manifest +++ b/cdist/conf/type/__consul_agent/manifest @@ -23,7 +23,7 @@ os=$(cat "$__global/explorer/os") case "$os" in - scientific|centos|debian|redhat|ubuntu) + scientific|centos|debian|devuan|redhat|ubuntu) # whitelist safeguard : ;; @@ -215,7 +215,11 @@ case "$os" in esac ;; - ubuntu) - init_upstart - ;; + devuan) + init_sysvinit debian + ;; + + ubuntu) + init_upstart + ;; esac diff --git a/cdist/conf/type/__consul_service/manifest b/cdist/conf/type/__consul_service/manifest index 9ba64141..4f52d542 100755 --- a/cdist/conf/type/__consul_service/manifest +++ b/cdist/conf/type/__consul_service/manifest @@ -32,6 +32,10 @@ if [ -f "$__object/parameter/check-script" -a ! -f "$__object/parameter/check-in echo "When using --check-script you must also define --check-interval" >&2 exit 1 fi +if [ -f "$__object/parameter/check-http" -a ! -f "$__object/parameter/check-interval" ]; then + echo "When using --check-http you must also define --check-interval" >&2 + exit 1 +fi # Generate json config file ( @@ -52,6 +56,12 @@ for param in $(ls "$__object/parameter/"); do printf ' "ttl": "%s"\n' "$(cat "$__object/parameter/check-ttl")" printf ' }\n' ;; + check-http) + printf ' ,"check": {\n' + printf ' "http": "%s"\n' "$(cat "$__object/parameter/check-http")" + printf ' ,"interval": "%s"\n' "$(cat "$__object/parameter/check-interval")" + printf ' }\n' + ;; tag) # create json array from newline delimited file tags="$(awk '{printf "\""$1"\","}' "$__object/parameter/tag")" diff --git a/cdist/conf/type/__consul_service/parameter/optional b/cdist/conf/type/__consul_service/parameter/optional index 496e31a3..2e3e8b63 100644 --- a/cdist/conf/type/__consul_service/parameter/optional +++ b/cdist/conf/type/__consul_service/parameter/optional @@ -1,3 +1,4 @@ +check-http check-interval check-script check-ttl From 06e1ddcf4712bd6ad6c759ccc43fdea2a0cb8bfe Mon Sep 17 00:00:00 2001 From: Kamila Souckova Date: Wed, 31 May 2017 18:57:21 +0200 Subject: [PATCH 04/12] __consul_agent: mention http-check in man page --- cdist/conf/type/__consul_service/man.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cdist/conf/type/__consul_service/man.rst b/cdist/conf/type/__consul_service/man.rst index bcfe4067..510be3d5 100644 --- a/cdist/conf/type/__consul_service/man.rst +++ b/cdist/conf/type/__consul_service/man.rst @@ -24,6 +24,9 @@ OPTIONAL PARAMETERS check-interval the interval in which the script given with --check-script should be run +check-http + the URL to check for HTTP 200-ish status every --check-interval + check-script the shell command to run every --check-interval From 0b37c79bf4cdca681472a9d4eca5f50aa339c430 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Thu, 1 Jun 2017 09:03:42 +0200 Subject: [PATCH 05/12] Update changelog --- docs/changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog b/docs/changelog index be0ed2e3..db0284a7 100644 --- a/docs/changelog +++ b/docs/changelog @@ -7,6 +7,7 @@ next: * Explorer kernel_name: uname -s (Kamila Součková) * Type __sysctl: Add devuan support (Nico Schottelius) * Core: Shorten ssh control path (Darko Poljak) + * Type __consul: Add new version and add http check (Kamila Součková) 4.4.2: 2017-03-08 * Core: Fix suppression of manifests' outputs (Darko Poljak) From d30103e9d2ea55013517ebd25029a5ab7292c6b5 Mon Sep 17 00:00:00 2001 From: Kamila Souckova Date: Thu, 1 Jun 2017 17:43:43 +0200 Subject: [PATCH 06/12] __daemontools*: add/improve; + add man pages --- .../type/__daemontools/files/init.d-svscan | 63 +++++++++++++++++++ cdist/conf/type/__daemontools/man.rst | 42 +++++++++++++ cdist/conf/type/__daemontools/manifest | 20 ++++++ .../conf/type/__daemontools/parameter/boolean | 1 + .../parameter/default/from-package | 1 + .../parameter/default/install-init-script | 0 .../type/__daemontools/parameter/optional | 1 + cdist/conf/type/__daemontools/singleton | 0 .../type/__daemontools_service/explorer/svc | 1 + cdist/conf/type/__daemontools_service/man.rst | 63 +++++++++++++++++++ .../conf/type/__daemontools_service/manifest | 7 +++ 11 files changed, 199 insertions(+) create mode 100644 cdist/conf/type/__daemontools/files/init.d-svscan create mode 100644 cdist/conf/type/__daemontools/man.rst create mode 100644 cdist/conf/type/__daemontools/manifest create mode 100644 cdist/conf/type/__daemontools/parameter/boolean create mode 100644 cdist/conf/type/__daemontools/parameter/default/from-package create mode 100644 cdist/conf/type/__daemontools/parameter/default/install-init-script create mode 100644 cdist/conf/type/__daemontools/parameter/optional create mode 100644 cdist/conf/type/__daemontools/singleton create mode 100644 cdist/conf/type/__daemontools_service/explorer/svc create mode 100644 cdist/conf/type/__daemontools_service/man.rst diff --git a/cdist/conf/type/__daemontools/files/init.d-svscan b/cdist/conf/type/__daemontools/files/init.d-svscan new file mode 100644 index 00000000..127dfdb3 --- /dev/null +++ b/cdist/conf/type/__daemontools/files/init.d-svscan @@ -0,0 +1,63 @@ +#!/bin/bash +### BEGIN INIT INFO +# Provides: svscan +# Required-Start: +# Required-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: svscan +# Description: djb svscan +### END INIT INFO +# from https://gist.githubusercontent.com/pacojp/5766990/raw/2ed009ab19515afc9e58291b636d673c5ca864b3/init.d.svscan +# written by Adam McKenna +# edited by Kamila Součková + +export PATH=$PATH:/usr/local/bin + +l=/var/log/svscan + +if [ ! -d $l ]; then + mkdir $l + chown daemon $l +fi + +case "$1" in + start) + echo -n "Starting daemontools: " + if [ ! `pidof svscan` ]; then + echo -n "svscan " + env - PATH="$PATH" svscan /service 2>&1 | setuidgid daemon multilog t /var/log/svscan & + echo "." + else + echo "already running." + fi + ;; + stop) + echo -n "Stopping daemontools: " + if [ `pidof svscan` ]; then + echo -n "svscan" + while [ `pidof svscan` ]; do + kill `pidof svscan` + echo -n "." + done + fi + echo -n " services" + for i in `ls -d /service/*`; do + svc -dx $i + echo -n "." + done + echo -n " logging " + for i in `ls -d /service/*/log`; do + svc -dx $i + echo -n "." + done + echo "" + ;; + restart|force-reload) + $0 stop + $0 start + ;; + *) + echo 'Usage: /etc/init.d/svscan {start|stop|restart|force-reload}' + exit 1 +esac diff --git a/cdist/conf/type/__daemontools/man.rst b/cdist/conf/type/__daemontools/man.rst new file mode 100644 index 00000000..62dc5681 --- /dev/null +++ b/cdist/conf/type/__daemontools/man.rst @@ -0,0 +1,42 @@ +cdist-type__daemontools(7) +========================== + +NAME +---- +cdist-type__daemontools - Install daemontools + + +DESCRIPTION +----------- +Install djb daemontools and (optionally) an init script. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +from-package + Package to install. Must be compatible with the original daemontools. Example: daemontools-encore. Default: daemontools. + +BOOLEAN PARAMETERS +------------------ +install-init-script + Add an init script and set it to start on boot. Default yes. + +EXAMPLES +-------- + +.. code-block:: sh + + __daemontools --from-package daemontools-encore # if you prefer + +SEE ALSO +-------- +cdist-type__daemontools_service + +AUTHORS +------- +Kamila Součková diff --git a/cdist/conf/type/__daemontools/manifest b/cdist/conf/type/__daemontools/manifest new file mode 100644 index 00000000..550994a7 --- /dev/null +++ b/cdist/conf/type/__daemontools/manifest @@ -0,0 +1,20 @@ +#!/bin/sh + +pkg=$(cat "$__object/parameter/from-package") + +__package $pkg + +if [ -f "$__object/parameter/install-init-script" ]; then + init=$(cat "$__global/explorer/init") + case $init in + init) + __config_file /etc/init.d/svscan --mode 755 --source "$__type/files/init.d-svscan" + require="$require __config_file/etc/init.d/svscan" __start_on_boot svscan + require="$require __start_on_boot/svscan" __process svscan --start 'service svscan start' + ;; + *) + echo "Your init system ($init) is not supported by this type. Submit a patch at github.com/ungleich/cdist!" + exit 1 + ;; + esac +fi diff --git a/cdist/conf/type/__daemontools/parameter/boolean b/cdist/conf/type/__daemontools/parameter/boolean new file mode 100644 index 00000000..99a1cefd --- /dev/null +++ b/cdist/conf/type/__daemontools/parameter/boolean @@ -0,0 +1 @@ +install-init-script diff --git a/cdist/conf/type/__daemontools/parameter/default/from-package b/cdist/conf/type/__daemontools/parameter/default/from-package new file mode 100644 index 00000000..598dd40a --- /dev/null +++ b/cdist/conf/type/__daemontools/parameter/default/from-package @@ -0,0 +1 @@ +daemontools diff --git a/cdist/conf/type/__daemontools/parameter/default/install-init-script b/cdist/conf/type/__daemontools/parameter/default/install-init-script new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__daemontools/parameter/optional b/cdist/conf/type/__daemontools/parameter/optional new file mode 100644 index 00000000..8eca305b --- /dev/null +++ b/cdist/conf/type/__daemontools/parameter/optional @@ -0,0 +1 @@ +from-package diff --git a/cdist/conf/type/__daemontools/singleton b/cdist/conf/type/__daemontools/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__daemontools_service/explorer/svc b/cdist/conf/type/__daemontools_service/explorer/svc new file mode 100644 index 00000000..4a867485 --- /dev/null +++ b/cdist/conf/type/__daemontools_service/explorer/svc @@ -0,0 +1 @@ +command -v svc diff --git a/cdist/conf/type/__daemontools_service/man.rst b/cdist/conf/type/__daemontools_service/man.rst new file mode 100644 index 00000000..aa15a826 --- /dev/null +++ b/cdist/conf/type/__daemontools_service/man.rst @@ -0,0 +1,63 @@ +cdist-type__daemontools_service(7) +================================== + +NAME +---- +cdist-type__daemontools_service - Create a daemontools-compatible service dir. + + +DESCRIPTION +----------- +Create a directory structure compatible with daemontools-like service management. + +Note that svc must be present on the target system. + +The object ID will be used as the service name. + +REQUIRED PARAMETERS +------------------- +None. + +OPTIONAL PARAMETERS +------------------- +run + Command to run. exec-ing and stderr redirection will be added. One of run, run-file must be specified. + + Example: `my-program` + +run-file + File to save as /run. One of run, run-file must be specified. + + Example: +.. code-block:: sh + #!/bin/sh + exec 2>&1 + exec my_program + + +log-run + Command to run for log consumption. Default: `multilog t ./main` + +servicedir + Directory to install into. Default: `/service` + +BOOLEAN PARAMETERS +------------------ +None. + +EXAMPLES +-------- + +.. code-block:: sh + + require="__daemontools" __daemontools_service prometheus --run "setuidgid prometheus $GOBIN/prometheus $FLAGS" + + +SEE ALSO +-------- +cdist-type__daemontools + + +AUTHORS +------- +Kamila Součková diff --git a/cdist/conf/type/__daemontools_service/manifest b/cdist/conf/type/__daemontools_service/manifest index 34f45545..175066af 100644 --- a/cdist/conf/type/__daemontools_service/manifest +++ b/cdist/conf/type/__daemontools_service/manifest @@ -10,6 +10,13 @@ run=$(cat "$__object/parameter/run") runfile=$(cat "$__object/parameter/run-file") logrun=$(cat "$__object/parameter/log-run") +svc=$(cat "$__type/explorer/svc") + +if [ -z "$svc" ]; then + echo "svc not found! Install daemontools first: see __daemontools" + exit 1 +fi + badusage() { echo "__daemontools_service/$__object_id: exactly one of --run, --run-file must be set" >&2 exit 1 From 5ac324cd91c12c088c531f69661f076421959e40 Mon Sep 17 00:00:00 2001 From: Kamila Souckova Date: Thu, 1 Jun 2017 22:26:18 +0200 Subject: [PATCH 07/12] sacrifice to the evil manpage demons --- cdist/conf/type/__daemontools/man.rst | 9 ++++++++- cdist/conf/type/__daemontools_service/man.rst | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__daemontools/man.rst b/cdist/conf/type/__daemontools/man.rst index 62dc5681..2e012cb5 100644 --- a/cdist/conf/type/__daemontools/man.rst +++ b/cdist/conf/type/__daemontools/man.rst @@ -35,8 +35,15 @@ EXAMPLES SEE ALSO -------- -cdist-type__daemontools_service +:strong:`cdist-type__daemontools_service`\ (7) AUTHORS ------- Kamila Součková + +COPYING +------- +Copyright \(C) 2017 Kamila Součková. 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. diff --git a/cdist/conf/type/__daemontools_service/man.rst b/cdist/conf/type/__daemontools_service/man.rst index aa15a826..0d75917e 100644 --- a/cdist/conf/type/__daemontools_service/man.rst +++ b/cdist/conf/type/__daemontools_service/man.rst @@ -55,9 +55,16 @@ EXAMPLES SEE ALSO -------- -cdist-type__daemontools +:strong:`cdist-type__daemontools`\ (7) AUTHORS ------- Kamila Součková + +COPYING +------- +Copyright \(C) 2017 Kamila Součková. 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. From c16277bb8fc36f207fdabc533ce01406ff609188 Mon Sep 17 00:00:00 2001 From: Kamila Souckova Date: Thu, 1 Jun 2017 22:55:58 +0200 Subject: [PATCH 08/12] =?UTF-8?q?manpage=20d=C3=A6mons=20won't=20stop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cdist/conf/type/__daemontools_service/man.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/cdist/conf/type/__daemontools_service/man.rst b/cdist/conf/type/__daemontools_service/man.rst index 0d75917e..66360361 100644 --- a/cdist/conf/type/__daemontools_service/man.rst +++ b/cdist/conf/type/__daemontools_service/man.rst @@ -29,6 +29,7 @@ run-file File to save as /run. One of run, run-file must be specified. Example: + .. code-block:: sh #!/bin/sh exec 2>&1 From 42bc5e28b90d4143c8f7318773bd601f8b54f3c7 Mon Sep 17 00:00:00 2001 From: Kamila Souckova Date: Thu, 1 Jun 2017 23:01:03 +0200 Subject: [PATCH 09/12] WHY can't I write a man page? --- cdist/conf/type/__daemontools_service/man.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/cdist/conf/type/__daemontools_service/man.rst b/cdist/conf/type/__daemontools_service/man.rst index 66360361..ec1d20ff 100644 --- a/cdist/conf/type/__daemontools_service/man.rst +++ b/cdist/conf/type/__daemontools_service/man.rst @@ -31,6 +31,7 @@ run-file Example: .. code-block:: sh + #!/bin/sh exec 2>&1 exec my_program From 8d5e20757778c1f7d27f2f188d5584aabda51a06 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Thu, 1 Jun 2017 23:08:25 +0200 Subject: [PATCH 10/12] Update changelog --- docs/changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog b/docs/changelog index db0284a7..e691145c 100644 --- a/docs/changelog +++ b/docs/changelog @@ -8,6 +8,7 @@ next: * Type __sysctl: Add devuan support (Nico Schottelius) * Core: Shorten ssh control path (Darko Poljak) * Type __consul: Add new version and add http check (Kamila Součková) + * New types: __daemontools and __daemontools_service (Kamila Součková) 4.4.2: 2017-03-08 * Core: Fix suppression of manifests' outputs (Darko Poljak) From 2272539c16e594a3c4705b9aa4466b42f680d716 Mon Sep 17 00:00:00 2001 From: Kamila Souckova Date: Thu, 1 Jun 2017 23:52:23 +0200 Subject: [PATCH 11/12] is it Christmas today? So many new awesome types! --- .../type/__prometheus_alertmanager/man.rst | 66 ++++++++++++++++ .../type/__prometheus_alertmanager/manifest | 39 ++++++++++ .../parameter/default/storage-path | 1 + .../parameter/optional | 1 + .../parameter/required | 2 + .../type/__prometheus_alertmanager/singleton | 0 cdist/conf/type/__prometheus_server/man.rst | 78 +++++++++++++++++++ cdist/conf/type/__prometheus_server/manifest | 57 ++++++++++++++ .../__prometheus_server/parameter/boolean | 1 + .../parameter/default/retention-days | 1 + .../parameter/default/rule-files | 0 .../parameter/default/storage-path | 1 + .../parameter/default/target-heap-size | 1 + .../parameter/default/with-daemontools | 0 .../__prometheus_server/parameter/optional | 4 + .../__prometheus_server/parameter/required | 3 + cdist/conf/type/__prometheus_server/singleton | 0 17 files changed, 255 insertions(+) create mode 100644 cdist/conf/type/__prometheus_alertmanager/man.rst create mode 100644 cdist/conf/type/__prometheus_alertmanager/manifest create mode 100644 cdist/conf/type/__prometheus_alertmanager/parameter/default/storage-path create mode 100644 cdist/conf/type/__prometheus_alertmanager/parameter/optional create mode 100644 cdist/conf/type/__prometheus_alertmanager/parameter/required create mode 100644 cdist/conf/type/__prometheus_alertmanager/singleton create mode 100644 cdist/conf/type/__prometheus_server/man.rst create mode 100644 cdist/conf/type/__prometheus_server/manifest create mode 100644 cdist/conf/type/__prometheus_server/parameter/boolean create mode 100644 cdist/conf/type/__prometheus_server/parameter/default/retention-days create mode 100644 cdist/conf/type/__prometheus_server/parameter/default/rule-files create mode 100644 cdist/conf/type/__prometheus_server/parameter/default/storage-path create mode 100644 cdist/conf/type/__prometheus_server/parameter/default/target-heap-size create mode 100644 cdist/conf/type/__prometheus_server/parameter/default/with-daemontools create mode 100644 cdist/conf/type/__prometheus_server/parameter/optional create mode 100644 cdist/conf/type/__prometheus_server/parameter/required create mode 100644 cdist/conf/type/__prometheus_server/singleton diff --git a/cdist/conf/type/__prometheus_alertmanager/man.rst b/cdist/conf/type/__prometheus_alertmanager/man.rst new file mode 100644 index 00000000..f218254e --- /dev/null +++ b/cdist/conf/type/__prometheus_alertmanager/man.rst @@ -0,0 +1,66 @@ +cdist-type__prometheus_alertmanager(7) +====================================== + +NAME +---- +cdist-type__prometheus_alertmanager - install Alertmanager + + +DESCRIPTION +----------- +Install and configure Prometheus Alertmanager (https://prometheus.io/docs/alerting/alertmanager/). + + +REQUIRED PARAMETERS +------------------- +config + Alertmanager configuration file. It will be saved as /etc/alertmanager/alertmanager.yml on the target. +listen-address + Passed as web.listen-address. + + +OPTIONAL PARAMETERS +------------------- +storage-path + Where to put data. Default: /data/alertmanager. (Directory will be created if needed.) + + +BOOLEAN PARAMETERS +------------------ +with-daemontools + Create a daemontools service directory under /service/prometheus. Default: yes. + Note: If you do not use this, Alertmanager will not be launched, and will not reload config on change. + If you use this, daemontools (or something compatible) must be installed. + + +EXAMPLES +-------- + +.. code-block:: sh + + ALERTPORT=9093 + + __daemontools + __golang_from_vendor --version 1.8.1 # required for prometheus and many exporters + + require="__daemontools __golang_from_vendor" __prometheus_alertmanager \ + --config "$__manifest/files/alertmanager.yml" \ + --storage-path /data/alertmanager \ + --listen-address "[::]:$ALERTPORT" + + +SEE ALSO +-------- +:strong:`cdist-type__prometheus_server`\ (7), :strong:`cdist-type__daemontools`\ (7), +Prometheus alerting documentation: https://prometheus.io/docs/alerting/overview/ + +AUTHORS +------- +Kamila Součková + +COPYING +------- +Copyright \(C) 2017 Kamila Součková. 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. diff --git a/cdist/conf/type/__prometheus_alertmanager/manifest b/cdist/conf/type/__prometheus_alertmanager/manifest new file mode 100644 index 00000000..61ac2d20 --- /dev/null +++ b/cdist/conf/type/__prometheus_alertmanager/manifest @@ -0,0 +1,39 @@ +#!/bin/sh + +GOBIN=/opt/gocode/bin # where to find go binaries +CONF_DIR=/etc/prometheus +LOGLEVEL=info +CONF=$CONF_DIR/alertmanager.yml + +### Prometheus server ####################################################### + +config="$(cat "$__object/parameter/config")" +storage_path="$(cat "$__object/parameter/storage-path")" +listen_address="$(cat "$__object/parameter/listen-address")" + +ONCHANGE="" +if [ -f "$__object/parameter/with-daemontools" ]; then + __daemontools_service prometheus --run "setuidgid prometheus $GOBIN/prometheus $REAL_FLAGS" + ONCHANGE="svc -h /service/prometheus" +fi + +FLAGS="config.file '$CONF' +storage.path '$storage_path' +web.listen-address '$listen_address' +log.level $LOGLEVEL" + +REAL_FLAGS="$(echo "$FLAGS" | sed -nE 's/^([^#]+).*/ --\1 \\/p')" + +__go_get github.com/prometheus/alertmanager/cmd/... + +__user prometheus --system +__directory "$storage_path" --owner prometheus +__directory "$CONF_DIR" --owner prometheus + +__daemontools_service alertmanager --run "setuidgid prometheus $GOBIN/alertmanager $REAL_FLAGS" + +require="$require __directory/$storage_path" \ +__config_file $CONF \ + --source $config \ + --group prometheus --mode 640 \ + --onchange "$ONCHANGE" diff --git a/cdist/conf/type/__prometheus_alertmanager/parameter/default/storage-path b/cdist/conf/type/__prometheus_alertmanager/parameter/default/storage-path new file mode 100644 index 00000000..4f3e7559 --- /dev/null +++ b/cdist/conf/type/__prometheus_alertmanager/parameter/default/storage-path @@ -0,0 +1 @@ +/data/alertmanager diff --git a/cdist/conf/type/__prometheus_alertmanager/parameter/optional b/cdist/conf/type/__prometheus_alertmanager/parameter/optional new file mode 100644 index 00000000..f99d0d37 --- /dev/null +++ b/cdist/conf/type/__prometheus_alertmanager/parameter/optional @@ -0,0 +1 @@ +storage-path diff --git a/cdist/conf/type/__prometheus_alertmanager/parameter/required b/cdist/conf/type/__prometheus_alertmanager/parameter/required new file mode 100644 index 00000000..02cb49d0 --- /dev/null +++ b/cdist/conf/type/__prometheus_alertmanager/parameter/required @@ -0,0 +1,2 @@ +config +listen-address diff --git a/cdist/conf/type/__prometheus_alertmanager/singleton b/cdist/conf/type/__prometheus_alertmanager/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__prometheus_server/man.rst b/cdist/conf/type/__prometheus_server/man.rst new file mode 100644 index 00000000..c03a71d5 --- /dev/null +++ b/cdist/conf/type/__prometheus_server/man.rst @@ -0,0 +1,78 @@ +cdist-type__prometheus_server(7) +================================ + +NAME +---- +cdist-type__prometheus_server - install Prometheus + + +DESCRIPTION +----------- +Install and configure Prometheus (https://prometheus.io/). + + +REQUIRED PARAMETERS +------------------- +config + Prometheus configuration file. It will be saved as /etc/prometheus/prometheus.yml on the target. +listen-address + Passed as web.listen-address. +alertmanager-url + Passed as alertmanager.url + + +OPTIONAL PARAMETERS +------------------- +retention-days + How long to keep data. Default: 30 +rule-files + Path to rule files. They will be installed under /etc/prometheus/. You need to include `rule_files: [/etc/prometheus/]` in the config file if you use this. +storage-path + Where to put data. Default: /data/prometheus. (Directory will be created if needed.) +target-heap-size + Passed as storage.local.target-heap-size. Default: 1/2 of RAM. + + +BOOLEAN PARAMETERS +------------------ +with-daemontools + Create a daemontools service directory under /service/prometheus. Default: yes. + Note: If you do not use this, Prometheus will not be launched, and will not reload config on change. + If you use this, daemontools (or something compatible) must be installed. + + +EXAMPLES +-------- + +.. code-block:: sh + + PROMPORT=9090 + ALERTPORT=9093 + + __daemontools + __golang_from_vendor --version 1.8.1 # required for prometheus and many exporters + + require="__daemontools __golang_from_vendor" __prometheus_server \ + --config "$__manifest/files/prometheus.yml" \ + --retention-days 14 \ + --storage-path /data/prometheus \ + --listen-address "[::]:$PROMPORT" \ + --rule-files "$__manifest/files/*.rules" \ + --alertmanager-url "http://monitoring1.node.consul:$ALERTPORT,http://monitoring2.node.consul:$ALERTPORT" + + +SEE ALSO +-------- +:strong:`cdist-type__prometheus_alertmanager`\ (7), :strong:`cdist-type__daemontools`\ (7), +Prometheus documentation: https://prometheus.io/docs/introduction/overview/ + +AUTHORS +------- +Kamila Součková + +COPYING +------- +Copyright \(C) 2017 Kamila Součková. 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. diff --git a/cdist/conf/type/__prometheus_server/manifest b/cdist/conf/type/__prometheus_server/manifest new file mode 100644 index 00000000..dd81701d --- /dev/null +++ b/cdist/conf/type/__prometheus_server/manifest @@ -0,0 +1,57 @@ +#!/bin/sh + +GOBIN=/opt/gocode/bin # where to find go binaries +CONF_DIR=/etc/prometheus +CONF=$CONF_DIR/prometheus.yml +LOGLEVEL=info + +config="$(cat "$__object/parameter/config")" +retention_days="$(cat "$__object/parameter/retention-days")" +storage_path="$(cat "$__object/parameter/storage-path")" +listen_address="$(cat "$__object/parameter/listen-address")" +alertmanager_url="$(cat "$__object/parameter/alertmanager-url")" +target_heap_size="$(cat "$__object/parameter/target-heap-size")" +rule_files="$(cat "$__object/parameter/rule-files")" + +# explorer in kB => convert; by default we go with 1/2 RAM +[ "$target_heap_size" = "auto" ] && target_heap_size=$(($(cat $__global/explorer/memory)*1024/2)) + +ONCHANGE="" +if [ -f "$__object/parameter/with-daemontools" ]; then + __daemontools_service prometheus --run "setuidgid prometheus $GOBIN/prometheus $REAL_FLAGS" + ONCHANGE="&& svc -h /service/prometheus" +fi + +FLAGS="config.file '$CONF' +storage.local.path '$storage_path' +storage.local.target-heap-size $(($target_heap_size)) # in bytes; should be 2/3 of available memory because it may be hungry +storage.local.retention $(($retention_days*24))h # golang doesn't have days :D +web.listen-address '$listen_address' +alertmanager.url '$alertmanager_url' +log.level $LOGLEVEL" + +REAL_FLAGS="$(echo "$FLAGS" | sed -nE 's/^([^#]+).*/ --\1 \\/p')" + +__go_get github.com/prometheus/prometheus/cmd/... + +__user prometheus --system +__directory "$storage_path" --owner prometheus +__directory "$CONF_DIR" --owner prometheus + + + +require="$require __directory/$storage_path" \ +__config_file $CONF \ + --source $config \ + --group prometheus --mode 640 \ + --onchange "$GOBIN/promtool check-config $CONF $ONCHANGE" + +for file in $rule_files; do + dest=$CONF_DIR/$(basename $file) + require="$require __directory/$CONF_DIR" \ + __config_file "$dest" \ + --source "$file" \ + --owner prometheus \ + --onchange "$GOBIN/promtool check-rules '$dest' $ONCHANGE" +done + diff --git a/cdist/conf/type/__prometheus_server/parameter/boolean b/cdist/conf/type/__prometheus_server/parameter/boolean new file mode 100644 index 00000000..de4eefdd --- /dev/null +++ b/cdist/conf/type/__prometheus_server/parameter/boolean @@ -0,0 +1 @@ +with-daemontools diff --git a/cdist/conf/type/__prometheus_server/parameter/default/retention-days b/cdist/conf/type/__prometheus_server/parameter/default/retention-days new file mode 100644 index 00000000..64bb6b74 --- /dev/null +++ b/cdist/conf/type/__prometheus_server/parameter/default/retention-days @@ -0,0 +1 @@ +30 diff --git a/cdist/conf/type/__prometheus_server/parameter/default/rule-files b/cdist/conf/type/__prometheus_server/parameter/default/rule-files new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__prometheus_server/parameter/default/storage-path b/cdist/conf/type/__prometheus_server/parameter/default/storage-path new file mode 100644 index 00000000..fc05f8f3 --- /dev/null +++ b/cdist/conf/type/__prometheus_server/parameter/default/storage-path @@ -0,0 +1 @@ +/data/prometheus diff --git a/cdist/conf/type/__prometheus_server/parameter/default/target-heap-size b/cdist/conf/type/__prometheus_server/parameter/default/target-heap-size new file mode 100644 index 00000000..865faf10 --- /dev/null +++ b/cdist/conf/type/__prometheus_server/parameter/default/target-heap-size @@ -0,0 +1 @@ +auto diff --git a/cdist/conf/type/__prometheus_server/parameter/default/with-daemontools b/cdist/conf/type/__prometheus_server/parameter/default/with-daemontools new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__prometheus_server/parameter/optional b/cdist/conf/type/__prometheus_server/parameter/optional new file mode 100644 index 00000000..4d8d8f3e --- /dev/null +++ b/cdist/conf/type/__prometheus_server/parameter/optional @@ -0,0 +1,4 @@ +target-heap-size +retention-days +rule-files +storage-path diff --git a/cdist/conf/type/__prometheus_server/parameter/required b/cdist/conf/type/__prometheus_server/parameter/required new file mode 100644 index 00000000..49abf924 --- /dev/null +++ b/cdist/conf/type/__prometheus_server/parameter/required @@ -0,0 +1,3 @@ +alertmanager-url +config +listen-address diff --git a/cdist/conf/type/__prometheus_server/singleton b/cdist/conf/type/__prometheus_server/singleton new file mode 100644 index 00000000..e69de29b From 4c9863cc542e5e77bc17a19814dd8048de86488b Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Fri, 2 Jun 2017 17:39:43 +0200 Subject: [PATCH 12/12] Update changelog --- docs/changelog | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/changelog b/docs/changelog index e691145c..c33ad05a 100644 --- a/docs/changelog +++ b/docs/changelog @@ -8,7 +8,8 @@ next: * Type __sysctl: Add devuan support (Nico Schottelius) * Core: Shorten ssh control path (Darko Poljak) * Type __consul: Add new version and add http check (Kamila Součková) - * New types: __daemontools and __daemontools_service (Kamila Součková) + * New types: __daemontools and __daemontools_service (Kamila Součková) + * New types: __prometheus_server and __prometheus_alertmanager (Kamila Součková) 4.4.2: 2017-03-08 * Core: Fix suppression of manifests' outputs (Darko Poljak)