Updated consul formula from upstream, added bin_dir for configurable install

This commit is contained in:
Eric Renfro 2019-05-06 14:38:54 -04:00
parent c0b672206e
commit cc56227f4e
Signed by: psi-jack
GPG key ID: 14977F3A50D9A5BF
13 changed files with 60 additions and 24 deletions

View file

@ -12,6 +12,7 @@ consul-template-tmpl-file-{{ loop.index }}:
file.managed:
- source: {{ tmpl.source }}
- name: /etc/consul-template/tmpl-source/{{ tmpl.name }}.ctmpl
- template: {{ tmpl.template_engine }}
consul-template.d-tmpl-{{ loop.index }}:
file.serialize:

View file

@ -1,6 +1,6 @@
consul_template:
version: 0.14.0
hash: 7c70ea5f230a70c809333e75fdcff2f6f1e838f29cfb872e1420a63cdf7f3a78
version: 0.20.0
hash: 500fe023c89517f959175eb79e21c33df0acf7733d3f3681ec8c5238863caf86
service: false
config:
@ -9,6 +9,7 @@ consul_template:
tmpl:
- name: example
source: salt://consul-template/files/example.ctmpl
template_engine: null # None in Python
config:
template:
source: /etc/consul-template/tmpl-source/example.ctmpl

View file

@ -1,13 +1,17 @@
[Unit]
Description=consul-template
Wants=network.target
After=network.target
Documentation=https://github.com/hashicorp/consul-template
Wants=network-online.target
After=network-online.target
[Service]
Environment="GOMAXPROCS=2" "PATH=/usr/local/bin:/usr/bin:/bin"
ExecStart=/usr/local/bin/consul-template -config /etc/consul-template.d
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=TERM
KillMode=process
KillSignal=SIGTERM
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target

View file

