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
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions armada_backend/consul_config.py
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion armada_backend/models/ships.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down
19 changes: 13 additions & 6 deletions armada_backend/run_consul.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down
Binary file added bin/consul-1.0.0
Binary file not shown.
Binary file added bin/consul-1.0.1-rc1
Binary file not shown.