diff --git a/.gitignore b/.gitignore index 06c4263..3c8d148 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ iotronic_lightningrod.egg-info build AUTHORS Authors -ChangeLog \ No newline at end of file +ChangeLog +*.md \ No newline at end of file diff --git a/README.rst b/README.rst index 7c8517c..b2213e5 100644 --- a/README.rst +++ b/README.rst @@ -11,7 +11,13 @@ board-side probe. * Source: https://github.com/openstack/iotronic-lightning-rod * Bugs: https://bugs.launchpad.net/iotronic-lightning-rod -Features --------- -* TODO +Installation guides +------------------- + +* `Arduino YUN `_. + +* `Ubuntu 16.04 `_. + +* `Raspberry Pi 3 `_. + diff --git a/doc/installation/arduino_yun.rst b/doc/installation/arduino_yun.rst new file mode 100644 index 0000000..8448621 --- /dev/null +++ b/doc/installation/arduino_yun.rst @@ -0,0 +1,138 @@ +IoTronic Lightning-rod installation guide for Arduino YUN +========================================================= + +We tested this procedure on a Arduino YUN board with OpenWRT LininoIO +image. + +Install from source code +------------------------ + +Install requirements +~~~~~~~~~~~~~~~~~~~~ + +Install Python and PIP: +''''''''''''''''''''''' + +:: + + opkg update + opkg install python-setuptools + easy_install pip + +Install dependencies +'''''''''''''''''''' + +:: + + opkg install git bzip2 python-netifaces + pip install --no-cache-dir zope.interface pyserial Babel oslo.config oslo.log + easy_install httplib2 + +Install Autobahn: +''''''''''''''''' + +:: + + # Install Twisted: + wget --no-check-certificate https://pypi.python.org/packages/source/T/Twisted/Twisted-14.0.2.tar.bz2 + bzip2 -d Twisted-14.0.2.tar.bz2 + tar -xvf Twisted-14.0.2.tar + cd Twisted-14.0.2/ + vi setup.py + + comment line 63: + #conditionalExtensions=getExtensions(), + + python setup.py install + cd /opt/ + rm -rf /opt/Twisted-14.0.2* + +:: + + easy_install autobahn + +Set up environment: +~~~~~~~~~~~~~~~~~~~ + +:: + + mkdir -p /var/lib/iotronic + mkdir /var/lib/iotronic/plugins + mkdir /var/log/iotronic/ + mkdir /etc/iotronic + +Install Lightning-rod +~~~~~~~~~~~~~~~~~~~~~ + +Get source code +''''''''''''''' + +:: + + cd /var/lib/iotronic + git clone git://github.com/MDSLab/iotronic-lightning-rod-agent.git + mv iotronic-lightning-rod-agent/ iotronic-lightning-rod/ + +Deployment +'''''''''' + +:: + + cd iotronic-lightning-rod/ + cp etc/iotronic/iotronic.conf /etc/iotronic/ + cp settings.example.json /var/lib/iotronic/settings.json + cp plugins.example.json /var/lib/iotronic/plugins.json + cp etc/init.d/lightning-rod /etc/init.d/lightning-rod + chmod +x /etc/init.d/lightning-rod + touch /var/log/iotronic/lightning-rod.log + +- Edit configuration file: + +nano /var/lib/iotronic/settings.json + +:: + + { + "iotronic": { + "board": { + "token": "" + }, + "wamp": { + "registration-agent": { + "url": "ws://:/", + "realm": "" + } + } + } + } + +- Set up logrotate: + +nano /etc/logrotate.d/lightning-rod.log + +:: + + /var/log/iotronic/lightning-rod.log { + weekly + rotate = 3 + compress + su root root + maxsize 5M + } + +Building +'''''''' + +:: + + cd /var/lib/iotronic/iotronic-lightning-rod/ + python setup.py install + +Execution: +~~~~~~~~~~ + +:: + + /etc/init.d/lightning-rod restart + + tail -f /var/log/iotronic/lightning-rod.log \ No newline at end of file diff --git a/doc/installation/raspberry_pi_3.rst b/doc/installation/raspberry_pi_3.rst new file mode 100644 index 0000000..593051c --- /dev/null +++ b/doc/installation/raspberry_pi_3.rst @@ -0,0 +1,99 @@ +IoTronic Lightning-rod installation guide for Raspberry Pi 3 +============================================================ + +We tested this procedure on a Raspberry Pi 3 board. + +Install from source code +------------------------ + +Install requirements +~~~~~~~~~~~~~~~~~~~~ + +:: + + pip install oslo-config oslo_log twisted autobahn httplib2 + +Set up environment: +~~~~~~~~~~~~~~~~~~~ + +:: + + mkdir -p /var/lib/iotronic + mkdir /var/lib/iotronic/plugins + mkdir /var/log/iotronic/ + mkdir /etc/iotronic + +Install Lightning-rod +~~~~~~~~~~~~~~~~~~~~~ + +Get source code +''''''''''''''' + +:: + + cd /var/lib/iotronic + git clone git://github.com/MDSLab/iotronic-lightning-rod-agent.git + mv iotronic-lightning-rod-agent/ iotronic-lightning-rod/ + +Deployment +'''''''''' + +:: + + cd iotronic-lightning-rod/ + cp etc/iotronic/iotronic.conf /etc/iotronic/ + cp settings.example.json /var/lib/iotronic/settings.json + cp plugins.example.json /var/lib/iotronic/plugins.json + cp etc/systemd/system/s4t-lightning-rod.service /etc/systemd/system/lightning-rod.service + chmod +x /etc/systemd/system/lightning-rod.service + systemctl daemon-reload + +- Edit configuration file: + + - nano /var/lib/iotronic/settings.json + + :: + + { + "iotronic": { + "board": { + "token": "" + }, + "wamp": { + "registration-agent": { + "url": "ws://:/", + "realm": "" + } + } + } + } + +- setup logrotate: +- nano /etc/logrotate.d/lightning-rod.log + + :: + + /var/log/iotronic/lightning-rod.log { + weekly + rotate = 3 + compress + su root root + maxsize 5M + } + +Building +'''''''' + +:: + + cd /var/lib/iotronic/iotronic-lightning-rod/ + python setup.py install + +Execution: +~~~~~~~~~~ + +:: + + systemctl restart lightning-rod.service + + tail -f /var/log/iotronic/lightning-rod.log \ No newline at end of file diff --git a/doc/installation/ubuntu1604.rst b/doc/installation/ubuntu1604.rst new file mode 100644 index 0000000..5a5a82b --- /dev/null +++ b/doc/installation/ubuntu1604.rst @@ -0,0 +1,100 @@ +IoTronic Lightning-rod installation guide for Ubuntu 16.04 +========================================================== + +We tested this procedure on a Ubuntu 16.04 (also within a LXD +container). Everything needs to be run as root. + +Install from source code via Git +-------------------------------- + +Install requirements +~~~~~~~~~~~~~~~~~~~~ + +:: + + pip install oslo-config oslo_log twisted autobahn httplib2 + +Set up environment: +~~~~~~~~~~~~~~~~~~~ + +:: + + mkdir -p /var/lib/iotronic + mkdir /var/lib/iotronic/plugins + mkdir /var/log/iotronic/ + mkdir /etc/iotronic + +Install Lightning-rod +~~~~~~~~~~~~~~~~~~~~~ + +Get source code +''''''''''''''' + +:: + + cd /var/lib/iotronic + git clone git://github.com/MDSLab/iotronic-lightning-rod-agent.git + mv iotronic-lightning-rod-agent/ iotronic-lightning-rod/ + +Deployment +'''''''''' + +:: + + cd iotronic-lightning-rod/ + cp etc/iotronic/iotronic.conf /etc/iotronic/ + cp settings.example.json /var/lib/iotronic/settings.json + cp plugins.example.json /var/lib/iotronic/plugins.json + cp etc/systemd/system/s4t-lightning-rod.service /etc/systemd/system/lightning-rod.service + chmod +x /etc/systemd/system/lightning-rod.service + systemctl daemon-reload + +- Edit configuration file: + + - nano /var/lib/iotronic/settings.json + + :: + + { + "iotronic": { + "board": { + "token": "" + }, + "wamp": { + "registration-agent": { + "url": "ws://:/", + "realm": "" + } + } + } + } + +- setup logrotate: +- nano /etc/logrotate.d/lightning-rod.log + + :: + + /var/log/iotronic/lightning-rod.log { + weekly + rotate = 3 + compress + su root root + maxsize 5M + } + +Building +'''''''' + +:: + + cd /var/lib/iotronic/iotronic-lightning-rod/ + python setup.py install + +Execution: +~~~~~~~~~~ + +:: + + systemctl restart lightning-rod.service + + tail -f /var/log/iotronic/lightning-rod.log \ No newline at end of file diff --git a/iotronic_lightningrod/modules/plugin_manager.py b/iotronic_lightningrod/modules/plugin_manager.py index e037593..41fd366 100644 --- a/iotronic_lightningrod/modules/plugin_manager.py +++ b/iotronic_lightningrod/modules/plugin_manager.py @@ -693,7 +693,7 @@ class PluginManager(Module.Module): w_msg = yield WM.WampError(str(err)) returnValue(w_msg.serialize()) - def PluginReboot(self, plugin_uuid): + def PluginReboot(self, plugin_uuid, parameters=None): """To reboot an asynchronous plugin (callable = false) into the board. :return: return a response to RPC request @@ -705,6 +705,9 @@ class PluginManager(Module.Module): LOG.info("RPC " + rpc_name + " CALLED for '" + plugin_uuid + "' plugin:") + LOG.info(" - plugin restarting with parameters:") + LOG.info(" " + str(parameters)) + try: plugin_home = iotronic_home + "/plugins/" + plugin_uuid @@ -721,15 +724,21 @@ class PluginManager(Module.Module): worker = PLUGINS_THRS[plugin_uuid] + # STOP PLUGIN---------------------------------------------- + if worker.isAlive(): - # STOP PLUGIN------------------------------------------ + LOG.info(" - Thread " + plugin_uuid + " is running, stopping...") LOG.debug(" - Stopping plugin " + str(worker)) worker.stop() + while worker.isAlive(): + pass + # Remove from plugin thread list del PLUGINS_THRS[plugin_uuid] + LOG.debug(" - plugin data structure cleaned!") # START PLUGIN------------------------------------------------- if os.path.exists(plugin_filename): @@ -737,13 +746,20 @@ class PluginManager(Module.Module): # Import plugin python module task = imp.load_source("plugin", plugin_filename) - if os.path.exists(plugin_params_file): + if parameters is None: - with open(plugin_params_file) as conf: - plugin_params = json.load(conf) + if os.path.exists(plugin_params_file): + + with open(plugin_params_file) as conf: + plugin_params = json.load(conf) + + else: + plugin_params = None else: - plugin_params = None + plugin_params = parameters + LOG.info(" - plugin restarting with parameters:") + LOG.info(" " + str(plugin_params)) worker = task.Worker( plugin_uuid, diff --git a/iotronic_lightningrod/plugins/Plugin.py b/iotronic_lightningrod/plugins/Plugin.py index c06b411..2f24731 100644 --- a/iotronic_lightningrod/plugins/Plugin.py +++ b/iotronic_lightningrod/plugins/Plugin.py @@ -43,6 +43,7 @@ class Plugin(threading.Thread): threading.Thread.__init__(self) # self.setDaemon(1) self.setName("Plugin " + str(self.name)) # Set thread name + LOG.debug("Plugin Name: " + self.name) self.uuid = uuid self.name = name