@ -20,6 +20,7 @@ consul-template-init-script:
consul-template-service:
service.running:
- name: consul-template
- enable: True
- watch:
- file: /etc/consul-template.d/*
{% endif %}

View file

@ -3,8 +3,9 @@
consul-config:
file.serialize:
- name: /etc/consul.d/config.json
- encoding: utf-8
- formatter: json
- dataset: {{ consul.config }}
- dataset: {{ consul.config | json }}
- user: {{ consul.user }}
- group: {{ consul.group }}
- mode: 0640
@ -40,4 +41,4 @@ consul-script-config:
- user: consul-user
- formatter: json
- dataset:
services: {{ consul.register }}
services: {{ consul.register | json }}

View file

@ -1,13 +1,14 @@
consul:
version: 1.4.0
download_host: releases.hashicorp.com
bin_dir: /usr/local/bin
service: false
user: consul
user_uid:
group: consul
ui_beta: false
group_gid:
config:
server: false
@ -16,6 +17,7 @@ consul:
ui: true
enable_debug: false
log_level: info
encrypt: ""
retry_join: []
retry_interval: 30s
datacenter: "main"

View file

@ -1,15 +1,20 @@
[Unit]
Description=consul
Wants=network.target
After=network.target
Description="HashiCorp Consul - A service mesh solution"
Documentation=https://www.consul.io/
Requires=network-online.target
After=network-online.target
ConditionFileNotEmpty=/etc/consul.d/config.json
[Service]
EnvironmentFile=-/etc/{% if grains['os_family'] == 'Debian' %}default{% else %}sysconfig{% endif %}/consul
ExecStart=/opt/consul/bin/consul agent -config-dir=/etc/consul.d
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=TERM
User={{ user }}
Group={{ group }}
ExecStart={{ bin_dir }}/consul agent -config-dir=/etc/consul.d
ExecReload={{ bin_dir }}/consul reload
KillMode=process
Restart=on-failure
RestartSec=42s
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target

View file

@ -24,7 +24,7 @@
. /etc/rc.d/init.d/functions
prog="consul"
exec="/opt/consul/bin/$prog"
exec="{{ bin_dir }}/$prog"
pidfile="/var/run/$prog.pid"
lockfile="/var/lock/subsys/$prog"
logfile="/var/log/$prog"

View file

@ -18,7 +18,7 @@ script
exec start-stop-daemon --start \
--chuid ${CONSUL_USER:-consul}:${CONSUL_GROUP:-consul} \
--exec /opt/consul/bin/consul agent -- \
--exec {{ bin_dir }}/consul agent -- \
-config-dir="/etc/consul.d" \
${CONSUL_FLAGS} \
>> /var/log/consul.log 2>&1

View file

@ -1,6 +1,9 @@
{%- if pillar.get('consul', {}).get('enabled', True) %}
{% from slspath+"/map.jinja" import consul with context %}
include:
- {{ slspath }}.install
- {{ slspath }}.config
- {{ slspath }}.service
{%- endif %}

View file

@ -6,7 +6,7 @@ consul-dep-unzip:
consul-bin-dir:
file.directory:
- name: /opt/consul/bin
- name: {{ consul.bin_dir }}
- makedirs: True
# Create consul user
@ -14,6 +14,9 @@ consul-group:
group.present:
- name: {{ consul.group }}
- system: True
{% if consul.get('group_gid', None) != None -%}
- gid: {{ consul.group_gid }}
{%- endif %}
consul-user:
user.present:
@ -23,6 +26,9 @@ consul-user:
- home: {{ salt['user.info'](consul.user)['home']|default(consul.config.data_dir) }}
- createhome: False
- system: True
{% if consul.get('user_uid', None) != None -%}
- uid: {{ consul.user_uid }}
{%- endif %}
- require:
- group: consul-group
@ -48,7 +54,7 @@ consul-download:
- name: /tmp/consul_{{ consul.version }}_linux_{{ consul.arch }}.zip
- source: https://{{ consul.download_host }}/consul/{{ consul.version }}/consul_{{ consul.version }}_linux_{{ consul.arch }}.zip
- source_hash: https://releases.hashicorp.com/consul/{{ consul.version }}/consul_{{ consul.version }}_SHA256SUMS
- unless: test -f /opt/consul/bin/consul-{{ consul.version }}
- unless: test -f {{ consul.bin_dir }}-{{ consul.version }}
consul-extract:
cmd.wait:
@ -58,10 +64,10 @@ consul-extract:
consul-install:
file.rename:
- name: /opt/consul/bin/consul-{{ consul.version }}
- name: {{ consul.bin_dir }}/consul-{{ consul.version }}
- source: /tmp/consul
- require:
- file: /opt/consul/bin
- file: {{ consul.bin_dir }}
- watch:
- cmd: consul-extract
@ -74,6 +80,6 @@ consul-clean:
consul-link:
file.symlink:
- target: consul-{{ consul.version }}
- name: /opt/consul/bin/consul
- name: {{ consul.bin_dir }}/consul
- watch:
- file: consul-install

View file

@ -14,27 +14,31 @@ consul-init-env:
- contents:
- CONSUL_USER={{ consul.user }}
- CONSUL_GROUP={{ consul.group }}
- CONSUL_UI_BETA={{ consul.ui_beta }}
- GOMAXPROCS=2
- PATH=/usr/local/bin:/usr/bin:/bin
consul-init-file:
file.managed:
{%- if salt['test.provider']('service') == 'systemd' %}
{%- if salt['test.provider']('service').startswith('systemd') %}
- source: salt://{{ slspath }}/files/consul.service
- name: /etc/systemd/system/consul.service
- template: jinja
- context:
user: {{ consul.user }}
group: {{ consul.group }}
bin_dir: {{ consul.bin_dir }}
- mode: 0644
{%- elif salt['test.provider']('service') == 'upstart' %}
- source: salt://{{ slspath }}/files/consul.upstart
- name: /etc/init/consul.conf
- context:
bin_dir: {{ consul.bin_dir }}
- mode: 0644
{%- else %}
- source: salt://{{ slspath }}/files/consul.sysvinit
- name: /etc/init.d/consul
- context:
bin_dir: {{ consul.bin_dir }}
- mode: 0755
{%- endif %}

View file

@ -5,6 +5,10 @@ consul:
# Set user and group for Consul config files and running service
user: consul
group: consul
bin_dir: /opt/consul/bin
version: 0.7.0
download_host: releases.hashicorp.com
config:
server: True
@ -22,6 +26,10 @@ consul:
- 1.1.1.1
- 2.2.2.2
ui: true
log_level: info
data_dir: /var/consul
register:
- name: Redis
checks: