Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions consul.openrc
Original file line number Diff line number Diff line change
@@ -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 $?
}
14 changes: 2 additions & 12 deletions consul/config.sls
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions consul/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ consul:
datacenter: "main"
register: []
scripts: []
startup_params: ""
58 changes: 58 additions & 0 deletions consul/files/consul.openrc
Original file line number Diff line number Diff line change
@@ -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 $?
}
4 changes: 2 additions & 2 deletions consul/files/consul.service
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ 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
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/local/bin/consul agent -config-dir=/etc/consul.d {{ salt['pillar.get']('consul:startup_params', '') }}
ExecReload=/bin/sh -c "/usr/local/bin/consul validate /etc/consul.d && /bin/kill -HUP $MAINPID"
KillSignal=TERM
User=consul

Expand Down
8 changes: 4 additions & 4 deletions consul/install.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
7 changes: 6 additions & 1 deletion consul/service.sls
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ 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
- 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
Expand All @@ -24,5 +29,5 @@ consul-service:
- enable: True
- watch:
- file: consul-init-file

- file: /etc/consul.d/*
{%- endif %}
3 changes: 2 additions & 1 deletion pillar.example
Original file line number Diff line number Diff line change
@@ -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
Expand Down