В чем разница между "systemctl start" и "systemctl enable"?

Я установил MariaDB-сервер на свою машину. При настройке я столкнулся с проблемой, должен ли я включать его все время, поскольку документ, которому я следую, предоставляется с этими шагами,

sudo yum install mariadb mariadb-server 
sudo systemctl start mariadb.service  
sudo systemctl enable mariadb.service

3 ответа

Решение

systemctl start а также systemctl enable делать разные вещи.

enable подключит указанный модуль в соответствующие места, чтобы он автоматически запускался при загрузке или при подключении соответствующего оборудования, или в других ситуациях, в зависимости от того, что указано в файле модуля.

start запускает устройство прямо сейчас.

disable а также stop являются противоположностью этому, соответственно.

Это означает, что при первой установке MariaDB вы можете запустить systemctl enable mariadb.service чтобы включить его, чтобы он запускался при загрузке. Вы также можете запустить systemctl start mariadb.serviceили просто перезагрузитесь, чтобы запустить MariaDB. Чтобы остановить MariaDB, беги systemctl stop mariadb.service (он снова запустится при следующей загрузке или при запуске вручную). Чтобы отключить его, чтобы он больше не запускался при загрузке, запустите systemctl disable mariadb.service,

Источник: manctl systemctl

Из systemctl man-страница:

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.

По существу, enable помечает службу для запуска при загрузке и start фактически запускает службу немедленно.

Начиная с версии 220 systemctl, включите и отключите поддержку ключа --now для запуска / остановки служб одновременно с включением / отключением.

например systemctl --now enable foobar.service

использование systemctl --version проверить установленную версию.

Другие вопросы по тегам