[systemd-devel] automatically restarting services on file changes

Simon McVittie smcv at collabora.com
Mon Jul 19 13:45:15 UTC 2021


On Tue, 13 Jul 2021 at 23:37:49 -0300, Webstrucs wrote:
> when I make any changes in this
> file it is necessary to restart the [service] in order to get the updates. Is there
> any way to implement [an automatic restart] so
> that you no longer need to use restarting the service when there are changes in
> the related file in python ?

Michael already said how this *can* be implemented.

Another relevant question here is whether this *should* be implemented.
It'll certainly be very convenient during development, but I would not
recommend having this mechanism during production use.

dbus (dbus-daemon) uses inotify to automatically schedule a configuration
reload when its .conf or .service files are changed. This seemed very
attractive at the time it was implemented, but it turns out to have been
a bad idea: if a file is written, that doesn't necessarily mean it has
immediately reached its final state. In particular, a real-world service
usually consists of more than one file, and if changes are being made
to several files, it's easy to get into a situation where one file has
been updated, but a second file has not, and until the second file is
also updated the service is in a broken state.

systemd learned from dbus' mistakes here: it does not automatically reload
when its configuration or units are changed, only when it is explicitly
told to reload via the "systemctl daemon-reload" command (or equivalent),
which is done (either automatically or manually) when all files have
been written and the overall system has reached a consistent state again.

I would recommend making a production service less like dbus-daemon and
more like systemd - only reloading or restarting when a consistent state
has been reached.

    smcv


More information about the systemd-devel mailing list