Merge consul states from salt-rbkmoney

This commit is contained in:
Antsiferov Grigory 2018-08-29 11:31:19 +03:00
parent 36d412a207
commit ba03345aa6
8 changed files with 253 additions and 0 deletions

54
sls/consul/conf.sls Normal file
View File

@ -0,0 +1,54 @@
include:
- consul.pkg
/etc/conf.d/consul:
file.managed:
- source: salt://consul/files/consul.confd.tpl
- template: jinja
- mode: 644
/etc/consul.d/:
file.directory:
- create: True
- mode: 755
- user: consul
- group: consul
/etc/consul.d/main-config.json:
file.serialize:
{% if salt['pillar.get']('consul:main-config', False) %}
- dataset_pillar: consul:main-config
{% else %}
- dataset:
server: true
bootstrap_expect: 1
ui: true
{% endif %}
- formatter: json
- mode: 644
- user: consul
- group: consul
/etc/consul.d/private-config.json:
file.serialize:
{% if salt['pillar.get']('consul:private-config', False) %}
- dataset_pillar: consul:private-config
{% else %}
- dataset: {}
{% endif %}
- formatter: json
- mode: 600
- user: consul
- group: consul
/etc/consul.d/reloadable-config.json:
file.serialize:
{% if salt['pillar.get']('consul:reloadable-config', False) %}
- dataset_pillar: consul:reloadable-config
{% else %}
- dataset: {}
{% endif %}
- formatter: json
- mode: 644
- user: consul
- group: consul

View File

@ -0,0 +1,58 @@
include:
- consul
app-admin/consul-template:
pkg.installed:
- pkgs:
- app-admin/consul-template: ">=0.18.0"
- require:
- portage_config: app-admin/consul-template
portage_config.flags:
- name: "<consul-template-0.19"
- accept_keywords:
- "~*"
/etc/conf.d/consul-template:
file.managed:
- source: salt://consul/files/consul-template/consul-template.confd.tpl
- template: jinja
- mode: 644
- require:
- pkg: app-admin/consul-template
/etc/init.d/consul-template:
file.managed:
- source: salt://consul/files/consul-template/consul-template.initd
- template: jinja
- mode: 755
- require:
- pkg: app-admin/consul-template
/etc/consul-template.d/consul.conf:
file.managed:
- source: salt://consul/files/consul-template/consul.conf.tpl
- template: jinja
- mode: 640
- user: root
- group: consul-template
- require:
- pkg: app-admin/consul-template
/etc/consul-template-templates/:
file.directory:
- create: true
- mode: 755
- user: consul-template
- group: consul-template
- require:
- pkg: app-admin/consul-template
consul-template:
service.running:
- enable: True
- watch:
- pkg: app-admin/consul-template
- file: /etc/conf.d/consul-template
- file: /etc/init.d/consul-template
- file: /etc/consul-template.d/consul.conf
- file: /etc/consul-template-templates/

View File

@ -0,0 +1,10 @@
# Managed by Salt
# you can change the init script behavior by setting those parameters
# - group (default: consul-template)
# - pidfile (default: /run/consul-template/consul-template.pid)
# - user (default: consul-template)
# extra arguments for the consul agent
user="{{ salt['pillar.get']('consul:template:user', 'root') }}"
group="{{ salt['pillar.get']('consul:template:group', 'root') }}"
command_args="{{ salt['pillar.get']('consul:template:extra-args', '-syslog') }}"

View File

@ -0,0 +1,30 @@
#!/sbin/openrc-run
# -*- mode: shell-script -*-
description="consul-template agent"
group="${group:-${SVCNAME}}"
pidfile="${pidfile:-"/run/${SVCNAME}/${SVCNAME}.pid"}"
user="${user:-${SVCNAME}}"
command="/usr/bin/${SVCNAME}"
command_args="-config=/etc/consul-template.d ${command_args}"
command_background="true"
start_stop_daemon_args="--user ${user} --group ${group} \
--stdout /var/log/${SVCNAME}/${SVCNAME}.log \
--stderr /var/log/${SVCNAME}/${SVCNAME}.log"
depend() {
need net
after net
}
start_pre() {
checkpath -d -m 0755 -o "${user}":"${group}" "${pidfile%/*}"
}
stop() {
# SIGINT is required for graceful shutdown of consul-template
ebegin "Stopping ${SVCNAME}"
start-stop-daemon --stop --signal SIGINT --pidfile "${pidfile}"
eend $?
}

