Skip to contentSkip to conversation

CLVMD: systemd native service

PATCH New Ondrej Kozina 1 participant 4 messages Nov 1, 2012 Kbuild

lore
Share & tools
lore
#0 lore raw

cover CLVMD: systemd native service

In response to (bz #829308):

Right now, clvmd init scripts are not compatible with systemd so I propose to add "native" systemd units for systemd enabled distros.

This patch splits clvmd service between two new services:

1) clvmd daemon itself (clvmd-daemon.service)
2) activation/deactivation of clustered VGs (clvmd.service)

There're several reasons to split it. First, there's no support for conditional stop in systemd and AFAIK they don't plan to support it. In other words:
if the deactivation fails for some reason, systemd doesn't care and simply kills all remaining procs in the cgroup (by default). Killing the remaining procs can be suppressed however it doesn't solve the following problem:

You can't repeat the stop command of a failed service. The repeated stop command is simply not propagated to the service. You would have to start and then try to stop the service again. Unfortunately, this can't be done while the daemon is still running (and we need the daemon to be active until all clustered VGs are deactivated successfully).

In a separated setup we need only to restart the failed activation service and that's fine.

Ondrej Kozina (3):
- add clvmd native systemd service
- add clvmd activation systemd service
- alter related configuration files

 configure.in                                       |  3 +
 make.tmpl.in                                       |  1 +
 scripts/Makefile.in                                |  9 ++-
 scripts/clvmd_activation_script_red_hat.sh.in      | 71 ++++++++++++++++++++++
 .../clvmd_activation_systemd_red_hat.service.in    | 14 +++++
 scripts/clvmd_systemd_red_hat.service.in           | 20 ++++++
 6 files changed, 117 insertions(+), 1 deletion(-)
 create mode 100755 scripts/clvmd_activation_script_red_hat.sh.in
 create mode 100644 scripts/clvmd_activation_systemd_red_hat.service.in
 create mode 100644 scripts/clvmd_systemd_red_hat.service.in
Signature · 1 line
1.7.12.4
#1 lore raw

PATCH 1/3 - add clvmd native systemd service

just a few notes:

RefuseManualStop - we don't want user to stop the daemon w/o proper deactivation RefuseManualStart - I can remove that, but right now I don't see any reason to allow it StopWhenUnneeded - when all direct dependecies are gone, we can finish

---
 scripts/clvmd_systemd_red_hat.service.in | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 scripts/clvmd_systemd_red_hat.service.in
scripts/clvmd_systemd_red_hat.service.in new file +20 -0
new file mode 100644
index 0000000..d141721
@@ -0,0 +1,20 @@
+[Unit]
+Description=Clustered LVM daemon
+Documentation=man:clvmd(8)
+After=network.target dlm.service corosync.service
+Before=remote-fs.target
+RefuseManualStart=true
+RefuseManualStop=true
+StopWhenUnneeded=true
+
+[Service]
+Type=forking
+Environment=CLVMD_OPTS=-T30
+EnvironmentFile=- at sysconfdir@/etc/sysconfig/clvmd
+ExecStart=@sbindir@/clvmd $CLVMD_OPTS
+ExecReload=@sbindir@/clvmd -R
+SuccessExitStatus=5
+TimeoutStartSec=30
+TimeoutStopSec=10
+OOMScoreAdjust=-1000
+Restart=on-abort
Signature · 1 line
1.7.12.4
#2 lore raw

PATCH 2/3 - add clvmd activation systemd service

In reply to Ondrej Kozina

OnFailure=clvmd-daemon.service - this will prevent the daemon to be killed if the (de)activation fails (yup, ugly hack).

clvmd_activation_script_red_hat.sh.in - It's a very simple rewrite of the original inititscript (no waiting in a loop, no awk)

---
 scripts/clvmd_activation_script_red_hat.sh.in      | 71 ++++++++++++++++++++++
 .../clvmd_activation_systemd_red_hat.service.in    | 14 +++++
 2 files changed, 85 insertions(+)
 create mode 100755 scripts/clvmd_activation_script_red_hat.sh.in
 create mode 100644 scripts/clvmd_activation_systemd_red_hat.service.in
