summaryrefslogtreecommitdiff
path: root/scripts/lvm2_pvscan_systemd_red_hat@.service.in
diff options
context:
space:
mode:
authorPeter Rajnoha <prajnoha@redhat.com>2013-10-22 14:03:53 +0200
committerPeter Rajnoha <prajnoha@redhat.com>2013-10-22 14:22:40 +0200
commit3fee6610286f83737d193c9047e24e8d7c85d1ce (patch)
treeda55b30be08bb1ee3d5d9395b092cfa1ed207d18 /scripts/lvm2_pvscan_systemd_red_hat@.service.in
parent0a48137d39c51163ee29608c8c7ccbeecb4a7815 (diff)
downloadlvm2-3fee6610286f83737d193c9047e24e8d7c85d1ce.tar.gz
udev+systemd: refine lvm2-pvscan@.service to better track device existence
When using ENV{SYSTEMD_WANTS}=lvm2-pvscan@... to instantiate a service for lvmetad scan when the new PV appears in the system, the service is started and executed. However, to track device removal, we need to bind it (the "BindsTo" systemd directive) to a certain .device systemd unit. In default systemd setup, the device is tracked by it's name and sysfs path (there's normally a sysfs path .device systemd unit for a device and then the device name .device unit as an alias for it). Neither of these two is useful for lvmetad update as we need to bind it to device's <major>:<minor> pair. The /dev/block/<major>:<minor> is the essential symlink under /dev that exists for each block device (created by default udev rules provided by udev directly). So let's use this as an alias for the device's .device unit as well by means of "ENV{SYSTEMD_ALIAS}" declaration within udev rules which systemd understands (this will create a new alias "dev-block-<major>:<minor>.device". Then we can easily bind the "dev-block-<major>:<minor>" device systemd unit with instantiated lvm2-pvscan@<major>:<minor>.service. So once the device is removed from the systemd, the lvm-pvscan@<major>:<minor>.service executes it's ExecStop action (which in turn notifies lvmetad about the device being gone). This completes the udev-systemd-lvmetad interaction then.
Diffstat (limited to 'scripts/lvm2_pvscan_systemd_red_hat@.service.in')
-rw-r--r--scripts/lvm2_pvscan_systemd_red_hat@.service.in11
1 files changed, 7 insertions, 4 deletions
diff --git a/scripts/lvm2_pvscan_systemd_red_hat@.service.in b/scripts/lvm2_pvscan_systemd_red_hat@.service.in
index 9d91b5ecb..07ea5caca 100644
--- a/scripts/lvm2_pvscan_systemd_red_hat@.service.in
+++ b/scripts/lvm2_pvscan_systemd_red_hat@.service.in
@@ -1,11 +1,14 @@
[Unit]
-Description=LVM2 PV scan on %I
+Description=LVM2 PV scan on device %i
Documentation=man:pvscan(8)
DefaultDependencies=no
-After=lvm2-lvmetad.socket %i.device
+BindsTo=dev-block-%i.device
+After=lvm2-lvmetad.socket
Before=shutdown.target
Conflicts=shutdown.target
[Service]
-Type=simple
-ExecStart=@sbindir@/pvscan --cache --activate ay %I
+Type=oneshot
+RemainAfterExit=yes
+ExecStart=@sbindir@/pvscan --cache --activate ay /dev/block/%i
+ExecStop=/usr/sbin/pvscan --cache %i