2

I recently noticed a server performing apt-get update && apt-get dist-upgrade

Amongst other things, docker was updated and restarted.

However, I noticed some changes I made to the service file previously were now gone. The file at /lib/systemd/system/docker.service seems to have been reset.

Is this possible? I don't recall if I ran daemon-reload after these changes.

EDIT: To be clear: I'm wondering is dist-upgrade basically removed the service file and replaced it with a default one?

And does daemon-reload prevent this in the future?

EDIT2: Ok, looks like sudo systemctl edit docker.service is the way to go and performs a daemon-reload on save.

3
  • 6
    Does this answer your question? How do I override or configure systemd services?
    – muru
    Jun 25, 2021 at 11:13
  • @muru No, my question is more "did dist-upgrade forcibly replace the entire service file with a new one, ignoring the existing one?"
    – KdgDev
    Jun 25, 2021 at 12:39
  • 2
    @muru Ah, I read a bit further and it does detail not to edit /lib/systemd/ files. Yeah this is going to be it.
    – KdgDev
    Jun 25, 2021 at 12:43

1 Answer 1

9

Don't edit files in /lib/systemd/ or /usr/share/systemd as they will get overwritten on updates.

Instead, copy the file to /etc/systemd/ and make the changes there.

The /etc/ directory (at least for systemd) is considered the place to store local config files. All other /**/systemd/ directories are considered sources of default and sample config files that should be replaced on any upgrade.

Another reason to not edit these package supplied config files is that if you copy it to /etc/systemd/... and edit it and make a mistake, you can always compare with the original file.

systemctl daemon-reload doesn't prevent anything. It just tells systemd to re-examine all of its config and use whatever has changed.

9
  • think /usr/local/lib/systemd/system/ is better than /etc/systemd... 1
    – user986805
    Jun 25, 2021 at 13:11
  • @bac0n the systemd-sanctioned location is /etc/systemd. That’s what systemctl edit uses. Jun 25, 2021 at 20:51
  • I wouldn't edit the one in /usr/local/lib/systemd either, I'd copy that to /etc/systemd as well before editing.
    – user10489
    Jun 25, 2021 at 22:20
  • @StephenKitt, what you suggest is something completely different and deserves its own answer and even be the preferred one, still, I think, copying files to /etc/systemd/ is not recommended, e.g., you lose the ability to mask units.
    – user986805
    Jun 26, 2021 at 6:20
  • 3
    @bac0n it’s already covered in muru’s answer here, no point in duplicating it IMO ;-). Jun 26, 2021 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.