RocketChat / docs-old

Rocket.Chat's user documentation.
https://docs.rocket.chat
335 stars 769 forks source link

How to enable systemd template units #2043

Closed sdarwin closed 2 years ago

sdarwin commented 2 years ago

Hi,

Reading the documentation, this text seemed to be logically inconsistent.

The other Services will be enable since they are "WantedBy"=RocketChat.service

Imagine a user wants to enable services on ports 3002, 3003, and 3004. Since these are systemd "templates", where will these numbers (3002, 3003, 3004) be stored and remembered later? The answer, I think, is they will only be retained if you type a command such as

systemctl enable rocketchat@3002

If that's the case, then "The services may be enabled". But not "the other services will be enabled".

From https://unix.stackexchange.com/questions/506347/why-do-most-systemd-examples-contain-wantedby-multi-user-target

"However, WantedBy is separate from the enabled/disabled state: so in another sense, it's sort of a "preset": it determines under what conditions the automatic start may happen, but only when the service is enabled in the first place."

CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.

sdarwin commented 2 years ago

You wrote: "Any other service defined with the WantedBy value as the main service will automatically get started when the main service runs." Not exactly, because the answer is more complicated than that.

For a service to be automatically started, it needs to be enabled, and when it is enabled, that step looks to WantedBy for information. Consider https://www.freedesktop.org/software/systemd/man/systemd.unit.html

WantedBy "A symbolic link is created in the .wants/ or .requires/ directory of each of the listed units when this unit is installed by systemctl enable."

So, WantedBy directs where the symbolic link is created. After a symbolic link is created, that will cause a startup during boot. Simply having WantedBy and nothing else, doesn't cause the automatic startup.

WantedBy + systemctl enable + symbolic link == automatic startup

Rodriq commented 2 years ago

You wrote: "Any other service defined with the WantedBy value as the main service will automatically get started when the main service runs." Not exactly, because the answer is more complicated than that.

For a service to be automatically started, it needs to be enabled, and when it is enabled, that step looks to WantedBy for information. Consider https://www.freedesktop.org/software/systemd/man/systemd.unit.html

WantedBy "A symbolic link is created in the .wants/ or .requires/ directory of each of the listed units when this unit is installed by systemctl enable."

So, WantedBy directs where the symbolic link is created. After a symbolic link is created, that will cause a startup during boot. Simply having WantedBy and nothing else, doesn't cause the automatic startup.

WantedBy + systemctl enable + symbolic link == automatic startup

I saw this note. In the link you shared

"Note: WantedBy= and RequiredBy= are used in the [Install] section to create symlinks in .wants/ and .requires/ directories. They cannot be used directly as a unit configuration setting.

Clear now! Thanks The docs will be updated