diff --git a/Dockerfile b/Dockerfile index 1c6506f7..0b7be206 100755 --- a/Dockerfile +++ b/Dockerfile @@ -6,8 +6,10 @@ RUN apt-get update && apt-get install -y rsync openssh-server libffi-dev libssl- RUN pip install paramiko web.py 'docker==2.4.2' raven contextlib2 ujson colored armada-heal # Consul -RUN curl -s https://releases.hashicorp.com/consul/0.7.5/consul_0.7.5_linux_amd64.zip | zcat > /usr/local/bin/consul \ - && chmod +x /usr/local/bin/consul +#RUN curl -s https://releases.hashicorp.com/consul/0.7.5/consul_0.7.5_linux_amd64.zip | zcat > /usr/local/bin/consul \ +# && chmod +x /usr/local/bin/consul +ADD bin/consul-1.0.1-rc1 /usr/local/bin/consul +#ADD bin/consul-1.0.0 /usr/local/bin/consul ADD ./armada_backend/supervisor/* /etc/supervisor/conf.d/ RUN rm -f /etc/supervisor/conf.d/local_magellan.conf diff --git a/armada_backend/consul_config.py b/armada_backend/consul_config.py index fee356e9..8ac8038e 100644 --- a/armada_backend/consul_config.py +++ b/armada_backend/consul_config.py @@ -1,6 +1,4 @@ -from armada_command.scripts.compat import json - -CONFIG_PATH = '/etc/consul.config' +CONFIG_PATH = '/etc/consul.json' # File where runtime settings are saved after something changes. RUNTIME_SETTINGS_PATH = '/opt/armada/runtime_settings.json' @@ -49,4 +47,4 @@ def get_consul_config(consul_mode, ship_ips, datacenter, ship_external_ip, ship_ {'type': 'keyprefix', 'prefix': 'services/{}/'.format(ship_name), 'handler': save_running_containers_cmd}, ] - return json.dumps(config, sort_keys=True, indent=4) + return config diff --git a/armada_backend/models/ships.py b/armada_backend/models/ships.py index 81fc6178..52e3e503 100644 --- a/armada_backend/models/ships.py +++ b/armada_backend/models/ships.py @@ -1,5 +1,6 @@ import os +import consul_config from armada_backend.utils import get_logger from armada_command.consul import kv from armada_command.consul.consul import consul_query @@ -36,7 +37,7 @@ def set_ship_name(new_name): kv.kv_remove(container) kv.kv_set('ships/{}/name'.format(ship_ip), new_name) kv.kv_set('ships/{}/ip'.format(new_name), ship_ip) - os.system('sed -i \'s|ships/{}/|ships/{}/|\' /etc/consul.config'.format(old_name, new_name)) + os.system('sed -i \'s|ships/{}/|ships/{}/|\' {}'.format(old_name, new_name, consul_config.CONFIG_PATH)) try: os.system('/usr/local/bin/consul reload') except Exception as e: diff --git a/armada_backend/run_consul.py b/armada_backend/run_consul.py index 8885412c..b401e888 100644 --- a/armada_backend/run_consul.py +++ b/armada_backend/run_consul.py @@ -45,17 +45,24 @@ def main(): ship_external_ip = get_external_ip() if ship_name is None: ship_name = ship_external_ip - consul_config_content = consul_config.get_consul_config(consul_mode, ship_ips, datacenter, ship_external_ip, - ship_name) + consul_config_dict = consul_config.get_consul_config(consul_mode, ship_ips, datacenter, ship_external_ip, ship_name) + + data_dir = consul_config_dict['data_dir'] + print(data_dir) + if not os.path.exists(data_dir): + os.makedirs(data_dir) + with open(os.path.join(data_dir, 'dummy'), 'w') as f: + f.write('') + + consul_config_content = json.dumps(consul_config_dict, sort_keys=True, indent=4) with open(consul_config.CONFIG_PATH, 'w') as config_file: config_file.write(consul_config_content) - command = '/usr/local/bin/consul agent -config-file {config_path}'.format(config_path=consul_config.CONFIG_PATH) - get_logger().info('RUNNING: %s', command) + command = ['consul', 'agent', '-config-file', consul_config.CONFIG_PATH, '-data-dir', data_dir] + get_logger().info('RUNNING: %s', ' '.join(command)) - args = command.split() - os.execv(args[0], args) + os.execvp(command[0], command) if __name__ == '__main__': diff --git a/bin/consul-1.0.0 b/bin/consul-1.0.0 new file mode 100755 index 00000000..c99ce478 Binary files /dev/null and b/bin/consul-1.0.0 differ diff --git a/bin/consul-1.0.1-rc1 b/bin/consul-1.0.1-rc1 new file mode 100755 index 00000000..4ff93803 Binary files /dev/null and b/bin/consul-1.0.1-rc1 differ