View File

@ -0,0 +1,15 @@
# Managed by Salt
{% set conf = salt['pillar.get']('consul:template', {}) %}
{% set conf_consul = conf.get('consul', {}) %}
consul {
address = "{{ conf_consul.get('address', '[::1]:8500') }}"
retry {
backoff = "{{ conf_consul.get('retry-backoff', '10s') }}"
max_backoff = "{{ conf_consul.get('retry-max-backoff', '5m') }}"
}
}
max_stale = "{{ conf.get('max-stale', '2m') }}"
wait {
min = "{{ conf.get('wait-min', '5s') }}"
max = "{{ conf.get('wait-max', '30s') }}"
}

View File

@ -0,0 +1,26 @@
# -*- mode: shell-script -*-
# Managed by Salt
# you can change the init script behavior by setting those parameters
# - group (default: consul)
# - pidfile (default: /run/consul/consul.pid)
# - user (default: consul)
# extra arguments for the consul agent
data_dir="{{ salt['pillar.get']('consul:data-dir', '/var/lib/consul') }}"
command_args="{{ salt['pillar.get']('consul:command-args', '-config-dir=/etc/consul.d') }}
-data-dir ${data_dir}"
# upstream strongly recommends > 1
GOMAXPROCS={{ salt['pillar.get']('consul:gomaxproc', 2) }}
user={{ salt['pillar.get']('consul:user', 'consul') }}
{% if salt['pillar.get']('consul:drop-services-on-start', False) %}
start_pre() {
if [ "$RC_CMD" != restart ]; then
for dir in services checks; do
test -d "${data_dir}/${dir}" && rm -rf "${data_dir}/${dir}"
done
fi
}
{% endif %}

40
sls/consul/init.sls Normal file
View File

@ -0,0 +1,40 @@
include:
- consul.pkg
- consul.conf
{% set data_dir = salt['pillar.get']('consul:data-dir', '/var/lib/consul') %}
{% set consul_user = salt['pillar.get']('consul:user', 'consul') %}
{{ data_dir }}/:
file.directory:
- create: True
- mode: 755
- user: {{ consul_user }}
consul:
service.running:
- enable: True
- watch:
- pkg: app-admin/consul
- file: /etc/conf.d/consul
- file: /etc/consul.d/
- file: /etc/consul.d/main-config.json
- file: /etc/consul.d/private-config.json
- file: {{ data_dir }}/
- require:
- file: /etc/consul.d/reloadable-config.json
consul-reload:
# This is for watch-in reloads
service.running:
- name: consul
- reload: True
- watch:
- file: /etc/consul.d/reloadable-config.json
- require:
- pkg: app-admin/consul
- file: /etc/conf.d/consul
- file: /etc/consul.d/
- file: /etc/consul.d/main-config.json
- file: /etc/consul.d/private-config.json
- file: {{ data_dir }}/

20
sls/consul/pkg.sls Normal file
View File

@ -0,0 +1,20 @@
{% set consul_version = salt['pillar.get']('consul:version', '<1.3') %}
{% set consul_packaged = salt['pillar.get']('consul:packaged', False) %}
{% if not consul_packaged %}
include:
- go.dev-go.go-tools
- go.dev-go.gox
{% endif %}
app-admin/consul:
pkg.installed:
- app-admin/consul:
- version: "{{ consul_version }}"
{% if consul_packaged %}
- binhost: force
{% endif %}
- require:
- portage_config: app-admin/consul
portage_config.flags:
- accept_keywords:
- "~*"