From 6c80eab762dc1b41d059f61764ca9ddff1ef6886 Mon Sep 17 00:00:00 2001 From: Nicola Peditto Date: Mon, 4 Mar 2019 11:42:37 +0100 Subject: [PATCH] Release v0.4.7: WSTUN socket recovery fixed. Web-UI improved. Installation guides updated. Change-Id: I959677109e4f4b1d0bf07d689f5abdd453da0f97 --- README.rst | 2 +- doc/installation/raspberry_pi_3.rst | 37 ++++------ doc/installation/ubuntu1604.rst | 31 +++----- iotronic_lightningrod/common/utils.py | 36 ++++++--- iotronic_lightningrod/modules/rest_manager.py | 13 +++- .../modules/web/templates/config.html | 73 ++++++++++++------- utils/docker/arm/Dockerfile | 2 +- utils/docker/x86_64/Dockerfile | 2 +- 8 files changed, 112 insertions(+), 84 deletions(-) diff --git a/README.rst b/README.rst index 62908bd..c415326 100644 --- a/README.rst +++ b/README.rst @@ -15,7 +15,7 @@ board-side probe. Installation guides ------------------- -* `Raspberry Pi 2/3 `_. +* `Raspberry Pi 3 `_. * `Ubuntu 16.04 `_. diff --git a/doc/installation/raspberry_pi_3.rst b/doc/installation/raspberry_pi_3.rst index 5041e6c..85a60fc 100644 --- a/doc/installation/raspberry_pi_3.rst +++ b/doc/installation/raspberry_pi_3.rst @@ -1,7 +1,7 @@ -IoTronic Lightning-rod installation guide for Raspberry Pi 2/3 -============================================================== +IoTronic Lightning-rod installation guide for Raspberry Pi 3 +============================================================ -We tested this procedure on a Raspberry Pi 2/3 board (Raspbian). +We tested this procedure on a Raspberry Pi 3 (Raspbian). Requirements ~~~~~~~~~~~~ @@ -57,8 +57,8 @@ Iotronic deployment lr_install -Execution: -~~~~~~~~~~ +Execution +~~~~~~~~~ :: systemctl start lightning-rod.service @@ -66,33 +66,26 @@ Execution: tail -f /var/log/iotronic/lightning-rod.log Iotronic setup -'''''''''''''' -- Web-UI configuration: +~~~~~~~~~~~~~~ +**Web-UI url:** :: http://:1474/config -Registration Agent URL: ws(s)://:/ -Registration Code: +There you need to provide the following information: + +- **Registration Agent URL:** ws(s)://:/ + + It is the url used to reach Iotronic registration agent (provided by the infrastructure): you have specify the IP address/domain name followed by the port (crossbar listening port, e.g. 8181) -- Manual configuration (first registration only) +- **Registration Code:** -:: + It is the code specified during the device registration to identify it (the first time). - lr_configure -Arguments required: - * , token released by IoTronic registration procedure - * , IoTronic Crossbar server WAMP URL: - ws(s)://:/ - -e.g. -:: - - lr_configure Troubleshooting: ~~~~~~~~~~~~~~~~ @@ -101,4 +94,4 @@ Troubleshooting: It is a dependency of Autobahn package **Solution:** - pip3 install cborregistration only) \ No newline at end of file + pip3 install cbor \ No newline at end of file diff --git a/doc/installation/ubuntu1604.rst b/doc/installation/ubuntu1604.rst index 002958d..158b992 100644 --- a/doc/installation/ubuntu1604.rst +++ b/doc/installation/ubuntu1604.rst @@ -61,8 +61,8 @@ Iotronic deployment lr_install -Execution: -~~~~~~~~~~ +Execution +~~~~~~~~~ :: systemctl start lightning-rod.service @@ -70,33 +70,26 @@ Execution: tail -f /var/log/iotronic/lightning-rod.log Iotronic setup -'''''''''''''' -- Web-UI configuration: +~~~~~~~~~~~~~~ +**Web-UI url:** :: http://:1474/config -Registration Agent URL: ws(s)://:/ -Registration Code: +There you need to provide the following information: + +- **Registration Agent URL:** ws(s)://:/ + + It is the url used to reach Iotronic registration agent (provided by the infrastructure): you have specify the IP address/domain name followed by the port (crossbar listening port, e.g. 8181) -- Manual configuration (first registration only) +- **Registration Code:** -:: + It is the code specified during the device registration to identify it (the first time). - lr_configure -Arguments required: - * , token released by IoTronic registration procedure - * , IoTronic Crossbar server WAMP URL: - ws(s)://:/ - -e.g. -:: - - lr_configure Troubleshooting: ~~~~~~~~~~~~~~~~ @@ -105,4 +98,4 @@ Troubleshooting: It is a dependency of Autobahn package **Solution:** - pip3 install cborregistration only) \ No newline at end of file + pip3 install cbor \ No newline at end of file diff --git a/iotronic_lightningrod/common/utils.py b/iotronic_lightningrod/common/utils.py index 3d381c1..15fc576 100644 --- a/iotronic_lightningrod/common/utils.py +++ b/iotronic_lightningrod/common/utils.py @@ -68,6 +68,7 @@ def destroyWampSocket(): LR_PID = os.getpid() try: + process = subprocess.Popen( ["gdb", "-p", str(LR_PID)], stdin=subprocess.PIPE, @@ -75,18 +76,33 @@ def destroyWampSocket(): ) proc = psutil.Process() - print("WAMP RECOVERY: " + str(proc.connections()[0])) - ws_fd = proc.connections()[0].fd - first = b"call ((void(*)()) shutdown)(" - fd = str(ws_fd).encode('ascii') - last = b"u,0)\nquit\ny" - commands = b"%s%s%s" % (first, fd, last) - process.communicate(input=commands)[0] + conn_list = proc.connections() + proc_msg = "WAMP RECOVERY: " + str(conn_list) + print(proc_msg) + LOG.info(proc_msg) - msg = "Websocket-Zombie closed! Restoring..." - LOG.warning(msg) - print(msg) + for socks in conn_list: + # print(socks.raddr, socks.fd) + if socks.raddr != (): + # print(socks.raddr.port, socks.fd) + socks_msg = "FD selected: " + str(socks.fd) \ + + " [port " + str(socks.raddr.port) + "]" + + print(socks_msg) + LOG.info(socks_msg) + + ws_fd = socks.fd + first = b"call ((void(*)()) shutdown)(" + fd = str(ws_fd).encode('ascii') + last = b"u,0)\nquit\ny" + commands = b"%s%s%s" % (first, fd, last) + process.communicate(input=commands)[0] + + msg = "Websocket-Zombie closed! Restoring..." + LOG.warning(msg) + print(msg) + break except Exception as e: LOG.warning("RPC-ALIVE - destroyWampSocket error: " + str(e)) diff --git a/iotronic_lightningrod/modules/rest_manager.py b/iotronic_lightningrod/modules/rest_manager.py index b12e6bf..e793584 100644 --- a/iotronic_lightningrod/modules/rest_manager.py +++ b/iotronic_lightningrod/modules/rest_manager.py @@ -208,7 +208,8 @@ class RestManager(Module.Module): return output.decode('ascii').strip() def identity_restore(filepath): - bashCommand = "device_bkp_rest restore " + filepath + "| tail -n 1" + bashCommand = "device_bkp_rest restore " \ + + str(filepath) + "| tail -n 1" process = subprocess.Popen(bashCommand, stdout=subprocess.PIPE, shell=True) output, error = process.communicate() @@ -227,7 +228,8 @@ class RestManager(Module.Module): @app.route('/restore', methods=['GET', 'POST']) def upload_file(): - if 'username' in f_session: + if ('username' in f_session) or str(board.status) == "first_boot": + f_session['status'] = str(board.status) if request.form.get('dev_rst_btn') == 'Device restore': @@ -268,7 +270,14 @@ class RestManager(Module.Module): app.config['UPLOAD_FOLDER'], filename ) + + bpath = bpath.replace(" ", "") + bpath = bpath.replace("(", "-") + bpath = bpath.replace(")", "-") + + print("--> storage path: " + str(bpath)) file.save(bpath) + out_res = identity_restore(bpath) print("--> restore result: " + str(out_res)) # restart LR diff --git a/iotronic_lightningrod/modules/web/templates/config.html b/iotronic_lightningrod/modules/web/templates/config.html index 6c7cf81..6c9203e 100644 --- a/iotronic_lightningrod/modules/web/templates/config.html +++ b/iotronic_lightningrod/modules/web/templates/config.html @@ -98,6 +98,46 @@ $(function(){

