<div dir="ltr">Thanks for the quick reply, Andrei. It sounds like there is indeed a race condition in my code then since there is nothing explicit in my implementation of service A that makes it wait until it has processed the method call from service B before it stops listening for method calls. Did I get that right?<div class="gmail_extra"><br><div class="gmail_quote">On Wed, Apr 1, 2015 at 8:26 PM, Andrei Borzenkov <span dir="ltr"><<a href="mailto:arvidjaar@gmail.com" target="_blank">arvidjaar@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">В Wed, 1 Apr 2015 18:22:50 -0700<br>
Kurt von Laven <<a href="mailto:kurt@endlessm.com">kurt@endlessm.com</a>> пишет:<br>
<span class=""><br>
> Hello folks,<br>
><br>
> I am trying to ensure that my system DBus service has time to handle a DBus<br>
> method call before it shuts down. My DBus service is implemented as a<br>
> system systemd service; let's call it service A. It runs a single-threaded,<br>
> synchronous event loop that listens for DBus method calls and handles them<br>
> appropriately. This event loop also listens for SIGTERM. When SIGTERM is<br>
> received, service A currently terminates the event loop, performs any<br>
> necessary writes to disk, and releases its resources. I am assuming that<br>
> when the system is shut down cleanly, systemd initially sends SIGTERM to<br>
> systemd services and only sends SIGKILL to abort it abruptly if it takes<br>
> too long to shut down when asked nicely.<br>
><br>
> I have another system systemd service, call it service B, that runs an<br>
> event loop listening for SIGTERM. When service B receives a SIGTERM, it<br>
> makes the aforementioned DBus method call and then flushes the system bus.<br>
> Service B specifies Requires=<br>
</span>> <<a href="http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Requires=" target="_blank">http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Requires=</a>>Service<br>
> A and After=<br>
> <<a href="http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Before=" target="_blank">http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Before=</a>>Service<br>
<span class="">> A. Service A makes no mention of service B in its unit configuration file.<br>
> Does systemd make any sort of guarantee that service A will get a chance to<br>
> handle the DBus method call before receiving SIGTERM, or does my code as<br>
> written have a race condition?<br>
><br>
<br>
</span>systemd will not initiate stopping of A before B has stopped. If it<br>
does, this should be considered a bug. So it is up to service B to<br>
handle termination correctly. Note that systemd will send SIGKILL after<br>
timeout if service has not terminated.<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><span><span style="font-size:15px;font-family:Arial;color:rgb(183,183,183);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">Kurt von Laven | Endless Mobile |  </span><a href="http://endlessm.com/" style="text-decoration:none" target="_blank"><span style="font-size:15px;font-family:Arial;color:rgb(183,183,183);background-color:transparent;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap">EndlessM.com</span></a></span><br></div></div>
</div></div>