What is the difference between "systemctl start" and "systemctl enable"?
I installed MariaDB-server to my machine. While setting up I met with a problem whether I have to enable it all the time as the document I follow is given with these steps,
sudo yum install mariadb mariadb-server
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
systemctl start
and systemctl enable
do different things.
enable
will hook the specified unit into relevant places, so that it will automatically start on boot, or when relevant hardware is plugged in, or other situations depending on what's specified in the unit file.
start
starts the unit right now.
disable
and stop
are the opposite of these, respectively.
This means that when you first install MariaDB, you might want to run systemctl enable mariadb.service
to enable it so it starts on boot. You might also want to run systemctl start mariadb.service
, or just reboot, in order to start MariaDB. To stop MariaDB, run systemctl stop mariadb.service
(it will start again on next boot or when you manually start it). To disable it so it doesn't start on boot anymore, run systemctl disable mariadb.service
.
Source: systemctl man page
From the systemctl
manpage:
enable NAME...
Enable one or more unit files or unit file instances, as specified
on the command line. This will create a number of symlinks as
encoded in the "[Install]" sections of the unit files. After the
symlinks have been created, the systemd configuration is reloaded
(in a way that is equivalent to daemon-reload) to ensure the
changes are taken into account immediately. Note that this does not
have the effect of also starting any of the units being enabled. If
this is desired, either --now should be used together with this
command, or an additional start command must be invoked for the
unit.
...
Enabling units should not be confused with starting (activating)
units, as done by the start command. Enabling and starting units is
orthogonal: units may be enabled without being started and started
without being enabled. Enabling simply hooks the unit into various
suggested places (for example, so that the unit is automatically
started on boot or when a particular kind of hardware is plugged
in). Starting actually spawns the daemon process (in case of
service units), or binds the socket (in case of socket units), and
so on.
Essentially, enable
marks the service for starting up on boot, and start
actually starts the service immediately.