+ +
+
+
Restore identity
+
+
+
+ +
+ + + + + + + + + + + + + + + + +
+ +
+
+ + +
+
+ +
+ +
+ + @@ -179,9 +206,12 @@ $(function(){ +--> + {% else %} + - @@ -260,6 +276,7 @@ $(function(){ +-->

diff --git a/utils/docker/arm/Dockerfile b/utils/docker/arm/Dockerfile index 386860f..e36a0be 100755 --- a/utils/docker/arm/Dockerfile +++ b/utils/docker/arm/Dockerfile @@ -12,7 +12,7 @@ RUN sed -i 's/# server_names_hash_bucket_size 64;/server_names_hash_bucket_size RUN rm -rf /var/lib/apt/lists/* -RUN npm install -g --unsafe @mdslab/wstun@1.0.9 && npm cache --force clean +RUN npm install -g --unsafe @mdslab/wstun@1.0.10 && npm cache --force clean RUN pip3 install iotronic-lightningrod diff --git a/utils/docker/x86_64/Dockerfile b/utils/docker/x86_64/Dockerfile index f278f9c..db35699 100644 --- a/utils/docker/x86_64/Dockerfile +++ b/utils/docker/x86_64/Dockerfile @@ -12,7 +12,7 @@ RUN sed -i 's/# server_names_hash_bucket_size 64;/server_names_hash_bucket_size RUN rm -rf /var/lib/apt/lists/* -RUN npm install -g --unsafe @mdslab/wstun@1.0.9 && npm cache --force clean +RUN npm install -g --unsafe @mdslab/wstun@1.0.10 && npm cache --force clean RUN pip3 install iotronic-lightningrod