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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
Method 2
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.
Method 3
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0