From f351ff5cafc47b8e5fc1412f7bca8b0be0b6a929 Mon Sep 17 00:00:00 2001 From: Nicola Peditto Date: Thu, 10 Jan 2019 14:32:56 +0100 Subject: [PATCH] Release Lightning-rod v0.4.5: - Docker procedures updated - Board registration procedure fixed - Rest Manager updated Change-Id: I4c9bb728d3f9696b73f902754e57ec0cb89bbae1 --- .../docker/{rpi_docker.md => arm_docker.md} | 4 +- doc/installation/docker/x86_64_docker.md | 4 +- iotronic_lightningrod/Board.py | 6 +- iotronic_lightningrod/modules/rest_manager.py | 6 +- .../modules/service_manager.py | 1 - utils/docker/arm/Dockerfile | 4 ++ utils/docker/arm/data/lr_configure | 55 +++++++++++++++++++ utils/docker/x86_64/Dockerfile | 4 ++ utils/docker/x86_64/data/lr_configure | 55 +++++++++++++++++++ 9 files changed, 130 insertions(+), 9 deletions(-) rename doc/installation/docker/{rpi_docker.md => arm_docker.md} (58%) create mode 100755 utils/docker/arm/data/lr_configure create mode 100755 utils/docker/x86_64/data/lr_configure diff --git a/doc/installation/docker/rpi_docker.md b/doc/installation/docker/arm_docker.md similarity index 58% rename from doc/installation/docker/rpi_docker.md rename to doc/installation/docker/arm_docker.md index 605fc30..e7ee293 100644 --- a/doc/installation/docker/rpi_docker.md +++ b/doc/installation/docker/arm_docker.md @@ -7,6 +7,6 @@ GitHub repo: ``` docker run -d --privileged \ -v lr_var:/var/lib/iotronic -v lr_le:/etc/letsencrypt/ \ ---net=host --restart unless-stopped \ ---name=lightning-rod mdslab/rpi-openstack-iotronic-lightning-rod +-v lr_nginx:/etc/nginx -v lr_confs:/etc/iotronic/ \ +--net=host --restart unless-stopped --name=lightning-rod mdslab/arm-openstack-iotronic-lightning-rod ``` diff --git a/doc/installation/docker/x86_64_docker.md b/doc/installation/docker/x86_64_docker.md index 3abf527..9ab1822 100644 --- a/doc/installation/docker/x86_64_docker.md +++ b/doc/installation/docker/x86_64_docker.md @@ -7,6 +7,6 @@ GitHub repo: ``` docker run -d --privileged \ -v lr_var:/var/lib/iotronic -v lr_le:/etc/letsencrypt/ \ ---net=host --restart unless-stopped \ ---name=lightning-rod mdslab/openstack-iotronic-lightning-rod +-v lr_nginx:/etc/nginx -v lr_confs:/etc/iotronic/ \ +--net=host --restart unless-stopped --name=lightning-rod mdslab/openstack-iotronic-lightning-rod ``` diff --git a/iotronic_lightningrod/Board.py b/iotronic_lightningrod/Board.py index dff6f86..2b3ea58 100644 --- a/iotronic_lightningrod/Board.py +++ b/iotronic_lightningrod/Board.py @@ -113,7 +113,6 @@ class Board(object): if self.status == None: LOG.warning("settings.json file exception: " + str(err)) - # STATUS REGISTERED try: self.code = board_config['code'] @@ -124,8 +123,8 @@ class Board(object): FIRST_BOOT = True LOG.info("FIRST BOOT procedure started") self.status = "first_boot" - else: + self.status = None # change to pre-registration status LOG.info('First registration board settings: ') LOG.info(' - code: ' + str(self.code)) self.getWampAgent(self.iotronic_config) @@ -144,7 +143,8 @@ class Board(object): LOG.info('WAMP Agent settings:') except Exception: - if (self.status is None) | (self.status == "registered"): + if (self.status is None) | (self.status == "registered") | \ + (self.status == "first_boot"): self.wamp_config = \ config['iotronic']['wamp']['registration-agent'] LOG.info('Registration Agent settings:') diff --git a/iotronic_lightningrod/modules/rest_manager.py b/iotronic_lightningrod/modules/rest_manager.py index be7f477..be05e1e 100644 --- a/iotronic_lightningrod/modules/rest_manager.py +++ b/iotronic_lightningrod/modules/rest_manager.py @@ -78,6 +78,10 @@ class RestManager(Module.Module): else: wstun_status = "Offline" + service_list = service_manager.services_list() + if service_list == "": + service_list = "no services exposed!" + info = { 'board_id': board.uuid, 'board_name': board.name, @@ -88,7 +92,7 @@ class RestManager(Module.Module): 'wstun_status': wstun_status, 'board_reg_status': str(board.status), 'iotronic_status': str(iotronic_status(board.status)), - 'service_list': str(service_manager.services_list()) + 'service_list': str(service_list) } return render_template('status.html', **info) diff --git a/iotronic_lightningrod/modules/service_manager.py b/iotronic_lightningrod/modules/service_manager.py index 4304e0b..95da6b9 100644 --- a/iotronic_lightningrod/modules/service_manager.py +++ b/iotronic_lightningrod/modules/service_manager.py @@ -592,7 +592,6 @@ class ServiceManager(Module.Module): "WSTUN server is offline! Retry " + str(count_ws) + "/5..." ) time.sleep(randint(3, 6)) - global ws_server_alive ws_server_alive = sock.connect_ex( (self.wstun_ip, int(self.wstun_port)) ) diff --git a/utils/docker/arm/Dockerfile b/utils/docker/arm/Dockerfile index 9301426..c3e20b4 100755 --- a/utils/docker/arm/Dockerfile +++ b/utils/docker/arm/Dockerfile @@ -16,6 +16,10 @@ RUN npm install -g --unsafe @mdslab/wstun@1.0.9 && npm cache --force clean RUN pip3 install iotronic-lightningrod +RUN sed -i "s|listen 80 default_server;|listen 50000 default_server;|g" /etc/nginx/sites-available/default +RUN sed -i "s|80 default_server;|50000 default_server;|g" /etc/nginx/sites-available/default + +COPY data/lr_configure /usr/local/bin/lr_configure COPY data/lr_install /usr/local/bin/lr_install COPY data/startLR /usr/local/bin/startLR diff --git a/utils/docker/arm/data/lr_configure b/utils/docker/arm/data/lr_configure new file mode 100755 index 0000000..98f33b2 --- /dev/null +++ b/utils/docker/arm/data/lr_configure @@ -0,0 +1,55 @@ +#!/usr/bin/python3 + +# Copyright 2017 MDSLAB - University of Messina +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import os +import sys + +if len(sys.argv) == 1: + + print('Arguments required:') + print(" with '-c' specify: ") + print(" without '-c' specify: ") + +else: + + if sys.argv[1] == "-c": + + if len(sys.argv) < 5: + print('Arguments required: ' + + ' ' + + ' ' + + '', + str(sys.argv) + ) + else: + os.system('sed -i "s|\\"code\\":.*|\\"code\\": \\"' + + sys.argv[2] + '\\"|g" ' + sys.argv[4] + '/settings.json') + os.system('sed -i "s|\\"url\\":.*|\\"url\\": \\"' + + sys.argv[3] + '\\",|g" ' + sys.argv[4] + '/settings.json') + os.system('sed -i "s||s4t|g" ' + + sys.argv[4] + '/settings.json') + + else: + if len(sys.argv) < 3: + print('Arguments required: ', + str(sys.argv)) + else: + os.system('sed -i "s|\\"code\\":.*|\\"code\\": \\"' + + sys.argv[1] + '\\"|g" /etc/iotronic/settings.json') + os.system('sed -i "s|\\"url\\":.*|\\"url\\": \\"' + + sys.argv[2] + '\\",|g" /etc/iotronic/settings.json') + os.system('sed -i "s||s4t|g" /etc/iotronic/settings.json') diff --git a/utils/docker/x86_64/Dockerfile b/utils/docker/x86_64/Dockerfile index 4542ec7..1dfd81a 100644 --- a/utils/docker/x86_64/Dockerfile +++ b/utils/docker/x86_64/Dockerfile @@ -16,6 +16,10 @@ RUN npm install -g --unsafe @mdslab/wstun@1.0.9 && npm cache --force clean RUN pip3 install iotronic-lightningrod +RUN sed -i "s|listen 80 default_server;|listen 50000 default_server;|g" /etc/nginx/sites-available/default +RUN sed -i "s|80 default_server;|50000 default_server;|g" /etc/nginx/sites-available/default + +COPY data/lr_configure /usr/local/bin/lr_configure COPY data/lr_install /usr/local/bin/lr_install COPY data/startLR /usr/local/bin/startLR diff --git a/utils/docker/x86_64/data/lr_configure b/utils/docker/x86_64/data/lr_configure new file mode 100755 index 0000000..98f33b2 --- /dev/null +++ b/utils/docker/x86_64/data/lr_configure @@ -0,0 +1,55 @@ +#!/usr/bin/python3 + +# Copyright 2017 MDSLAB - University of Messina +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import os +import sys + +if len(sys.argv) == 1: + + print('Arguments required:') + print(" with '-c' specify: ") + print(" without '-c' specify: ") + +else: + + if sys.argv[1] == "-c": + + if len(sys.argv) < 5: + print('Arguments required: ' + + ' ' + + ' ' + + '', + str(sys.argv) + ) + else: + os.system('sed -i "s|\\"code\\":.*|\\"code\\": \\"' + + sys.argv[2] + '\\"|g" ' + sys.argv[4] + '/settings.json') + os.system('sed -i "s|\\"url\\":.*|\\"url\\": \\"' + + sys.argv[3] + '\\",|g" ' + sys.argv[4] + '/settings.json') + os.system('sed -i "s||s4t|g" ' + + sys.argv[4] + '/settings.json') + + else: + if len(sys.argv) < 3: + print('Arguments required: ', + str(sys.argv)) + else: + os.system('sed -i "s|\\"code\\":.*|\\"code\\": \\"' + + sys.argv[1] + '\\"|g" /etc/iotronic/settings.json') + os.system('sed -i "s|\\"url\\":.*|\\"url\\": \\"' + + sys.argv[2] + '\\",|g" /etc/iotronic/settings.json') + os.system('sed -i "s||s4t|g" /etc/iotronic/settings.json')