I don't want to remove the service, I just want to avoid its start on boot. I still need the option to start it manually later (with the systemctl start <service> command).

I tried to use systemctl disable <service>. It doesn't work, because it removes the service.

There is another possibility. In its service file,


could be commented out (and then, systemctl daemon-reload). It works in the case of my own services, because their service files was written by me.

However, the service files belonging to distribution, are in /lib/systemd/system. Files in this directory are managed by the OS, i.e. they would be overwritten by updates, other parts of the system might assume that these are unmodified, and so on. Simply editing system files out of the /etc is a bad practice, and I don't want to do that. I don't want to edit configuration files in my /lib.

What to do?

  • 1
    use systemctl disable <service> – eblock May 3 at 10:35
  • 5
    Why would systemctl disable remove a service? I never had that issue, disabling always worked for me. However, editing drop-in files in /etc/systemd/system is actually the desired way, at least that's what I learned. – eblock May 3 at 10:52
  • @eblock Yes, it removes the service. After a systemctl disable <service>, you won't be able to see it in systemctl --all any more. You can enable it again if you wish, and the you can start it, but not this is what I want. I only want it to not start on boot (thus, to remove from the wishlist of multi-user.target). Solving the problem on your way would be a workaround, not the solution. However, if there is no better option, I will need to do that. – peterh May 3 at 10:59
  • Check the output of systemctl disable <service> and the existence of that unit file under /lib. Normally it wouldn't be removed, if it really get removed, then you'll not be able to enable or start it again. systemctl --all doesn't seem to be a valid syntax for systemctl . – 炸鱼薯条德里克 May 3 at 11:40
  • @炸鱼薯条德里克 systemctl --all most definitely is a valid command. – Stephen Kitt May 3 at 11:41

systemctl disable is the correct way to do this; it still allows starting a unit manually, even if it doesn’t appear in systemctl --all’s output — to list all startable units, you should run systemctl list-unit-files instead. To render a unit un-startable, you need to mask it.

$ sudo systemctl stop unbound
$ sudo systemctl status unbound
● unbound.service - Unbound DNS server
   Loaded: loaded (/lib/systemd/system/unbound.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Fri 2019-05-03 13:12:41 CEST; 5s ago
     Docs: man:unbound(8)
 Main PID: 5320 (code=exited, status=0/SUCCESS)

$ sudo systemctl disable unbound
$ sudo systemctl status unbound
● unbound.service - Unbound DNS server
   Loaded: loaded (/lib/systemd/system/unbound.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:unbound(8)

$ sudo systemctl start unbound
$ sudo systemctl status unbound
● unbound.service - Unbound DNS server
   Loaded: loaded (/lib/systemd/system/unbound.service; disabled; vendor preset: enabled)
   Active: active (running) since Fri 2019-05-03 13:13:14 CEST; 1s ago
     Docs: man:unbound(8)
  Process: 30513 ExecStartPre=/usr/lib/unbound/package-helper chroot_setup (code=exited, status=0/SUCCESS)
  Process: 30518 ExecStartPre=/usr/lib/unbound/package-helper root_trust_anchor_update (code=exited, status=0/SUCCESS)
 Main PID: 30525 (unbound)
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/unbound.service
           └─30525 /usr/sbin/unbound -d

If you really want to, you can override system-provided services defined in /lib by adding files in /etc, and change their desired target; systemctl edit yourunit will do the right thing: it opens an editor, allowing you to override only the settings you care about, and it will store the result in the right place, as an override “snippet”. Updates made to non-overridden settings in the system-provided services (e.g. by package upgrades) will be taken into account transparently.

  • If I see it correctly, systemctl edit actually creates some override file, is it true? I think, overriding WantedBy to am empty string would a nice solution, without the duplication of the configuration from the /lib. Is it possible? – peterh May 3 at 11:26
  • Yes, that’s correct. But the correct solution really is systemctl disable. (systemctl start can start a unit which doesn’t appear in systemctl --all.) – Stephen Kitt May 3 at 11:27
  • 2
    And system list-unit-files has also the disabled entries... wonderful. Somewhere I've read this: "Systemd is a quite good OS, only it requires some improvement in its boot mechanism." ;-) – peterh May 3 at 11:37

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.