There is a service I want to run only when another service fails ([Unit] OnFailure=foo), but I don't want this service (foo) to start up automatically on boot. One option is running systemctl disable foo, but I'm looking for another way.

Background: I am creating an OS image, and I don't want to have to boot the machine up, run that command (systemctl disable foo), then shut it down before declaring my image final.


All services are "disabled" by default; "enablement" is opt-in.

If foo.service is your custom service, then it won't be started unless explicitly pulled in by something (like the OnFailure= directive), and you should not "disable" anything.

  • So basically you "get this functionality for free" unless foo has been enabled previously? – rogerdpack May 9 at 17:59

systemctl enable works by manipulating symlinks in /etc/systemd/system/ (for system daemons). When you enable a service, it looks at the WantedBy lines in the [Install] section, and plops symlinks in those .wants directories.

systemctl disable does the opposite.

You can just remove those symlinks—doing that by hand is fully equivalent to using systemctl disable.

  • This would be a service that hasn't been run by systemd yet (it's custom), so there wouldn't be any of those extra symlinks. I am guessing those would be created on first boot? – Tshepang Apr 21 '15 at 16:43
  • 3
    @Tshepang it shouldn't be enabled unless you enable it manually (or in a script, of course) – derobert Apr 21 '15 at 16:44
  • 1
    Oh, I assumed it would be enabled automatically (which is something I've come to expect by installing Debian packages). Good to know. – Tshepang Apr 21 '15 at 16:45
  • 3
    @Tshepang that's the postinst script in the package doing an enable. Or I guess shipping the symlinks in the package, not sure if they do that. – derobert Apr 21 '15 at 16:47

You can use systemctl start ServiceName.service and systemctl stop Service.Name.service to start and stop a service respectively. In contrast to systemctl enable ... and systemctl disable ..., the start and stop commands only last for the current session, therefore when you reboot the machine the changes wont be saved.

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.