Linux Basics - Services

hi

In module " Linux Basics - Services " What is difference between these two commands

  1. Within a service unit file " [ Install ] WantedBy =multi-user.target " &
  2. #systemctl enable docker ( or any other service name ) .

with best regards
Pradeep Nehe

1 Like

Hello, @ppnehe
To start a service at boot time. If you’ll not enable the service. In that condition, that service will work till the system is up and after reboot it won’t work. Service status is marked as stopped.

You can refer this source link to understand what is WantedBy, multi-user and .target.

If I’m not mistaken, WantedBy is only looked at when the service is enabled. In other words, unless a service is enabled, the WantedBy field is ignored altogether and the service won’t start up.

It’s a feature that should emulate runlevels, which came from init systems that were used before systemd came along. These runlevels can be seen as a group of services that you might want to start together.

On the other hand, if a service is enabled, and WantedBy is not specified, systemd will just start the service when all of its dependencies are up-and-running (regardless of the runlevel that the system is running in).

EDIT: seems I’m wrong:

2.) if you omit the WantedBy=multi-user.target line and no other enabled service includes a Requires=your.service or Wants=your.service in its service definition, your service will not be started automatically.

This is the dependencies handling mechanism in systemd. multi-user.target is the alternative for runlevel 3 in systemd world. That said, reaching multi-user.target includes starting the “Confluent ZooKeeper” service. Probably that’s what you need indeed