scripts/clvmd_activation_script_red_hat.sh.in new file +71 -0
new file mode 100755
index 0000000..07eadec
@@ -0,0 +1,71 @@
+#!/bin/bash
+
+sbindir=/usr/sbin
+
+lvm_vgchange=${sbindir}/vgchange
+lvm_vgscan=${sbindir}/vgscan
+lvm_vgs=${sbindir}/vgs
+lvm_lvm=${sbindir}/lvm
+
+parse_clustered_vgs() {
+	while read -r name attrs;
+	do
+		test "${attrs:5:1}" == 'c' && echo -n "$name "
+	done
+}
+
+# NOTE: replace this with vgs, once display filter per attr is implemented.
+clustered_vgs() {
+	${lvm_vgs} -o vg_name,vg_attr --noheadings | parse_clustered_vgs
+}
+
+activate() {
+	eval local $(${lvm_lvm} dumpconfig devices/obtain_device_list_from_udev 2>/dev/null) 2>/dev/null
+	if [ $? -ne 0 ]; then
+		echo "Warning: expected single couple of key=value in output of dumpconfig"
+	fi
+
+	if [ -z $obtain_device_list_from_udev -o $obtain_device_list_from_udev -ne 1 ]; then
+		echo -n "lvm.conf option obtain_device_list_from_udev!=1: Executing vgscan"
+		${lvm_vgscan} > /dev/null 2>&1
+	fi
+
+	echo -n "Activating ${LVM_VGS:-"all VG(s)"}: "
+        ${lvm_vgchange} -ayl $LVM_VGS || return 1
+
+	return 0
+}
+
+deactivate()
+{
+	# NOTE: following section will be replaced by blkdeactivate script
+	# with option supporting request to deactivate all clustered volume
+	# groups in the system
+	[ -z $LVM_VGS ] && LVM_VGS="$(clustered_vgs)"
+	if [ -n "$LVM_VGS" ]; then
+		echo -n "Deactivating clustered VG(s): "
+                ${lvm_vgchange} -anl $LVM_VGS || return 1
+	fi
+
+	return 0
+}
+
+case "$1" in
+  deactivate)
+	deactivate
+	rtrn=$?
+	;;
+  activate)
+	activate
+	rtrn=$?
+	;;
+  reload)
+	rtrn=0;
+	;;
+  *)
+	echo $"Usage: $0 {activate|deactivate|reload}"
+	rtrn=3
+	;;
+esac
+
+exit $rtrn
scripts/clvmd_activation_systemd_red_hat.service.in new file +14 -0
new file mode 100644
index 0000000..b5bd963
@@ -0,0 +1,14 @@
+[Unit]
+Description=Clustered LVM volumes activation service
+Requires=clvmd-daemon.service
+After=clvmd-daemon.service
+OnFailure=clvmd-daemon.service
+PropagatesReloadTo=clvmd-daemon.service
+
+[Service]
+Type=simple
+RemainAfterExit=yes
+EnvironmentFile=- at sysconfdir@/sysconfig/clvmd
+ExecStart=@libexecdir@/clvmd/clvmd.sh activate
+ExecStop=@libexecdir@/clvmd/clvmd.sh deactivate
+ExecReload=@libexecdir@/clvmd/clvmd.sh reload
Signature · 1 line
1.7.12.4
#3 lore raw

PATCH 3/3 - alter related configuration files

In reply to Ondrej Kozina
---
 configure.in        | 3 +++
 make.tmpl.in        | 1 +
 scripts/Makefile.in | 9 ++++++++-
 3 files changed, 12 insertions(+), 1 deletion(-)
configure.in +3 -0
index 75e0d84..2fe0763 100644
@@ -1658,7 +1658,10 @@ python/setup.py
 scripts/blkdeactivate.sh
 scripts/blk_availability_init_red_hat
 scripts/blk_availability_systemd_red_hat.service
+scripts/clvmd_activation_script_red_hat.sh
+scripts/clvmd_activation_systemd_red_hat.service
 scripts/clvmd_init_red_hat
+scripts/clvmd_systemd_red_hat.service
 scripts/cmirrord_init_red_hat
 scripts/lvm2_lvmetad_init_red_hat
 scripts/lvm2_lvmetad_systemd_red_hat.socket
make.tmpl.in +1 -0
index 8b56f01..5102237 100644
@@ -73,6 +73,7 @@ systemd_unit_dir = $(DESTDIR)@systemdsystemunitdir@
 systemd_generator_dir = $(DESTDIR)@systemdutildir@/system-generators
 tmpfiles_dir = $(DESTDIR)@tmpfilesdir@
 ocf_scriptdir = $(DESTDIR)@OCFDIR@
+libexecdir = $(DESTDIR)@libexecdir@
 
 USRLIB_RELPATH = $(shell echo $(abspath $(usrlibdir) $(libdir)) | \
   $(AWK) -f $(top_srcdir)/scripts/relpath.awk)
scripts/Makefile.in +8 -1
index 91e2e94..7f1f1cf 100644
@@ -108,6 +108,12 @@ ifeq ("@BUILD_LVMETAD@", "yes")
 	$(INSTALL_DATA) lvm2_lvmetad_systemd_red_hat.socket $(systemd_unit_dir)/lvm2-lvmetad.socket
 	$(INSTALL_DATA) lvm2_lvmetad_systemd_red_hat.service $(systemd_unit_dir)/lvm2-lvmetad.service
 endif
+ifneq ("@CLVMD@", "none")
+	$(INSTALL_DATA) clvmd_systemd_red_hat.service $(systemd_unit_dir)/clvmd-daemon.service
+	$(INSTALL_DATA) clvmd_activation_systemd_red_hat.service $(systemd_unit_dir)/clvmd.service
+	$(INSTALL_DIR) $(libexecdir)/clvmd
+	$(INSTALL_DATA) clvmd_activation_script_red_hat.sh $(libexecdir)/clvmd/clvmd.sh
+endif
 
 install_tmpfiles_configuration:
 	$(INSTALL_DIR) $(tmpfiles_dir)
@@ -118,4 +124,5 @@ DISTCLEAN_TARGETS += clvmd_init_red_hat cmirrord_init_red_hat \
 		     dm_event_systemd_red_hat.socket dm_event_systemd_red_hat.service \
 		     lvm2_monitoring_systemd_red_hat.service \
 		     lvm2_lvmetad_systemd_red_hat.socket lvm2_lvmetad_systemd_red_hat.service \
-		     lvm2_tmpfiles_red_hat.conf
+		     lvm2_tmpfiles_red_hat.conf clvmd_systemd_red_hat.service \
+		     clvmd_activation_systemd_red_hat.service clvmd_activation_script_red_hat.sh
Signature · 1 line
1.7.12.4