[systemd-devel] Synchronization Between Services at Shutdown

Kurt von Laven kurt at endlessm.com
Wed Apr 1 18:22:50 PDT 2015

Hello folks,

I am trying to ensure that my system DBus service has time to handle a DBus
method call before it shuts down. My DBus service is implemented as a
system systemd service; let's call it service A. It runs a single-threaded,
synchronous event loop that listens for DBus method calls and handles them
appropriately. This event loop also listens for SIGTERM. When SIGTERM is
received, service A currently terminates the event loop, performs any
necessary writes to disk, and releases its resources. I am assuming that
when the system is shut down cleanly, systemd initially sends SIGTERM to
systemd services and only sends SIGKILL to abort it abruptly if it takes
too long to shut down when asked nicely.

I have another system systemd service, call it service B, that runs an
event loop listening for SIGTERM. When service B receives a SIGTERM, it
makes the aforementioned DBus method call and then flushes the system bus.
Service B specifies Requires=
A and After=
A. Service A makes no mention of service B in its unit configuration file.
Does systemd make any sort of guarantee that service A will get a chance to
handle the DBus method call before receiving SIGTERM, or does my code as
written have a race condition?

Be well,

Kurt von Laven | Endless Mobile | 732.784.7356 |  EndlessM.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20150401/9e8807c2/attachment.html>

More information about the systemd-devel mailing list