From 25ee8ba480654c267fef67b4d60b11d8609f756d Mon Sep 17 00:00:00 2001 From: Eric Renfro Date: Thu, 17 May 2018 21:35:09 -0400 Subject: [PATCH] Added configuration handler. --- fabio/config.sls | 17 +++++++++++++++++ fabio/defaults.yaml | 7 +++++-- fabio/files/fabio.cfg | 3 +++ fabio/files/fabio.service | 2 +- fabio/init.sls | 2 +- fabio/install.sls | 4 ++-- fabio/service.sls | 3 ++- 7 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 fabio/files/fabio.cfg diff --git a/fabio/config.sls b/fabio/config.sls index 1f054ff..4eb9b00 100644 --- a/fabio/config.sls +++ b/fabio/config.sls @@ -1,5 +1,22 @@ {%- from slspath + '/map.jinja' import fabio with context -%} +fabio-config: + file.managed: + - name: {{ fabio.config_file }} + - source: salt://{{ slspath }}/files/fabio.cfg + - context: + config: {{ fabio.config }} + - template: jinja + - user: {{ fabio.user}} + - group: {{ fabio.group }} + - mode: 0640 + - require: + - user: fabio-user + {%- if fabio.service %} + - watch_in: + - service: fabio + {%- endif %} + {# fabio-config: file.serialize: diff --git a/fabio/defaults.yaml b/fabio/defaults.yaml index 5b95d37..182bbef 100644 --- a/fabio/defaults.yaml +++ b/fabio/defaults.yaml @@ -8,6 +8,9 @@ fabio: user: fabio group: fabio + config_file: /etc/fabio/fabio.cfg + consul_address: localhost:8500 + data_dir: /var/fabio + config: - consul_address: localhost:8500 - data_dir: /var/fabio + proxy.addr: :80,:9999 diff --git a/fabio/files/fabio.cfg b/fabio/files/fabio.cfg new file mode 100644 index 0000000..8c68688 --- /dev/null +++ b/fabio/files/fabio.cfg @@ -0,0 +1,3 @@ +{%- for key, val in config.iteritems() %} +{{ key }} = {{ val }} +{%- endfor %} \ No newline at end of file diff --git a/fabio/files/fabio.service b/fabio/files/fabio.service index 3f3d43b..4783089 100644 --- a/fabio/files/fabio.service +++ b/fabio/files/fabio.service @@ -5,7 +5,7 @@ After=network.target [Service] EnvironmentFile=-/etc/{% if grains['os_family'] == 'Debian' %}default{% else %}sysconfig{% endif %}/fabio -ExecStart=/usr/local/bin/fabio -registry.consul.addr {{ consul_address }} +ExecStart=/usr/local/bin/fabio -cfg {{ config_file }} -registry.consul.addr {{ consul_address }} ExecReload=/bin/kill -HUP $MAINPID User={{ user }} Group={{ group }} diff --git a/fabio/init.sls b/fabio/init.sls index 2956807..48610da 100644 --- a/fabio/init.sls +++ b/fabio/init.sls @@ -2,5 +2,5 @@ include: - {{ slspath }}.install - {# - {{ slspath }}.config #} + - {{ slspath }}.config - {{ slspath }}.service diff --git a/fabio/install.sls b/fabio/install.sls index b3e6555..71eec4b 100644 --- a/fabio/install.sls +++ b/fabio/install.sls @@ -15,7 +15,7 @@ fabio-user: - name: {{ fabio.user }} - groups: - {{ fabio.group }} - - home: {{ salt['user.info'](fabio.user)['home']|default(fabio.config.data_dir) }} + - home: {{ salt['user.info'](fabio.user)['home']|default(fabio.data_dir) }} - createhome: False - system: True - require: @@ -31,7 +31,7 @@ fabio-config-dir: fabio-data-dir: file.directory: - - name: {{ fabio.config.data_dir }} + - name: {{ fabio.data_dir }} - makedirs: True - user: {{ fabio.user }} - group: {{ fabio.group }} diff --git a/fabio/service.sls b/fabio/service.sls index 8e0570e..e1f62f1 100644 --- a/fabio/service.sls +++ b/fabio/service.sls @@ -26,7 +26,8 @@ fabio-init-file: - context: user: {{ fabio.user }} group: {{ fabio.group }} - consul_address: {{ fabio.config.consul_address }} + config_file: {{ fabio.config_file }} + consul_address: {{ fabio.consul_address }} - mode: 0644 {%- elif salt['test.provider']('service') == 'upstart' %} - source: salt://{{ slspath }}/files/fabio.upstart