Skip to content

Commit

Permalink
Merge pull request #160 from trevorr/upstart-redhat
Browse files Browse the repository at this point in the history
Allow upstart to be used on non-Debian systems
  • Loading branch information
mattfinlayson authored Aug 18, 2016
2 parents 0e81e69 + df10349 commit a2e36e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
owner=root
group=root
mode=0644
when: consul_use_upstart and ansible_os_family == "Debian"
when: consul_use_upstart
notify:
- "{{ consul_restart_handler }}"

Expand Down
30 changes: 17 additions & 13 deletions templates/consul.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,30 @@ start on (local-filesystems and net-device-up IFACE!=lo)
stop on runlevel [016]

script

# Make sure to use all our CPUs, because Consul can block a scheduler thread

{% if consul_dynamic_bind %}
# Get the public IP
BIND=`ifconfig eth0 | grep "inet addr" | awk '{ print substr($2,6) }'`
# Get the public IP
BIND=`ifconfig eth0 | grep "inet addr" | awk '{ print substr($2,6) }'`
{% endif %}

{% if consul_client_address_bind %}
# Get the public IP
CLIENT_BIND=`ifconfig eth0 | grep "inet addr" | awk '{ print substr($2,6) }'`
# Get the public IP
CLIENT_BIND=`ifconfig eth0 | grep "inet addr" | awk '{ print substr($2,6) }'`
{% endif %}

sudo setcap CAP_NET_BIND_SERVICE=+eip {{ consul_home }}/bin/consul; exec sudo -u {{ consul_user }} -g {{ consul_group }} GOMAXPROCS=`nproc` {{ consul_home }}/bin/consul agent \
# Allow non-root to bind to privileged ports (if used)
setcap CAP_NET_BIND_SERVICE=+eip {{ consul_home }}/bin/consul

# Set GOMAXPROCS to use all our CPUs, because Consul can block a scheduler thread
# Use su to become consul user non-interactively on old Upstart versions (see http://superuser.com/a/234541/76168)
exec su -s /bin/sh -c 'GOMAXPROCS=`nproc` exec "$0" "$@" &>>{{ consul_log_file }}' consul -- /opt/consul/bin/consul agent \
{% if consul_dynamic_bind %}
-bind=$BIND \
-bind=$BIND \
{% endif %}
{% if consul_client_address_bind %}
-client=$CLIENT_BIND \
-client=$CLIENT_BIND \
{% endif %}
-config-dir {{ consul_config_dir }} \
-config-file={{ consul_config_file }} \
>> {{ consul_log_file }} 2>&1
-config-dir={{ consul_config_dir }} \
-config-file={{ consul_config_file }}
end script

{% if consul_leave_on_terminate -%}
Expand All @@ -37,4 +38,7 @@ pre-stop exec {{ consul_home }}/bin/consul leave
respawn
respawn limit 10 10

# Avoid Upstart re-spawning the process upon `consul leave`
normal exit 0 INT

kill timeout 10

0 comments on commit a2e36e7

Please sign in to comment.