From 561123b07cedd44a5cf729a294438fd087ff5fc2 Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Tue, 21 Jul 2020 15:24:19 +0200 Subject: [PATCH] Add systemd service To unify the systemd services for opensm from the different distributions, add `opensm.service` and `opensm@.service`. The `opensm@.service` starts opensm on a given port. `opensm.service` starts opensm for all available ports via the `opensm@.service`. fixes #9 Signed-off-by: Benjamin Drung --- .gitignore | 1 + Makefile.am | 6 ++++++ configure.ac | 7 +++++++ opensm.service | 13 +++++++++++++ opensm@.service.in | 10 ++++++++++ 5 files changed, 37 insertions(+) create mode 100644 opensm.service create mode 100644 opensm@.service.in diff --git a/.gitignore b/.gitignore index bbee270b..eedec6c6 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,7 @@ Makefile.in man/opensm.8 man/torus-2QoS.8 man/torus-2QoS.conf.5 +opensm@.service opensm.spec opensm/opensm opensm/osm_qos_parser_l.c diff --git a/Makefile.am b/Makefile.am index 0bd48b48..9bb97e01 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,6 +19,12 @@ docs = doc/performance-manager-HOWTO.txt doc/QoS_management_in_OpenSM.txt \ doc/partition-config.txt doc/opensm-sriov.txt \ doc/current-routing.txt doc/opensm_release_notes-3.3.txt +systemdunitdir = $(SYSTEMD_UNIT_DIR) +systemdunit_DATA = opensm.service opensm@.service + +opensm@.service: opensm@.service.in + sed -e 's,@sbindir\@,$(sbindir),g' $< > $@ + EXTRA_DIST = autogen.sh opensm.spec $(various_scripts) $(man_MANS) $(docs) dist-hook: $(EXTRA_DIST) diff --git a/configure.ac b/configure.ac index 4633fbb1..d7389203 100644 --- a/configure.ac +++ b/configure.ac @@ -270,6 +270,13 @@ AC_DEFINE_UNQUOTED(HAVE_DEFAULT_PER_MOD_LOGGING_FILE, [Define a Per Module Logging config file]) AC_SUBST(PER_MOD_LOGGING_FILE) +SYSTEMD_UNIT_DIR=`pkg-config systemd --variable=systemdsystemunitdir` +# Use default if SYSTEMD_DIR is empty +if test x"$SYSTEMD_UNIT_DIR" = "x"; then + SYSTEMD_UNIT_DIR=/lib/systemd/system +fi +AC_SUBST([SYSTEMD_UNIT_DIR]) + dnl select example event plugin or not OPENIB_OSM_DEFAULT_EVENT_PLUGIN_SEL diff --git a/opensm.service b/opensm.service new file mode 100644 index 00000000..0f78f041 --- /dev/null +++ b/opensm.service @@ -0,0 +1,13 @@ +[Unit] +Description=Starts the OpenSM InfiniBand fabric Subnet Managers +Documentation=man:opensm(8) +Before=network.target remote-fs-pre.target +ConditionPathExists=/sys/class/infiniband_mad/abi_version + +[Service] +Type=oneshot +ExecStart=/bin/sh -c 'PORTS=$(/usr/sbin/ibstat -p); if test -z "$PORTS"; then echo "No InfiniBand ports found."; exit 0; fi; echo "Starting opensm on following ports: $PORTS"; systemctl start $(echo $PORTS | sed -r "s/(\\w+)/opensm@\\1.service/g")' +RemainAfterExit=on + +[Install] +WantedBy=network-online.target diff --git a/opensm@.service.in b/opensm@.service.in new file mode 100644 index 00000000..aaf5dd2a --- /dev/null +++ b/opensm@.service.in @@ -0,0 +1,10 @@ +[Unit] +Description=Starts the OpenSM InfiniBand fabric Subnet Manager %I +Documentation=man:opensm(8) +Before=network.target remote-fs-pre.target +PartOf=opensm.service +ConditionPathExists=/sys/class/infiniband_mad/abi_version + +[Service] +Type=simple +ExecStart=@sbindir@/opensm --guid %I --log_file /var/log/opensm.%I.log