22

Can someone clarify for me difference between "enable" and "start" for a systemd unit. I have been told that if a unit has an [Install] section, then enable should be called, otherwise just start is enough.

How this handled in startup process? Systemd automagically makes right decision?

2
  • Systemd/systemctl does not have an activate command, do you mean start?
    – Wieland
    Aug 9, 2016 at 10:54
  • Yeap, start - for activate. Aug 9, 2016 at 11:01

2 Answers 2

32

To start (activate) a service , you will run the command systemctl start my_service.service, this will start the service immediately in the current session.

To enable a service at boot , you will run systemctl enable my_service.service .

Enable one or more units or unit instances. This will create a set of symlinks, as encoded in the "[Install]" sections of the indicated unit files. After the symlinks have been created, the system manager configuration is reloaded (in a way equivalent to daemon-reload), in order to ensure the changes are taken into account immediately

The /usr/lib/systemd/system/ contains init scripts , when you type systemctl enable to start a service at boot it will be linked to /etc/systemd/system/.

#systemctl enable my_service.service
ln -s '/usr/lib/systemd/system/my_service.service' '/etc/systemd/system/multi-user.target.wants/my_service.service'
1
  • 1
    under "init scripts" you mean unit files ? Aug 9, 2016 at 16:52
12

systemctl enable configures the system to start the service at next reboot (with caveats around correct target states, etc).

systemctl start starts (activates) the service immediately.

So if you want a service to start now and on every reboot then you need to both enable and start the service.

2
  • 22
    The last sentence is not true: systemctl enable --now will both start and enable a unit.
    – Wieland
    Aug 9, 2016 at 12:07
  • I really wish this showed in systemctl --help. It's in the manpage, but buried in a paragraph, which is not usually how subcommand options are listed in manpages. I always struggle to locate this option as I don't need it often and never seem to remember if it's a systemctl start or systemctl enable option. :-/
    – bobpaul
    Apr 12, 2020 at 19:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .