Skip to contentSkip to conversation

dmeventd: ensure systemd service gets stopped on shutdown

RFC In review Thomas Lamprecht 2 participants 5 messages Oct 2, 2017 – Oct 5, 2017

lore
Share & tools
lore
#0 lore raw

RFC 1/1 dmeventd: ensure systemd service gets stopped on shutdown

The service pf dmeventd, dm-eventd.service, uses 'DefaultDependencies=no' as it wants to start up very early in the boot process.
But, this also removed the implicit 'Conflicts' and 'Before' settings to the shutdown target, which is in charge of stopping all service gracefully on poweroff, reboot or halt.
This caused that the service was not stopped on shutdown by the normal systemd shutdown process, but only once the systemd-shutdown service took over the role of PID 1 and sent first a SIGTERM then - after DEFAULT_TIMEOUT_USEC (90 seconds) of waiting, a SIGKILL to all remaining processes.
dmeventd only exits if at the next main loop iteration after the time where the signal was received all threads are idle, else the exit request gets simply ignored (not queued).

Lets add the shutdown target conflict again, so that it gets stopped during the normal systemd shutdown process, previous to reaching shutdown.target.
First, this allows the user o notice more easily the offending process as its logged with journald still operating - which isn't the case once systemd-shutdown took over the PID 1 role. Secondly, at this stage the shutdown of dmeventd seems to succeed always, interestingly. This could be explained by the sync which systemd-shutdown triggers before broadcasting SIGTERM and SIGKILL. This sync could change (meta)data from a monitored dm device and thus keep dmeventd from exiting as _idle_since is 0.

---

The last part where I try make sense out of the differing behavior if systemd-shutdown sends the SIGTERM or systemd previous to that sends it is speculation, albeit not complete unreasonable one. RFC for that matter and for the matter that I do not yet have in-depth knowledge of dmeventd and its users.

 scripts/dm_event_systemd_red_hat.service.in | 2 ++
 1 file changed, 2 insertions(+)
scripts/dm_event_systemd_red_hat.service.in +2 -0
index 7c607aaf2..a3284c810 100644
@@ -4,6 +4,8 @@ Documentation=man:dmeventd(8)
 Requires=dm-event.socket
 After=dm-event.socket
 Before=local-fs-pre.target
+Before=shutdown.target
+Conflicts=shutdown.target
 DefaultDependencies=no
 
 [Service]
Signature · 1 line
2.11.0
#1 lore raw

scripts/dm_event_systemd_red_hat.service.in Documentation=man:dmeventd(8) · line 10

Quoted 12 lines · Thomas Lamprecht
scripts/dm_event_systemd_red_hat.service.in +2 -0
index 7c607aaf2..a3284c810 100644
@@ -4,6 +4,8 @@ Documentation=man:dmeventd(8)
 Requires=dm-event.socket
 After=dm-event.socket
 Before=local-fs-pre.target
+Before=shutdown.target
+Conflicts=shutdown.target
 DefaultDependencies=no
 

Hi!

Yes, we should be able to make cleaner ordering of these services. By design, the dm-event.service is supposed to be stopped after all the monitoring clients command dmeventd to unmonitor particular devices belonging to a subsystem (like LVM with "vgchange --monitor n" that is part of lvm2-monitor.service).

At this moment, we just let the dmeventd to get stopped/killed when the last SIGTERM signal is sent to all remaining processes on shutdown. But I agree it would be cleaner to do this as part of proper "service stop" action for dm-event.service (that would be executed as part of
Conflicts: shutdown.target which you reference in your patch).

Unfortunately, there's a bug which we need to fix first for this to work correctly, I've filed it here:
https://bugzilla.redhat.com/show_bug.cgi?id=1498080

Signature · 1 line
Peter
#2 lore raw
Quoted 28 lines · Peter Rajnoha

scripts/dm_event_systemd_red_hat.service.in Documentation=man:dmeventd(8) · line 10

Quoted 12 lines · Thomas Lamprecht
scripts/dm_event_systemd_red_hat.service.in +2 -0
index 7c607aaf2..a3284c810 100644
@@ -4,6 +4,8 @@ Documentation=man:dmeventd(8)
 Requires=dm-event.socket
 After=dm-event.socket
 Before=local-fs-pre.target
+Before=shutdown.target
+Conflicts=shutdown.target
 DefaultDependencies=no
 

Hi!

Yes, we should be able to make cleaner ordering of these services. By design, the dm-event.service is supposed to be stopped after all the monitoring clients command dmeventd to unmonitor particular devices belonging to a subsystem (like LVM with "vgchange --monitor n" that is part of lvm2-monitor.service).

