From 2e3da1ab45614e6c3b373c6e34a389cc281cdfe5 Mon Sep 17 00:00:00 2001 From: Nicola Peditto Date: Fri, 21 Sep 2018 18:39:36 +0200 Subject: [PATCH] Restyling Packaging Change-Id: I1da9ba514df9f4aae0efec081bcb4697855d5a20 --- MANIFEST.in | 12 +- etc/logrotate.d/lightning-rod.log | 11 ++ scripts/configure_lr.py | 28 +++++ scripts/install_lr.py | 103 ++++++++++++++++++ setup.cfg | 2 + setup.py | 18 ++- .../plugins.example.json | 0 .../services.example.json | 0 .../settings.example.json | 0 9 files changed, 172 insertions(+), 2 deletions(-) create mode 100644 etc/logrotate.d/lightning-rod.log create mode 100644 scripts/configure_lr.py create mode 100644 scripts/install_lr.py rename plugins.example.json => templates/plugins.example.json (100%) rename services.example.json => templates/services.example.json (100%) rename settings.example.json => templates/settings.example.json (100%) diff --git a/MANIFEST.in b/MANIFEST.in index 90f8a7a..bb4613f 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,16 @@ +include etc/iotronic/iotronic.conf +include templates/settings.example.json +include templates/plugins.example.json +include templates/services.example.json +include etc/systemd/system/s4t-lightning-rod.service +include etc/logrotate.d/lightning-rod.log +include scripts/install_lr.py +include scripts/configure_lr.py + include AUTHORS include ChangeLog exclude .gitignore exclude .gitreview -global-exclude *.pyc \ No newline at end of file +global-exclude *.pyc + diff --git a/etc/logrotate.d/lightning-rod.log b/etc/logrotate.d/lightning-rod.log new file mode 100644 index 0000000..e29687f --- /dev/null +++ b/etc/logrotate.d/lightning-rod.log @@ -0,0 +1,11 @@ +/var/log/iotronic/lightning-rod.log /var/log/wstun/wstun.log{ + copytruncate + create + missingok + weekly + rotate = 3 + compress + notifempty + su root root + maxsize 5M +} diff --git a/scripts/configure_lr.py b/scripts/configure_lr.py new file mode 100644 index 0000000..f932e01 --- /dev/null +++ b/scripts/configure_lr.py @@ -0,0 +1,28 @@ +# 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. + +# !/usr/bin/python3 +import os +import sys + +if len(sys.argv) < 3: + print('Arguments required: " ', + str(sys.argv)) +else: + os.system('sed -i "s||' + + sys.argv[1] + '|g" /etc/iotronic/settings.json') + os.system('sed -i "s|ws://:/|' + + sys.argv[2] + '|g" /etc/iotronic/settings.json') + os.system('sed -i "s||s4t|g" /etc/iotronic/settings.json') diff --git a/scripts/install_lr.py b/scripts/install_lr.py new file mode 100644 index 0000000..61bb058 --- /dev/null +++ b/scripts/install_lr.py @@ -0,0 +1,103 @@ +# 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. + +# !/usr/bin/python3 +import os +import site + + +py_dist_pack = site.getsitepackages()[0] +print(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: + print(' - iotronic.conf - Already exists.') + + +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.') + + +from subprocess import call +call(["systemctl", "enable", "lightning-rod.service"]) +call(["systemctl", "daemon-reload"]) + +os.system('cp ' + py_dist_pack + '/iotronic_lightningrod/scripts/' + + 'configure_lr.py /usr/bin/configure_lr') +os.chmod('/usr/bin/configure_lr', 0o744) diff --git a/setup.cfg b/setup.cfg index 531dd75..5366f09 100644 --- a/setup.cfg +++ b/setup.cfg @@ -64,3 +64,5 @@ s4t.modules = [options] build_scripts = executable= /usr/bin/env python + + diff --git a/setup.py b/setup.py index dcce8e6..75669b7 100644 --- a/setup.py +++ b/setup.py @@ -27,5 +27,21 @@ except ImportError: setuptools.setup( setup_requires=['pbr>=1.8'], pbr=True, - + include_package_data=True, + data_files=[ + ('/iotronic_lightningrod/etc/iotronic', + ['etc/iotronic/iotronic.conf']), + ('/iotronic_lightningrod/scripts', ['scripts/install_lr.py']), + ('/iotronic_lightningrod/scripts', ['scripts/configure_lr.py']), + ('/iotronic_lightningrod/templates', + ['templates/settings.example.json']), + ('/iotronic_lightningrod/templates', + ['templates/plugins.example.json']), + ('/iotronic_lightningrod/templates', + ['templates/services.example.json']), + ('/iotronic_lightningrod/etc/logrotate.d', + ['etc/logrotate.d/lightning-rod.log']), + ('/iotronic_lightningrod/etc/systemd/system/', + ['etc/systemd/system/s4t-lightning-rod.service']), + ], ) diff --git a/plugins.example.json b/templates/plugins.example.json similarity index 100% rename from plugins.example.json rename to templates/plugins.example.json diff --git a/services.example.json b/templates/services.example.json similarity index 100% rename from services.example.json rename to templates/services.example.json diff --git a/settings.example.json b/templates/settings.example.json similarity index 100% rename from settings.example.json rename to templates/settings.example.json