265

Let's say I write a mine.service file. Then I use systemctl enable mine.service.

If I later decide to edit mine.service, do I have to tell systemd that mine.service was changed? If so, how do I do that?

425nesp
  • 2,892
  • 2
  • 12
  • 8

2 Answers2

312

After you make changes to your unit file, you should run systemctl daemon-reload, as outlined here.

daemon-reload
Reload systemd manager configuration. This will rerun all generators (see systemd.generator(7)), reload all unit files, and recreate the entire dependency tree. While the daemon is being reloaded, all sockets systemd listens on behalf of user configuration will stay accessible.

You can then restart (or reload) your service as you desire with

systemctl restart your-service-name

(daemon-reload won't reload/restart the services themselves, just makes systemd aware of the new configuration)

hwjp
  • 398
  • 5
  • 7
GregL
  • 9,370
  • 2
  • 25
  • 36
  • 3
    I found I also needed to run a `systemctl restart` to actually restart the service itself... – hwjp Oct 04 '16 at 20:52
  • 17
    Just in case, `daemon-reload` isn't universal, have got to run `systemctl --user daemon-reload` for user services. – Alec Mev Jan 25 '18 at 22:06
  • As a note it also "delete the previous configuration created by generators" before rerunning them: https://www.freedesktop.org/software/systemd/man/systemd.generator.html – rogerdpack May 09 '19 at 17:22
  • 2
    Bit of a syntax complaint but should != must. And must it is, which feels lame because systemctl is smart enough to tell you that you need to reload it, but won't reload itself. – Kevin Mar 04 '21 at 06:08
  • Yeah, you’re absolutely right, it does need to be run after changing a unit. – GregL Mar 04 '21 at 18:52
39

As an addition to the answer above: In case you changed something in the [Install] directive, you may need to run sudo systemctl reenable YOURUNITFILE in order to recreate the symlinks in the .target directories.

HomelessGamer
  • 491
  • 4
  • 3