[meta-virtualization] [meta-openstack][PATCH] tgt: add systemd service file

mingli.yu at windriver.com mingli.yu at windriver.com
Fri Aug 10 00:29:32 PDT 2018


From: Mingli Yu <Mingli.Yu at windriver.com>

Add systemd service file for tgt

Signed-off-by: Mingli Yu <Mingli.Yu at windriver.com>
---
 meta-openstack/recipes-support/tgt/files/tgtd      |  5 ++++
 .../recipes-support/tgt/files/tgtd.service         | 33 ++++++++++++++++++++++
 meta-openstack/recipes-support/tgt/tgt_git.bb      | 22 +++++++++++++--
 3 files changed, 58 insertions(+), 2 deletions(-)
 create mode 100644 meta-openstack/recipes-support/tgt/files/tgtd
 create mode 100755 meta-openstack/recipes-support/tgt/files/tgtd.service

diff --git a/meta-openstack/recipes-support/tgt/files/tgtd b/meta-openstack/recipes-support/tgt/files/tgtd
new file mode 100644
index 0000000..64df6a3
--- /dev/null
+++ b/meta-openstack/recipes-support/tgt/files/tgtd
@@ -0,0 +1,5 @@
+# options for tgtd
+TGTD_OPTS=""
+
+# configuration file
+TGTD_CONFIG=/etc/tgt/targets.conf
diff --git a/meta-openstack/recipes-support/tgt/files/tgtd.service b/meta-openstack/recipes-support/tgt/files/tgtd.service
new file mode 100755
index 0000000..afbd4b4
--- /dev/null
+++ b/meta-openstack/recipes-support/tgt/files/tgtd.service
@@ -0,0 +1,33 @@
+[Unit]
+Description=tgtd iSCSI target daemon
+After=network.target
+
+[Service]
+EnvironmentFile=@SYSCONFDIR@/sysconfig/tgtd
+
+ExecStart=@SBINDIR@/tgtd -f $TGTD_OPTS
+# see bz 848942. workaround for a race for now.
+ExecStartPost=@BASE_BINDIR@/sleep 5
+# Put tgtd into "offline" state until all the targets are configured.
+# We don't want initiators to (re)connect and fail the connection
+# if it's not ready.
+ExecStartPost=@SBINDIR@/tgtadm --op update --mode sys --name State -v offline
+# Configure the targets.
+ExecStartPost=@SBINDIR@/tgt-admin -e -c $TGTD_CONFIG
+# Put tgtd into "ready" state.
+ExecStartPost=@SBINDIR@/tgtadm --op update --mode sys --name State -v ready
+
+# Update configuration for targets. Only targets which
+# are not in use will be updated.
+ExecReload=@SBINDIR@/tgt-admin --update ALL -c $TGTD_CONFIG
+
+# NOTE: Shutdown of the iscsi target may cause data corruption
+# for initiators that are connected.
+ExecStop=@SBINDIR@/tgtadm --op update --mode sys --name State -v offline
+# Remove all targets. It only removes targets which are not in use.
+ExecStop=@SBINDIR@/tgt-admin --update ALL -c /dev/null
+# tgtd will exit if all targets were removed
+ExecStop=@SBINDIR@/tgtadm --op delete --mode system
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-openstack/recipes-support/tgt/tgt_git.bb b/meta-openstack/recipes-support/tgt/tgt_git.bb
index f4e12da..b94b034 100644
--- a/meta-openstack/recipes-support/tgt/tgt_git.bb
+++ b/meta-openstack/recipes-support/tgt/tgt_git.bb
@@ -12,13 +12,19 @@ SRC_URI = "git://github.com/fujita/tgt.git \
         file://0001-usr-Makefile-WARNING-fix.patch \
         file://usr-Makefile-apply-LDFLAGS-to-all-executables.patch \
 "
-SRC_URI += "file://tgtd.init"
+SRC_URI += "file://tgtd.init \
+            file://tgtd.service \
+            file://tgtd \
+"
 
 S = "${WORKDIR}/git"
 
 CONFFILES_${PN} += "${sysconfdir}/tgt/targets.conf"
 
-inherit update-rc.d
+inherit update-rc.d systemd
+
+SYSTEMD_SERVICE_${PN} = "tgtd.service"
+SYSTEMD_AUTO_ENABLE_${PN} = "disable"
 
 CFLAGS += ' -I. -DUSE_SIGNALFD -DUSE_TIMERFD -D_GNU_SOURCE -DTGT_VERSION=\\"1.0.63\\" -DBSDIR=\\"${libdir}/backing-store\\"'
 
@@ -33,9 +39,21 @@ do_install() {
     if ${@bb.utils.contains('DISTRO_FEATURES', 'sysvinit', 'true', 'false', d)}; then
         install -d ${D}${sysconfdir}/init.d
         install -m 0755 ${WORKDIR}/tgtd.init ${D}${sysconfdir}/init.d/tgtd
+    elif ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'true', 'false', d)}; then
+        install -d ${D}${systemd_unitdir}/system
+        install -m 0644 ${WORKDIR}/tgtd.service ${D}${systemd_unitdir}/system/tgtd.service
+        install -d ${D}${sysconfdir}/sysconfig
+        install -m 0644 ${WORKDIR}/tgtd ${D}${sysconfdir}/sysconfig/tgtd
+        sed -i -e 's, at SBINDIR@,${sbindir},g' ${D}${systemd_unitdir}/system/tgtd.service
+        sed -i -e 's, at BASE_BINDIR@,${base_bindir},g' ${D}${systemd_unitdir}/system/tgtd.service
+        sed -i -e 's, at SYSCONFDIR@,${sysconfdir},g' ${D}${systemd_unitdir}/system/tgtd.service
     fi
 }
 
+FILES_${PN} += "${systemd_unitdir}/system/tgtd.service \
+                ${sysconfdir}/sysconfig/tgtd \
+"
+
 RDEPENDS_${PN} = " \
     bash \
     libaio \
-- 
2.7.4



More information about the meta-virtualization mailing list