Release v0.4.3:

* Service Manager refactored:
 - WSTUN server check added
 - backup management for services.json file
* Docker installation procedures updated

Change-Id: I492e35272c88cf0ebdd5e1b1b5b35f22f616c6e5
This commit is contained in:
Nicola Peditto 2018-12-11 15:45:40 +01:00
parent 84678996b0
commit 044b45ff00
10 changed files with 896 additions and 417 deletions

View File

@ -65,7 +65,7 @@ def destroyWampSocket():
print("WAMP RECOVERY: " + str(proc.connections()[0]))
ws_fd = proc.connections()[0].fd
first = b"call shutdown("
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)

View File

@ -259,7 +259,6 @@ async def IotronicLogin(board, session, details):
# reconnection = False
else:
LOG.error(" - Access denied to Iotronic.")
Bye()
except exception.ApplicationError as e:

File diff suppressed because it is too large Load Diff

View File

@ -18,12 +18,38 @@
import os
import sys
if len(sys.argv) < 3:
print('Arguments required: <REGISTRATION-TOKEN> <WAMP-REG-AGENT-URL>',
str(sys.argv))
if len(sys.argv) == 1:
print('Arguments required:')
print(" with '-c' specify: <REGISTRATION-TOKEN> <WAMP-REG-AGENT-URL> <LR_CONF_PATH>")
print(" without '-c' specify: <REGISTRATION-TOKEN> <WAMP-REG-AGENT-URL>")
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|<IOTRONIC-REALM>|s4t|g" /etc/iotronic/settings.json')
if sys.argv[1] == "-c":
if len(sys.argv) < 5:
print('Arguments required: '
+ '<REGISTRATION-TOKEN> '
+ '<WAMP-REG-AGENT-URL> '
+ '<LR_CONF_PATH>',
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|<IOTRONIC-REALM>|s4t|g" '
+ sys.argv[4] + '/settings.json')
else:
if len(sys.argv) < 3:
print('Arguments required: <REGISTRATION-TOKEN> <WAMP-REG-AGENT-URL>',
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|<IOTRONIC-REALM>|s4t|g" /etc/iotronic/settings.json')

View File

@ -0,0 +1,30 @@
FROM ubuntu:bionic
RUN apt-get update && apt-get install -y \
socat dsniff git ntpdate python build-essential vim lsof gdb screen python3 python3-setuptools python3-pip npm
ENV TZ 'Europe/Rome'
ENV DEBIAN_FRONTEND=noninteractive
RUN echo $TZ > /etc/timezone && apt-get update && apt-get install -y tzdata && rm -f /etc/localtime && ln -nfs /usr/share/zoneinfo/$TZ /etc/localtime && dpkg-reconfigure -f noninteractive tzdata
RUN apt-get install -y nginx python-certbot-nginx
RUN sed -i 's/# server_names_hash_bucket_size 64;/server_names_hash_bucket_size 64;/g' /etc/nginx/nginx.conf
RUN rm -rf /var/lib/apt/lists/*
RUN npm install -g --unsafe @mdslab/wstun@1.0.9 && npm cache --force clean
RUN pip3 install iotronic-lightningrod
COPY data/lr_install /usr/local/bin/lr_install
COPY data/startLR /usr/local/bin/startLR
RUN /usr/local/bin/lr_install
VOLUME /var/lib/iotronic
RUN ln -s /usr/local/bin/wstun /usr/bin/wstun
#CMD [ "/usr/sbin/nginx"]
#CMD [ "/usr/local/bin/lightning-rod"]
CMD ["/usr/local/bin/startLR"]

View File

@ -0,0 +1,111 @@
#!/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 site
if os.path.exists('/iotronic_lightningrod/'):
print("Cleaning install folders...")
os.system('rm -rf ' + site.getsitepackages()[0]
+ '/iotronic_lightningrod/etc')
os.system('rm -rf ' + site.getsitepackages()[0]
+ '/iotronic_lightningrod/templates')
print("Moving installation folders...")
os.system('mv -f /iotronic_lightningrod/* '
+ site.getsitepackages()[0] + '/iotronic_lightningrod/')
py_dist_pack = site.getsitepackages()[0]
print("Python packages folder: " + py_dist_pack)
print('Iotronic environment creation:')
if not os.path.exists('/etc/iotronic/'):
os.makedirs('/etc/iotronic/', 0o644)
print(' - /etc/iotronic/ - Created.')
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/'
+ 'templates/settings.example.json /etc/iotronic/settings.json')
print(' - settings.json - Created.')
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/'
+ 'etc/iotronic/iotronic.conf /etc/iotronic/iotronic.conf')
print(' - iotronic.conf - Created.')
else:
print(' - /etc/iotronic/ - Already exists.')
if not os.path.isfile('/etc/iotronic/settings.json'):
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/templates/'
+ 'settings.example.json /etc/iotronic/settings.json')
print(' - settings.json - Created.')
else:
print(' - settings.json - Already exists.')
if not os.path.isfile('/etc/iotronic/iotronic.conf'):
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/'
+ 'etc/iotronic/iotronic.conf /etc/iotronic/iotronic.conf')
print(' - iotronic.conf - Created.')
else:
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/'
+ 'etc/iotronic/iotronic.conf /etc/iotronic/iotronic.conf')
print(' - iotronic.conf - Overwritten.')
if not os.path.exists('/var/lib/iotronic/'):
os.makedirs('/var/lib/iotronic/plugins', 0o644)
print(' - /var/lib/iotronic/plugins - Created.')
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/templates/'
+ 'plugins.example.json /var/lib/iotronic/plugins.json')
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/templates/'
+ 'services.example.json /var/lib/iotronic/services.json')
print(' - configuration files added.')
else:
print(' - /var/lib/iotronic/ - Already exists.')
if not os.path.isfile('/var/lib/iotronic/plugins.json'):
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/templates/'
+ 'plugins.example.json /var/lib/iotronic/plugins.json')
print(' - plugins.json - Created.')
else:
print(' - plugins.json - Already exists.')
if not os.path.isfile('/var/lib/iotronic/services.json'):
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/templates/'
+ 'services.example.json /var/lib/iotronic/services.json')
print(' - services.json - Created.')
else:
print(' - services.json - Already exists.')
print('Logging configuration: ')
if not os.path.exists('/var/log/iotronic/'):
os.makedirs('/var/log/iotronic/', 0o644)
print(' - /var/log/iotronic/ - Created.')
else:
print(' - /var/log/iotronic/ - Already exists.')
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/etc/logrotate.d/'
+ 'lightning-rod.log /etc/logrotate.d/lightning-rod.log')
print(' - logrotate configured.')
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/etc/systemd/system/'
+ 's4t-lightning-rod.service '
+ '/etc/systemd/system/lightning-rod.service')
os.chmod('/etc/systemd/system/lightning-rod.service', 0o744)
print('Lightning-rod systemd script installed.')
"""
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/scripts/'
+ 'configure_lr.py /usr/bin/configure_lr')
os.chmod('/usr/bin/configure_lr', 0o744)
"""

View File

@ -0,0 +1,30 @@
#!/bin/bash
# Start the first process
/usr/sbin/nginx
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start NGINX: $status"
exit $status
fi
# Start the second process
/usr/local/bin/lightning-rod
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start Lightning-rod: $status"
exit $status
fi
while sleep 60; do
ps aux |grep nginx |grep -q -v grep
PROCESS_1_STATUS=$?
ps aux |grep lightning-rod |grep -q -v grep
PROCESS_2_STATUS=$?
# If the greps above find anything, they exit with 0 status
# If they are not both 0, then something is wrong
if [ $PROCESS_1_STATUS -ne 0 -o $PROCESS_2_STATUS -ne 0 ]; then
echo "One of the processes has already exited."
exit 1
fi
done

View File

@ -0,0 +1,30 @@
FROM ubuntu:bionic
RUN apt-get update && apt-get install -y \
socat dsniff git ntpdate python build-essential vim lsof gdb screen python3 python3-setuptools python3-pip npm
ENV TZ 'Europe/Rome'
ENV DEBIAN_FRONTEND=noninteractive
RUN echo $TZ > /etc/timezone && apt-get update && apt-get install -y tzdata && rm -f /etc/localtime && ln -nfs /usr/share/zoneinfo/$TZ /etc/localtime && dpkg-reconfigure -f noninteractive tzdata
RUN apt-get install -y nginx python-certbot-nginx
RUN sed -i 's/# server_names_hash_bucket_size 64;/server_names_hash_bucket_size 64;/g' /etc/nginx/nginx.conf
RUN rm -rf /var/lib/apt/lists/*
RUN npm install -g --unsafe @mdslab/wstun@1.0.9 && npm cache --force clean
RUN pip3 install iotronic-lightningrod
COPY data/lr_install /usr/local/bin/lr_install
COPY data/startLR /usr/local/bin/startLR
RUN /usr/local/bin/lr_install
VOLUME /var/lib/iotronic
RUN ln -s /usr/local/bin/wstun /usr/bin/wstun
#CMD [ "/usr/sbin/nginx"]
#CMD [ "/usr/local/bin/lightning-rod"]
CMD ["/usr/local/bin/startLR"]

View File

@ -0,0 +1,111 @@
#!/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 site
if os.path.exists('/iotronic_lightningrod/'):
print("Cleaning install folders...")
os.system('rm -rf ' + site.getsitepackages()[0]
+ '/iotronic_lightningrod/etc')
os.system('rm -rf ' + site.getsitepackages()[0]
+ '/iotronic_lightningrod/templates')
print("Moving installation folders...")
os.system('mv -f /iotronic_lightningrod/* '
+ site.getsitepackages()[0] + '/iotronic_lightningrod/')
py_dist_pack = site.getsitepackages()[0]
print("Python packages folder: " + py_dist_pack)
print('Iotronic environment creation:')
if not os.path.exists('/etc/iotronic/'):
os.makedirs('/etc/iotronic/', 0o644)
print(' - /etc/iotronic/ - Created.')
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/'
+ 'templates/settings.example.json /etc/iotronic/settings.json')
print(' - settings.json - Created.')
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/'
+ 'etc/iotronic/iotronic.conf /etc/iotronic/iotronic.conf')
print(' - iotronic.conf - Created.')
else:
print(' - /etc/iotronic/ - Already exists.')
if not os.path.isfile('/etc/iotronic/settings.json'):
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/templates/'
+ 'settings.example.json /etc/iotronic/settings.json')
print(' - settings.json - Created.')
else:
print(' - settings.json - Already exists.')
if not os.path.isfile('/etc/iotronic/iotronic.conf'):
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/'
+ 'etc/iotronic/iotronic.conf /etc/iotronic/iotronic.conf')
print(' - iotronic.conf - Created.')
else:
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/'
+ 'etc/iotronic/iotronic.conf /etc/iotronic/iotronic.conf')
print(' - iotronic.conf - Overwritten.')
if not os.path.exists('/var/lib/iotronic/'):
os.makedirs('/var/lib/iotronic/plugins', 0o644)
print(' - /var/lib/iotronic/plugins - Created.')
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/templates/'
+ 'plugins.example.json /var/lib/iotronic/plugins.json')
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/templates/'
+ 'services.example.json /var/lib/iotronic/services.json')
print(' - configuration files added.')
else:
print(' - /var/lib/iotronic/ - Already exists.')
if not os.path.isfile('/var/lib/iotronic/plugins.json'):
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/templates/'
+ 'plugins.example.json /var/lib/iotronic/plugins.json')
print(' - plugins.json - Created.')
else:
print(' - plugins.json - Already exists.')
if not os.path.isfile('/var/lib/iotronic/services.json'):
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/templates/'
+ 'services.example.json /var/lib/iotronic/services.json')
print(' - services.json - Created.')
else:
print(' - services.json - Already exists.')
print('Logging configuration: ')
if not os.path.exists('/var/log/iotronic/'):
os.makedirs('/var/log/iotronic/', 0o644)
print(' - /var/log/iotronic/ - Created.')
else:
print(' - /var/log/iotronic/ - Already exists.')
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/etc/logrotate.d/'
+ 'lightning-rod.log /etc/logrotate.d/lightning-rod.log')
print(' - logrotate configured.')
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/etc/systemd/system/'
+ 's4t-lightning-rod.service '
+ '/etc/systemd/system/lightning-rod.service')
os.chmod('/etc/systemd/system/lightning-rod.service', 0o744)
print('Lightning-rod systemd script installed.')
"""
os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/scripts/'
+ 'configure_lr.py /usr/bin/configure_lr')
os.chmod('/usr/bin/configure_lr', 0o744)
"""

View File

@ -0,0 +1,30 @@
#!/bin/bash
# Start the first process
/usr/sbin/nginx
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start NGINX: $status"
exit $status
fi
# Start the second process
/usr/local/bin/lightning-rod
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start Lightning-rod: $status"
exit $status
fi
while sleep 60; do
ps aux |grep nginx |grep -q -v grep
PROCESS_1_STATUS=$?
ps aux |grep lightning-rod |grep -q -v grep
PROCESS_2_STATUS=$?
# If the greps above find anything, they exit with 0 status
# If they are not both 0, then something is wrong
if [ $PROCESS_1_STATUS -ne 0 -o $PROCESS_2_STATUS -ne 0 ]; then
echo "One of the processes has already exited."
exit 1
fi
done