From 8c85fa576ec6e4f4b53a9b15039326536e3a93f8 Mon Sep 17 00:00:00 2001 From: morgana2313 <32460045+morgana2313@users.noreply.github.com> Date: Wed, 22 Nov 2017 09:43:57 +0100 Subject: [PATCH 01/11] Update defaults.yaml New startup_params parameter --- consul/defaults.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/consul/defaults.yaml b/consul/defaults.yaml index 170f3557..347496fb 100644 --- a/consul/defaults.yaml +++ b/consul/defaults.yaml @@ -16,3 +16,4 @@ consul: datacenter: "main" register: [] scripts: [] + startup_params: "" From 06c72fc4cf0c0779bfa9bdba347486d8cb418e5a Mon Sep 17 00:00:00 2001 From: morgana2313 <32460045+morgana2313@users.noreply.github.com> Date: Wed, 22 Nov 2017 09:44:48 +0100 Subject: [PATCH 02/11] Update consul.service Add startup params to consul --- consul/files/consul.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consul/files/consul.service b/consul/files/consul.service index ecc27753..b9fcbbff 100644 --- a/consul/files/consul.service +++ b/consul/files/consul.service @@ -5,7 +5,7 @@ After=network.target [Service] Environment="GOMAXPROCS=2" "PATH=/usr/local/bin:/usr/bin:/bin" -ExecStart=/usr/local/bin/consul agent -config-dir=/etc/consul.d +ExecStart=/usr/local/bin/consul agent -config-dir=/etc/consul.d {{ salt['pillar.get']('consul:startup_params', '') }} ExecReload=/bin/kill -HUP $MAINPID KillSignal=TERM User=consul From 271fa849c3aadab6d66b43f5e5d1593fc223cf05 Mon Sep 17 00:00:00 2001 From: morgana2313 <32460045+morgana2313@users.noreply.github.com> Date: Wed, 22 Nov 2017 09:45:35 +0100 Subject: [PATCH 03/11] Update service.sls Add startup params to consul --- consul/service.sls | 1 + 1 file changed, 1 insertion(+) diff --git a/consul/service.sls b/consul/service.sls index 3870954d..cd833fb9 100644 --- a/consul/service.sls +++ b/consul/service.sls @@ -6,6 +6,7 @@ consul-init-file: - source: salt://{{ slspath }}/files/consul.service - name: /etc/systemd/system/consul.service - mode: 0644 + - template: jinja {%- elif salt['test.provider']('service') == 'upstart' %} - source: salt://{{ slspath }}/files/consul.upstart - name: /etc/init/consul.conf From bc91540a8edf6a58945134f0cbee7d7e6425264f Mon Sep 17 00:00:00 2001 From: morgana2313 <32460045+morgana2313@users.noreply.github.com> Date: Wed, 22 Nov 2017 09:47:28 +0100 Subject: [PATCH 04/11] Update pillar.example Startup params for consul --- pillar.example | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pillar.example b/pillar.example index 84d8f613..30b63da6 100644 --- a/pillar.example +++ b/pillar.example @@ -1,7 +1,8 @@ consul: # Start Consul agent service and enable it at boot time service: True - + startup_params: --client "127.0.0.1" + config: server: True bind_addr: 0.0.0.0 From 1637a29e7bf2a8022e9e3962ffd06459e9eb93bc Mon Sep 17 00:00:00 2001 From: morgana2313 <32460045+morgana2313@users.noreply.github.com> Date: Tue, 5 Dec 2017 15:18:32 +0100 Subject: [PATCH 05/11] Validate, then reload on changes --- consul/service.sls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consul/service.sls b/consul/service.sls index cd833fb9..6ad4ab7e 100644 --- a/consul/service.sls +++ b/consul/service.sls @@ -25,5 +25,5 @@ consul-service: - enable: True - watch: - file: consul-init-file - + - file: /etc/consul.d/* {%- endif %} From d64606470c7f34ca28397374e38496a57a9414b1 Mon Sep 17 00:00:00 2001 From: morgana2313 <32460045+morgana2313@users.noreply.github.com> Date: Tue, 5 Dec 2017 15:19:32 +0100 Subject: [PATCH 06/11] Validate, then reload on changes --- consul/files/consul.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consul/files/consul.service b/consul/files/consul.service index b9fcbbff..98faad3b 100644 --- a/consul/files/consul.service +++ b/consul/files/consul.service @@ -6,7 +6,7 @@ After=network.target [Service] Environment="GOMAXPROCS=2" "PATH=/usr/local/bin:/usr/bin:/bin" ExecStart=/usr/local/bin/consul agent -config-dir=/etc/consul.d {{ salt['pillar.get']('consul:startup_params', '') }} -ExecReload=/bin/kill -HUP $MAINPID +ExecReload=/bin/sh -c "/usr/local/bin/consul validate /etc/consul.d && /bin/kill -HUP $MAINPID" KillSignal=TERM User=consul From f907e0cea7688d04a463a8b7e5c559b3e0c791f1 Mon Sep 17 00:00:00 2001 From: morgana2313 <32460045+morgana2313@users.noreply.github.com> Date: Tue, 5 Dec 2017 15:25:04 +0100 Subject: [PATCH 07/11] Validate, then reload on changes --- consul/config.sls | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/consul/config.sls b/consul/config.sls index cde3836d..b766f5a5 100644 --- a/consul/config.sls +++ b/consul/config.sls @@ -1,12 +1,7 @@ {% from slspath + "/map.jinja" import consul with context %} -consul-config: +/etc/consul.d/config.json: file.serialize: - - name: /etc/consul.d/config.json - {% if consul.service != False %} - - watch_in: - - service: consul - {% endif %} - user: consul - group: consul - require: @@ -25,13 +20,8 @@ consul-script-install-{{ loop.index }}: - mode: 0755 {% endfor %} -consul-script-config: +/etc/consul.d/services.json: file.serialize: - - name: /etc/consul.d/services.json - {% if consul.service != False %} - - watch_in: - - service: consul - {% endif %} - user: consul - group: consul - require: From 5af4e87965d5289f8c8510fd950fb64ff4cbda57 Mon Sep 17 00:00:00 2001 From: morgana2313 <32460045+morgana2313@users.noreply.github.com> Date: Sat, 23 Dec 2017 12:47:56 +0100 Subject: [PATCH 08/11] Update service.sls Add openrc startup scripts for Gentoo and Alpine --- consul/service.sls | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/consul/service.sls b/consul/service.sls index 6ad4ab7e..7fd87e03 100644 --- a/consul/service.sls +++ b/consul/service.sls @@ -11,6 +11,10 @@ consul-init-file: - source: salt://{{ slspath }}/files/consul.upstart - name: /etc/init/consul.conf - mode: 0644 + {%- elif salt['test.provider']('service') == 'gentoo_service' %} + - source: salt://{{ slspath }}/files/consul.openrc + - name: /etc/init.d/consul + - mode: 0755 {%- else %} - source: salt://{{ slspath }}/files/consul.sysvinit - name: /etc/init.d/consul From ce8d96b5b5e7a939fdc3b760ad3ee2f47562aac6 Mon Sep 17 00:00:00 2001 From: morgana2313 <32460045+morgana2313@users.noreply.github.com> Date: Sat, 23 Dec 2017 12:50:11 +0100 Subject: [PATCH 09/11] Create consul.openrc Add openrc startup script for Gentoo and Alpine --- consul.openrc | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 consul.openrc diff --git a/consul.openrc b/consul.openrc new file mode 100644 index 00000000..21b08244 --- /dev/null +++ b/consul.openrc @@ -0,0 +1,55 @@ +#!/sbin/openrc-run + +if [ -z "${CONSUL_DIR}" ] ; then + CONSUL_DIR="/etc/consul.d" +fi +if [ -z "${CONSUL_PID}" ] ; then + CONSUL_PID="/run/consul.pid" +fi + +extra_started_commands="reload graceful" +required_files=$CONSUL_CONF + +depend() { + need net + use logger dns + after firewall + after famd + after sshd +} + +checkconfig() { + + if [ ! -d "${CONSUL_DIR}" ] ; then + ewarn "${CONSUL_DIR} does not exist." + return 1 + fi + + /usr/local/bin/consul validate "${CONSUL_DIR}" +} + +start() { + checkconfig || return 1 + + ebegin "Starting consul" + start-stop-daemon --start --quiet --background --make-pidfile --pidfile "${CONSUL_PID}" \ + --exec /usr/local/bin/consul -- agent -config-dir="${CONSUL_DIR}" + eend $? +} + +stop() { + local rv=0 + ebegin "Stopping consul" + start-stop-daemon --stop --quiet --pidfile "${CONSUL_PID}" + rm -f "${CONSUL_PID}" + eend $? +} + +reload() { + if ! service_started "${SVCNAME}" ; then + eerror "${SVCNAME} isn't running" + return 1 + fi + checkconfig || return 1 + eend $? +} From a31118410a0250202cd24ee5165ee1d8e610a673 Mon Sep 17 00:00:00 2001 From: morgana2313 <32460045+morgana2313@users.noreply.github.com> Date: Sat, 23 Dec 2017 12:54:50 +0100 Subject: [PATCH 10/11] Update install.sls Only download/unzip/install/link consul binary if right version not already installed. --- consul/install.sls | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/consul/install.sls b/consul/install.sls index 4370da97..cd993c87 100644 --- a/consul/install.sls +++ b/consul/install.sls @@ -47,7 +47,7 @@ consul-download: consul-extract: cmd.wait: - name: unzip /tmp/consul_{{ consul.version }}_linux_{{ consul.arch }}.zip -d /tmp - - watch: + - onchanges: - file: consul-download consul-install: @@ -56,18 +56,18 @@ consul-install: - source: /tmp/consul - require: - file: /usr/local/bin - - watch: + - onchanges: - cmd: consul-extract consul-clean: file.absent: - name: /tmp/consul_{{ consul.version }}_linux_{{ consul.arch }}.zip - - watch: + - onchanges: - file: consul-install consul-link: file.symlink: - target: consul-{{ consul.version }} - name: /usr/local/bin/consul - - watch: + - onchanges: - file: consul-install From c12a2c036fc6dffcb649a60c0b055e8c59f8fefc Mon Sep 17 00:00:00 2001 From: morgana2313 <32460045+morgana2313@users.noreply.github.com> Date: Sat, 23 Dec 2017 15:30:11 +0100 Subject: [PATCH 11/11] Create consul.openrc OpenRC startup file --- consul/files/consul.openrc | 58 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 consul/files/consul.openrc diff --git a/consul/files/consul.openrc b/consul/files/consul.openrc new file mode 100644 index 00000000..95986446 --- /dev/null +++ b/consul/files/consul.openrc @@ -0,0 +1,58 @@ +#!/sbin/openrc-run + +extra_started_commands="reload" + + +if [ -z "${CONSUL_DIR}" ] ; then + CONSUL_DIR="/etc/consul.d" +fi +if [ -z "${CONSUL_PID}" ] ; then + CONSUL_PID="/run/consul.pid" +fi + +required_files=$CONSUL_CONF + +depend() { + need net + use logger dns + after firewall + after famd + after sshd +} + +checkconfig() { + + if [ ! -d "${CONSUL_DIR}" ] ; then + ewarn "${CONSUL_DIR} does not exist." + return 1 + fi + + /usr/local/bin/consul validate "${CONSUL_DIR}" +} + +start() { + checkconfig || return 1 + + ebegin "Starting consul" + start-stop-daemon --start --quiet --background --make-pidfile --pidfile "${CONSUL_PID}" \ + --exec /usr/local/bin/consul -- agent -config-dir="${CONSUL_DIR}" + eend $? +} + +stop() { + local rv=0 + ebegin "Stopping consul" + start-stop-daemon --stop --quiet --pidfile "${CONSUL_PID}" + rm -f "${CONSUL_PID}" + eend $? +} + +reload() { + if ! service_started "${SVCNAME}" ; then + eerror "${SVCNAME} isn't running" + return 1 + fi + checkconfig || return 1 + /usr/local/bin/consul reload + eend $? +}