From 9b33e07260e056b579a1a1c3629f182b2a0d8ede Mon Sep 17 00:00:00 2001 From: Enrico Faulhaber Date: Wed, 25 Sep 2019 11:18:54 +0200 Subject: [PATCH] Provide systemd files + move example cfg from etc/ to cfg/ Change-Id: I437b3e2aaca55539ff110f5a46e411b34e0a0b9c Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/21319 Tested-by: JenkinsCodeReview Reviewed-by: Enrico Faulhaber --- {etc => cfg}/amagnet.cfg | 0 {etc => cfg}/ccr12.cfg | 0 {etc => cfg}/cryo.cfg | 0 {etc => cfg}/demo.cfg | 0 {etc => cfg}/epics.cfg | 0 {etc => cfg}/sim.cfg | 0 {etc => cfg}/sim_mlz_amagnet.cfg | 0 {etc => cfg}/sim_mlz_cci3he1.cfg | 0 {etc => cfg}/sim_mlz_ccidu1.cfg | 0 {etc => cfg}/sim_mlz_ccr12.cfg | 0 {etc => cfg}/sim_mlz_ccr12_v2.cfg | 0 {etc => cfg}/sim_mlz_htf02.cfg | 0 {etc => cfg}/sim_mlz_stressihtf2.cfg | 0 {etc => cfg}/sim_mlz_stressihtf2_v2.cfg | 0 {etc => cfg}/stressihtf2.cfg | 0 {etc => cfg}/test.cfg | 0 etc/secop-generator | 59 +++++++++++++++++++++++++ etc/secop.target | 8 ++++ etc/secop@.service | 12 +++++ secop/lib/__init__.py | 2 +- setup.py | 15 +++++-- 21 files changed, 92 insertions(+), 4 deletions(-) rename {etc => cfg}/amagnet.cfg (100%) rename {etc => cfg}/ccr12.cfg (100%) rename {etc => cfg}/cryo.cfg (100%) rename {etc => cfg}/demo.cfg (100%) rename {etc => cfg}/epics.cfg (100%) rename {etc => cfg}/sim.cfg (100%) rename {etc => cfg}/sim_mlz_amagnet.cfg (100%) rename {etc => cfg}/sim_mlz_cci3he1.cfg (100%) rename {etc => cfg}/sim_mlz_ccidu1.cfg (100%) rename {etc => cfg}/sim_mlz_ccr12.cfg (100%) rename {etc => cfg}/sim_mlz_ccr12_v2.cfg (100%) rename {etc => cfg}/sim_mlz_htf02.cfg (100%) rename {etc => cfg}/sim_mlz_stressihtf2.cfg (100%) rename {etc => cfg}/sim_mlz_stressihtf2_v2.cfg (100%) rename {etc => cfg}/stressihtf2.cfg (100%) rename {etc => cfg}/test.cfg (100%) create mode 100755 etc/secop-generator create mode 100644 etc/secop.target create mode 100644 etc/secop@.service diff --git a/etc/amagnet.cfg b/cfg/amagnet.cfg similarity index 100% rename from etc/amagnet.cfg rename to cfg/amagnet.cfg diff --git a/etc/ccr12.cfg b/cfg/ccr12.cfg similarity index 100% rename from etc/ccr12.cfg rename to cfg/ccr12.cfg diff --git a/etc/cryo.cfg b/cfg/cryo.cfg similarity index 100% rename from etc/cryo.cfg rename to cfg/cryo.cfg diff --git a/etc/demo.cfg b/cfg/demo.cfg similarity index 100% rename from etc/demo.cfg rename to cfg/demo.cfg diff --git a/etc/epics.cfg b/cfg/epics.cfg similarity index 100% rename from etc/epics.cfg rename to cfg/epics.cfg diff --git a/etc/sim.cfg b/cfg/sim.cfg similarity index 100% rename from etc/sim.cfg rename to cfg/sim.cfg diff --git a/etc/sim_mlz_amagnet.cfg b/cfg/sim_mlz_amagnet.cfg similarity index 100% rename from etc/sim_mlz_amagnet.cfg rename to cfg/sim_mlz_amagnet.cfg diff --git a/etc/sim_mlz_cci3he1.cfg b/cfg/sim_mlz_cci3he1.cfg similarity index 100% rename from etc/sim_mlz_cci3he1.cfg rename to cfg/sim_mlz_cci3he1.cfg diff --git a/etc/sim_mlz_ccidu1.cfg b/cfg/sim_mlz_ccidu1.cfg similarity index 100% rename from etc/sim_mlz_ccidu1.cfg rename to cfg/sim_mlz_ccidu1.cfg diff --git a/etc/sim_mlz_ccr12.cfg b/cfg/sim_mlz_ccr12.cfg similarity index 100% rename from etc/sim_mlz_ccr12.cfg rename to cfg/sim_mlz_ccr12.cfg diff --git a/etc/sim_mlz_ccr12_v2.cfg b/cfg/sim_mlz_ccr12_v2.cfg similarity index 100% rename from etc/sim_mlz_ccr12_v2.cfg rename to cfg/sim_mlz_ccr12_v2.cfg diff --git a/etc/sim_mlz_htf02.cfg b/cfg/sim_mlz_htf02.cfg similarity index 100% rename from etc/sim_mlz_htf02.cfg rename to cfg/sim_mlz_htf02.cfg diff --git a/etc/sim_mlz_stressihtf2.cfg b/cfg/sim_mlz_stressihtf2.cfg similarity index 100% rename from etc/sim_mlz_stressihtf2.cfg rename to cfg/sim_mlz_stressihtf2.cfg diff --git a/etc/sim_mlz_stressihtf2_v2.cfg b/cfg/sim_mlz_stressihtf2_v2.cfg similarity index 100% rename from etc/sim_mlz_stressihtf2_v2.cfg rename to cfg/sim_mlz_stressihtf2_v2.cfg diff --git a/etc/stressihtf2.cfg b/cfg/stressihtf2.cfg similarity index 100% rename from etc/stressihtf2.cfg rename to cfg/stressihtf2.cfg diff --git a/etc/test.cfg b/cfg/test.cfg similarity index 100% rename from etc/test.cfg rename to cfg/test.cfg diff --git a/etc/secop-generator b/etc/secop-generator new file mode 100755 index 0000000..4362ed0 --- /dev/null +++ b/etc/secop-generator @@ -0,0 +1,59 @@ + +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# ***************************************************************************** +# Copyright (c) 2015-2019 by the authors, see LICENSE +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# Module authors: +# Alexander Lenz +# Enrico Faulhaber +# +# ***************************************************************************** + +import os +import sys +import fnmatch +from os import path + +from secop.lib import getGeneralConfig + +def main(): + normal_dir = sys.argv[1] + + global_config = getGeneralConfig() + config_dir = global_config['confdir'] + + secop_unit = '/lib/systemd/system/secop@.service' + wants_dir = normal_dir + '/secop.target.wants' + + all_servers = [base for (base, ext) in + map(path.splitext, os.listdir(config_dir)) if ext == '.cfg'] + all_servers.sort() + + for srv in all_servers: + symlink = '%s/secop@%s.service' % (normal_dir, srv) + os.symlink(secop_unit, symlink) + + # the stamp file signals successful run of the generator + open(normal_dir + '/secop.stamp', 'w').close() + + +if __name__ == '__main__': + try: + main() + except Exception: + pass # don't signal an error here diff --git a/etc/secop.target b/etc/secop.target new file mode 100644 index 0000000..562789b --- /dev/null +++ b/etc/secop.target @@ -0,0 +1,8 @@ +[Unit] +Description=Start all SECoP SEC-nodes +Requires=network-online.service +Wants=network-online.service +After=network-online.service + +[Install] +WantedBy=multi-user.target diff --git a/etc/secop@.service b/etc/secop@.service new file mode 100644 index 0000000..64e7518 --- /dev/null +++ b/etc/secop@.service @@ -0,0 +1,12 @@ +[Unit] +Description=SECoP SEC-node: %i +After=network-online.service + +[Service] +Type=notify +ExecStart=/usr/bin/secop-server %I +Restart=on-abnormal +RestartSec=30 + +[Install] +WantedBy=multi-user.target diff --git a/secop/lib/__init__.py b/secop/lib/__init__.py index 97ee80b..9969723 100644 --- a/secop/lib/__init__.py +++ b/secop/lib/__init__.py @@ -40,7 +40,7 @@ repodir = path.abspath(path.join(path.dirname(__file__), u'..', u'..')) CONFIG = { u'piddir': os.path.join(repodir, u'pid'), u'logdir': os.path.join(repodir, u'log'), - u'confdir': os.path.join(repodir, u'etc'), + u'confdir': os.path.join(repodir, u'cfg'), u'basedir': repodir, } if os.path.exists(os.path.join(repodir, u'.git')) else { u'piddir': u'/var/run/secop', diff --git a/setup.py b/setup.py index 00e3672..19fe831 100644 --- a/setup.py +++ b/setup.py @@ -43,12 +43,19 @@ setup( author='Enrico Faulhaber', author_email='enrico.faulhaber@frm2.tum.de', description='SECoP Playground core system', - packages=find_packages(), + packages=find_packages(exclude=['test']), package_data={'secop': ['RELEASE-VERSION'] + uis}, - data_files=[('/etc/init.d', ['etc/secop-server'])], + data_files=[ + ('/etc/init.d', ['etc/secop-server']), + ('/lib/systemd/system-generators', ['etc/secop-generator']), + ('/lib/systemd/system', ['etc/secop@.service', + 'etc/secop.target']), + ('/var/log/secop', []), + ('/var/run/secop', []), + ], scripts=scripts, classifiers=[ - 'Development Status :: 6 - Mature', + 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'Intended Audience :: Science/Research', 'Natural Language :: English', @@ -57,6 +64,8 @@ setup( 'Programming Language :: Python', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.6', 'Topic :: Scientific/Engineering', 'Topic :: Scientific/Engineering :: Human Machine Interfaces', 'Topic :: Scientific/Engineering :: Physics',