CORD-842 automatically restart chameleon when API changes
Change-Id: I9695690e401b851289127c6ffa5aadb76fe954e8
diff --git a/xos/grpc/grpc_server.py b/xos/grpc/grpc_server.py
index 7649640..cb5b2a7 100644
--- a/xos/grpc/grpc_server.py
+++ b/xos/grpc/grpc_server.py
@@ -154,6 +154,27 @@
activator_func(service, self.server)
+def restart_chameleon():
+ import docker
+
+ def find_container(client, search_name):
+ for c in client.containers():
+ for c_name in c["Names"]:
+ if (search_name in c_name):
+ return c
+ return None
+
+ client=docker.from_env()
+ chameleon_container = find_container(client, "xos_chameleon_1")
+ if chameleon_container:
+ try:
+ # the first attempt always fails with 404 error
+ # docker-py bug?
+ client.restart(chameleon_container["Names"][0])
+ except:
+ client.restart(chameleon_container["Names"][0])
+
+
# This is to allow running the GRPC server in stand-alone mode
if __name__ == '__main__':
@@ -161,6 +182,8 @@
server = XOSGrpcServer().start()
+ restart_chameleon()
+
import time
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
try:
diff --git a/xos/synchronizers/onboarding/xosbuilder.py b/xos/synchronizers/onboarding/xosbuilder.py
index ac6f566..864e972 100644
--- a/xos/synchronizers/onboarding/xosbuilder.py
+++ b/xos/synchronizers/onboarding/xosbuilder.py
@@ -344,6 +344,9 @@
"extra_hosts": extra_hosts,
"volumes": volume_list}
+ # The core needs access to docker so it can restart Chameleon
+ core_volume_list = volume_list + [{"host_path": "/var/run/docker.sock", "container_path": "/var/run/docker.sock", "read_only": False}]
+
containers["xos_core"] = {
"image": "xosproject/xos-ui",
"command": 'bash -c "cd grpc; bash ./start_grpc_server.sh"',
@@ -351,7 +354,7 @@
"ports": {"50055": "50055", "50051" : "50051"},
"external_links": external_links,
"extra_hosts": extra_hosts,
- "volumes": volume_list}
+ "volumes": core_volume_list}
if xos.no_start:
containers["xos_ui"]["command"] = "sleep 864000"