At this moment, we just let the dmeventd to get stopped/killed when the last SIGTERM signal is sent to all remaining processes on shutdown. But I agree it would be cleaner to do this as part of proper "service stop" action for dm-event.service (that would be executed as part of
Conflicts: shutdown.target which you reference in your patch).

Quoted 4 lines

Unfortunately, there's a bug which we need to fix first for this to work correctly, I've filed it here:
https://bugzilla.redhat.com/show_bug.cgi?id=1498080

I'm running in exactly this bug for a while now quite consistently, this was the cause for my initial investigation and also this patch.

As with the ordering enforced dm-eventd.service will be terminated directly after lvm2-monitor.service instead of a bit later where normal service termination is already finished.

I had initially also the idea for queuing the exit, i.e. set _exit_now to 2 and log once that web could not exit immediately but exit is scheduled and then wait for the next possible moment where we may really exit. Optionally we could avoid running new threads if a exit request is pending.

cheers,
Thomas

#3 lore raw
Quoted 29 lines · Thomas Lamprecht
Quoted 28 lines · Peter Rajnoha

scripts/dm_event_systemd_red_hat.service.in Documentation=man:dmeventd(8) · line 10

Quoted 12 lines · Thomas Lamprecht
scripts/dm_event_systemd_red_hat.service.in +2 -0
index 7c607aaf2..a3284c810 100644
@@ -4,6 +4,8 @@ Documentation=man:dmeventd(8)
 Requires=dm-event.socket
 After=dm-event.socket
 Before=local-fs-pre.target
+Before=shutdown.target
+Conflicts=shutdown.target
 DefaultDependencies=no
 

Hi!

Yes, we should be able to make cleaner ordering of these services. By design, the dm-event.service is supposed to be stopped after all the monitoring clients command dmeventd to unmonitor particular devices belonging to a subsystem (like LVM with "vgchange --monitor n" that is part of lvm2-monitor.service).

At this moment, we just let the dmeventd to get stopped/killed when the last SIGTERM signal is sent to all remaining processes on shutdown. But I agree it would be cleaner to do this as part of proper "service stop" action for dm-event.service (that would be executed as part of
Conflicts: shutdown.target which you reference in your patch).

Quoted 8 lines
Quoted 4 lines

Unfortunately, there's a bug which we need to fix first for this to work correctly, I've filed it here:
https://bugzilla.redhat.com/show_bug.cgi?id=1498080

I'm running in exactly this bug for a while now quite consistently, this was the cause for my initial investigation and also this patch.

The bug is now fixed:

https://www.redhat.com/archives/lvm-devel/2017-October/msg00004.html

So I've pushed your patched too:

https://www.redhat.com/archives/lvm-devel/2017-October/msg00006.html

Thanks.

Signature · 1 line
Peter
#4 lore raw
Quoted 38 lines · Peter Rajnoha
Quoted 29 lines · Thomas Lamprecht
Quoted 28 lines · Peter Rajnoha

scripts/dm_event_systemd_red_hat.service.in Documentation=man:dmeventd(8) · line 10

Quoted 12 lines · Thomas Lamprecht
scripts/dm_event_systemd_red_hat.service.in +2 -0
index 7c607aaf2..a3284c810 100644
@@ -4,6 +4,8 @@ Documentation=man:dmeventd(8)
 Requires=dm-event.socket
 After=dm-event.socket
 Before=local-fs-pre.target
+Before=shutdown.target
+Conflicts=shutdown.target
 DefaultDependencies=no
 

Hi!

Yes, we should be able to make cleaner ordering of these services. By design, the dm-event.service is supposed to be stopped after all the monitoring clients command dmeventd to unmonitor particular devices belonging to a subsystem (like LVM with "vgchange --monitor n" that is part of lvm2-monitor.service).

At this moment, we just let the dmeventd to get stopped/killed when the last SIGTERM signal is sent to all remaining processes on shutdown. But I agree it would be cleaner to do this as part of proper "service stop" action for dm-event.service (that would be executed as part of
Conflicts: shutdown.target which you reference in your patch).

Quoted 8 lines
Quoted 4 lines

Unfortunately, there's a bug which we need to fix first for this to work correctly, I've filed it here:
https://bugzilla.redhat.com/show_bug.cgi?id=1498080

I'm running in exactly this bug for a while now quite consistently, this was the cause for my initial investigation and also this patch.

Quoted 8 lines

The bug is now fixed:

https://www.redhat.com/archives/lvm-devel/2017-October/msg00004.html

So I've pushed your patched too:

https://www.redhat.com/archives/lvm-devel/2017-October/msg00006.html

Thanks, perfect!