add new types to manage consul and friends
Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
parent
4f7ae8425d
commit
2c7ab566e1
83 changed files with 2308 additions and 0 deletions
71
cdist/conf/type/__consul/man.text
Normal file
71
cdist/conf/type/__consul/man.text
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
cdist-type__consul(7)
|
||||||
|
=====================
|
||||||
|
Steven Armstrong <steven-cdist--@--armstrong.cc>
|
||||||
|
|
||||||
|
|
||||||
|
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).
|
65
cdist/conf/type/__consul/manifest
Executable file
65
cdist/conf/type/__consul/manifest
Executable file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
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"
|
1
cdist/conf/type/__consul/parameter/default/install-from
Normal file
1
cdist/conf/type/__consul/parameter/default/install-from
Normal file
|
@ -0,0 +1 @@
|
||||||
|
https://dl.bintray.com/mitchellh/consul/0.4.1_linux_amd64.zip
|
1
cdist/conf/type/__consul/parameter/default/install-to
Normal file
1
cdist/conf/type/__consul/parameter/default/install-to
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/usr/local/bin/consul
|
1
cdist/conf/type/__consul/parameter/default/state
Normal file
1
cdist/conf/type/__consul/parameter/default/state
Normal file
|
@ -0,0 +1 @@
|
||||||
|
present
|
3
cdist/conf/type/__consul/parameter/optional
Normal file
3
cdist/conf/type/__consul/parameter/optional
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
install-from
|
||||||
|
install-to
|
||||||
|
state
|
0
cdist/conf/type/__consul/singleton
Normal file
0
cdist/conf/type/__consul/singleton
Normal file
17
cdist/conf/type/__consul_agent/files/consul.systemd
Normal file
17
cdist/conf/type/__consul_agent/files/consul.systemd
Normal file
|
@ -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
|
93
cdist/conf/type/__consul_agent/files/consul.sysv
Normal file
93
cdist/conf/type/__consul_agent/files/consul.sysv
Normal file
|
@ -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 $?
|
13
cdist/conf/type/__consul_agent/files/consul.upstart
Normal file
13
cdist/conf/type/__consul_agent/files/consul.upstart
Normal file
|
@ -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
|
||||||
|
|
31
cdist/conf/type/__consul_agent/gencode-remote
Executable file
31
cdist/conf/type/__consul_agent/gencode-remote
Executable file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
service="consul"
|
||||||
|
state="$(cat "$__object/parameter/state")"
|
||||||
|
|
||||||
|
case "$state" in
|
||||||
|
present)
|
||||||
|
:
|
||||||
|
;;
|
||||||
|
absent)
|
||||||
|
echo "service $service stop || true"
|
||||||
|
;;
|
||||||
|
esac
|
134
cdist/conf/type/__consul_agent/man.text
Normal file
134
cdist/conf/type/__consul_agent/man.text
Normal file
|
@ -0,0 +1,134 @@
|
||||||
|
cdist-type__consul_agent(7)
|
||||||
|
===========================
|
||||||
|
Steven Armstrong <steven-cdist--@--armstrong.cc>
|
||||||
|
|
||||||
|
|
||||||
|
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).
|
175
cdist/conf/type/__consul_agent/manifest
Executable file
175
cdist/conf/type/__consul_agent/manifest
Executable file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
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
|
8
cdist/conf/type/__consul_agent/parameter/boolean
Normal file
8
cdist/conf/type/__consul_agent/parameter/boolean
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
disable-remote-exec
|
||||||
|
disable-update-check
|
||||||
|
leave-on-terminate
|
||||||
|
rejoin-after-leave
|
||||||
|
server
|
||||||
|
syslog
|
||||||
|
verify-incoming
|
||||||
|
verify-outgoing
|
1
cdist/conf/type/__consul_agent/parameter/default/group
Normal file
1
cdist/conf/type/__consul_agent/parameter/default/group
Normal file
|
@ -0,0 +1 @@
|
||||||
|
consul
|
1
cdist/conf/type/__consul_agent/parameter/default/state
Normal file
1
cdist/conf/type/__consul_agent/parameter/default/state
Normal file
|
@ -0,0 +1 @@
|
||||||
|
present
|
1
cdist/conf/type/__consul_agent/parameter/default/user
Normal file
1
cdist/conf/type/__consul_agent/parameter/default/user
Normal file
|
@ -0,0 +1 @@
|
||||||
|
consul
|
13
cdist/conf/type/__consul_agent/parameter/optional
Normal file
13
cdist/conf/type/__consul_agent/parameter/optional
Normal file
|
@ -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
|
|
@ -0,0 +1 @@
|
||||||
|
retry-join
|
0
cdist/conf/type/__consul_agent/singleton
Normal file
0
cdist/conf/type/__consul_agent/singleton
Normal file
68
cdist/conf/type/__consul_check/man.text
Normal file
68
cdist/conf/type/__consul_check/man.text
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
cdist-type__consul_check(7)
|
||||||
|
=============================
|
||||||
|
Steven Armstrong <steven-cdist--@--armstrong.cc>
|
||||||
|
|
||||||
|
|
||||||
|
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).
|
64
cdist/conf/type/__consul_check/manifest
Executable file
64
cdist/conf/type/__consul_check/manifest
Executable file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
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 -
|
1
cdist/conf/type/__consul_check/parameter/default/state
Normal file
1
cdist/conf/type/__consul_check/parameter/default/state
Normal file
|
@ -0,0 +1 @@
|
||||||
|
present
|
7
cdist/conf/type/__consul_check/parameter/optional
Normal file
7
cdist/conf/type/__consul_check/parameter/optional
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
id
|
||||||
|
interval
|
||||||
|
name
|
||||||
|
notes
|
||||||
|
script
|
||||||
|
state
|
||||||
|
ttl
|
24
cdist/conf/type/__consul_reload/gencode-remote
Executable file
24
cdist/conf/type/__consul_reload/gencode-remote
Executable file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
service="consul"
|
||||||
|
if grep -q "^__file/etc/consul/conf.d/" "$__messages_in"; then
|
||||||
|
echo "service $service status && service $service reload || true"
|
||||||
|
fi
|
42
cdist/conf/type/__consul_reload/man.text
Normal file
42
cdist/conf/type/__consul_reload/man.text
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
cdist-type__consul_reload(7)
|
||||||
|
============================
|
||||||
|
Steven Armstrong <steven-cdist--@--armstrong.cc>
|
||||||
|
|
||||||
|
|
||||||
|
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).
|
0
cdist/conf/type/__consul_reload/singleton
Normal file
0
cdist/conf/type/__consul_reload/singleton
Normal file
71
cdist/conf/type/__consul_service/man.text
Normal file
71
cdist/conf/type/__consul_service/man.text
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
cdist-type__consul_service(7)
|
||||||
|
=============================
|
||||||
|
Steven Armstrong <steven-cdist--@--armstrong.cc>
|
||||||
|
|
||||||
|
|
||||||
|
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).
|
83
cdist/conf/type/__consul_service/manifest
Executable file
83
cdist/conf/type/__consul_service/manifest
Executable file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
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 -
|
1
cdist/conf/type/__consul_service/parameter/default/state
Normal file
1
cdist/conf/type/__consul_service/parameter/default/state
Normal file
|
@ -0,0 +1 @@
|
||||||
|
present
|
7
cdist/conf/type/__consul_service/parameter/optional
Normal file
7
cdist/conf/type/__consul_service/parameter/optional
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
check-interval
|
||||||
|
check-script
|
||||||
|
check-ttl
|
||||||
|
id
|
||||||
|
name
|
||||||
|
port
|
||||||
|
state
|
|
@ -0,0 +1 @@
|
||||||
|
tag
|
|
@ -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
|
89
cdist/conf/type/__consul_template/files/consul-template.sysv
Normal file
89
cdist/conf/type/__consul_template/files/consul-template.sysv
Normal file
|
@ -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 $?
|
|
@ -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
|
72
cdist/conf/type/__consul_template/man.text
Normal file
72
cdist/conf/type/__consul_template/man.text
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
cdist-type__consul_template(7)
|
||||||
|
==============================
|
||||||
|
Steven Armstrong <steven-cdist--@--armstrong.cc>
|
||||||
|
|
||||||
|
|
||||||
|
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).
|
121
cdist/conf/type/__consul_template/manifest
Executable file
121
cdist/conf/type/__consul_template/manifest
Executable file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
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
|
2
cdist/conf/type/__consul_template/parameter/boolean
Normal file
2
cdist/conf/type/__consul_template/parameter/boolean
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
ssl
|
||||||
|
ssl-no-verify
|
|
@ -0,0 +1 @@
|
||||||
|
localhost:8500
|
7
cdist/conf/type/__consul_template/parameter/optional
Normal file
7
cdist/conf/type/__consul_template/parameter/optional
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
auth
|
||||||
|
batch-size
|
||||||
|
consul
|
||||||
|
max-stale
|
||||||
|
retry
|
||||||
|
token
|
||||||
|
wait
|
0
cdist/conf/type/__consul_template/singleton
Normal file
0
cdist/conf/type/__consul_template/singleton
Normal file
69
cdist/conf/type/__consul_template_template/man.text
Normal file
69
cdist/conf/type/__consul_template_template/man.text
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
cdist-type__consul_template_template(7)
|
||||||
|
=======================================
|
||||||
|
Steven Armstrong <steven-cdist--@--armstrong.cc>
|
||||||
|
|
||||||
|
|
||||||
|
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).
|
74
cdist/conf/type/__consul_template_template/manifest
Executable file
74
cdist/conf/type/__consul_template_template/manifest
Executable file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
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 -
|
|
@ -0,0 +1 @@
|
||||||
|
present
|
|
@ -0,0 +1,4 @@
|
||||||
|
command
|
||||||
|
source
|
||||||
|
source-file
|
||||||
|
state
|
|
@ -0,0 +1 @@
|
||||||
|
destination
|
64
cdist/conf/type/__consul_watch_checks/man.text
Normal file
64
cdist/conf/type/__consul_watch_checks/man.text
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
cdist-type__consul_watch_checks(7)
|
||||||
|
==================================
|
||||||
|
Steven Armstrong <steven-cdist--@--armstrong.cc>
|
||||||
|
|
||||||
|
|
||||||
|
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).
|
61
cdist/conf/type/__consul_watch_checks/manifest
Executable file
61
cdist/conf/type/__consul_watch_checks/manifest
Executable file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
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 -
|
|
@ -0,0 +1 @@
|
||||||
|
present
|
5
cdist/conf/type/__consul_watch_checks/parameter/optional
Normal file
5
cdist/conf/type/__consul_watch_checks/parameter/optional
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
datacenter
|
||||||
|
filter-service
|
||||||
|
filter-state
|
||||||
|
state
|
||||||
|
token
|
1
cdist/conf/type/__consul_watch_checks/parameter/required
Normal file
1
cdist/conf/type/__consul_watch_checks/parameter/required
Normal file
|
@ -0,0 +1 @@
|
||||||
|
handler
|
58
cdist/conf/type/__consul_watch_event/man.text
Normal file
58
cdist/conf/type/__consul_watch_event/man.text
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
cdist-type__consul_watch_event(7)
|
||||||
|
=================================
|
||||||
|
Steven Armstrong <steven-cdist--@--armstrong.cc>
|
||||||
|
|
||||||
|
|
||||||
|
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).
|
51
cdist/conf/type/__consul_watch_event/manifest
Executable file
51
cdist/conf/type/__consul_watch_event/manifest
Executable file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
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 -
|
|
@ -0,0 +1 @@
|
||||||
|
present
|
4
cdist/conf/type/__consul_watch_event/parameter/optional
Normal file
4
cdist/conf/type/__consul_watch_event/parameter/optional
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
datacenter
|
||||||
|
name
|
||||||
|
state
|
||||||
|
token
|
1
cdist/conf/type/__consul_watch_event/parameter/required
Normal file
1
cdist/conf/type/__consul_watch_event/parameter/required
Normal file
|
@ -0,0 +1 @@
|
||||||
|
handler
|
55
cdist/conf/type/__consul_watch_key/man.text
Normal file
55
cdist/conf/type/__consul_watch_key/man.text
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
cdist-type__consul_watch_key(7)
|
||||||
|
===============================
|
||||||
|
Steven Armstrong <steven-cdist--@--armstrong.cc>
|
||||||
|
|
||||||
|
|
||||||
|
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).
|
51
cdist/conf/type/__consul_watch_key/manifest
Executable file
51
cdist/conf/type/__consul_watch_key/manifest
Executable file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
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 -
|
|
@ -0,0 +1 @@
|
||||||
|
present
|
3
cdist/conf/type/__consul_watch_key/parameter/optional
Normal file
3
cdist/conf/type/__consul_watch_key/parameter/optional
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
datacenter
|
||||||
|
state
|
||||||
|
token
|
2
cdist/conf/type/__consul_watch_key/parameter/required
Normal file
2
cdist/conf/type/__consul_watch_key/parameter/required
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
handler
|
||||||
|
key
|
55
cdist/conf/type/__consul_watch_keyprefix/man.text
Normal file
55
cdist/conf/type/__consul_watch_keyprefix/man.text
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
cdist-type__consul_watch_keyprefix(7)
|
||||||
|
=====================================
|
||||||
|
Steven Armstrong <steven-cdist--@--armstrong.cc>
|
||||||
|
|
||||||
|
|
||||||
|
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).
|
51
cdist/conf/type/__consul_watch_keyprefix/manifest
Executable file
51
cdist/conf/type/__consul_watch_keyprefix/manifest
Executable file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
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 -
|
|
@ -0,0 +1 @@
|
||||||
|
present
|
|
@ -0,0 +1,3 @@
|
||||||
|
datacenter
|
||||||
|
state
|
||||||
|
token
|
|
@ -0,0 +1,2 @@
|
||||||
|
handler
|
||||||
|
keyprefix
|
52
cdist/conf/type/__consul_watch_nodes/man.text
Normal file
52
cdist/conf/type/__consul_watch_nodes/man.text
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
cdist-type__consul_watch_nodes(7)
|
||||||
|
=================================
|
||||||
|
Steven Armstrong <steven-cdist--@--armstrong.cc>
|
||||||
|
|
||||||
|
|
||||||
|
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).
|
51
cdist/conf/type/__consul_watch_nodes/manifest
Executable file
51
cdist/conf/type/__consul_watch_nodes/manifest
Executable file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
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 -
|
|
@ -0,0 +1 @@
|
||||||
|
present
|
3
cdist/conf/type/__consul_watch_nodes/parameter/optional
Normal file
3
cdist/conf/type/__consul_watch_nodes/parameter/optional
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
datacenter
|
||||||
|
state
|
||||||
|
token
|
1
cdist/conf/type/__consul_watch_nodes/parameter/required
Normal file
1
cdist/conf/type/__consul_watch_nodes/parameter/required
Normal file
|
@ -0,0 +1 @@
|
||||||
|
handler
|
74
cdist/conf/type/__consul_watch_service/man.text
Normal file
74
cdist/conf/type/__consul_watch_service/man.text
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
cdist-type__consul_watch_service(7)
|
||||||
|
===================================
|
||||||
|
Steven Armstrong <steven-cdist--@--armstrong.cc>
|
||||||
|
|
||||||
|
|
||||||
|
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).
|
54
cdist/conf/type/__consul_watch_service/manifest
Executable file
54
cdist/conf/type/__consul_watch_service/manifest
Executable file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
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 -
|
1
cdist/conf/type/__consul_watch_service/parameter/boolean
Normal file
1
cdist/conf/type/__consul_watch_service/parameter/boolean
Normal file
|
@ -0,0 +1 @@
|
||||||
|
passingonly
|
|
@ -0,0 +1 @@
|
||||||
|
present
|
|
@ -0,0 +1,4 @@
|
||||||
|
datacenter
|
||||||
|
state
|
||||||
|
tag
|
||||||
|
token
|
|
@ -0,0 +1,2 @@
|
||||||
|
handler
|
||||||
|
service
|
52
cdist/conf/type/__consul_watch_services/man.text
Normal file
52
cdist/conf/type/__consul_watch_services/man.text
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
cdist-type__consul_watch_services(7)
|
||||||
|
====================================
|
||||||
|
Steven Armstrong <steven-cdist--@--armstrong.cc>
|
||||||
|
|
||||||
|
|
||||||
|
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).
|
51
cdist/conf/type/__consul_watch_services/manifest
Executable file
51
cdist/conf/type/__consul_watch_services/manifest
Executable file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
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 -
|
|
@ -0,0 +1 @@
|
||||||
|
present
|
|
@ -0,0 +1,3 @@
|
||||||
|
datacenter
|
||||||
|
state
|
||||||
|
token
|
|
@ -0,0 +1 @@
|
||||||
|
handler
|
|
@ -7,6 +7,20 @@ Changelog
|
||||||
next:
|
next:
|
||||||
* New type __staged_file: Manage staged files
|
* New type __staged_file: Manage staged files
|
||||||
* New type __config_file: Manage configuration files and run code on change
|
* 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:
|
3.1.11:
|
||||||
* Type __start_on_boot: Support Ubuntu upstart
|
* Type __start_on_boot: Support Ubuntu upstart
|
||||||
|
|
Loading…
Reference in a new issue