When we enable any service using systemctl, in which runlevel would that service run?
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
As far as I know when we boot Linux system the services mentioned in runlevels (rcX.d
) would be started.
If we enable any service to start during boot-up using systemctl
command then will that service will be added to that default runlevel?
services systemd
New contributor
add a comment |Â
up vote
3
down vote
favorite
As far as I know when we boot Linux system the services mentioned in runlevels (rcX.d
) would be started.
If we enable any service to start during boot-up using systemctl
command then will that service will be added to that default runlevel?
services systemd
New contributor
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
As far as I know when we boot Linux system the services mentioned in runlevels (rcX.d
) would be started.
If we enable any service to start during boot-up using systemctl
command then will that service will be added to that default runlevel?
services systemd
New contributor
As far as I know when we boot Linux system the services mentioned in runlevels (rcX.d
) would be started.
If we enable any service to start during boot-up using systemctl
command then will that service will be added to that default runlevel?
services systemd
New contributor
edited Sep 6 at 23:27
Kevin Bowen
13.9k145769
13.9k145769
New contributor
asked Sep 6 at 20:31
Shrey Kanna
161
161
New contributor
New contributor
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
Actually no, it does not but you can run:
systemctl show -p WantedBy service-name
to find that in which target it would be run, for example:
systemctl show -p WantedBy tlp.service
WantedBy=multi-user.target
which indicates that if I enable tlp
it would be started when I get into multi-user.target
.
Also worth to mention that run-levels are deprecated and systemd uses target instead:
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ‰ÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ
âÂÂRunlevel â Target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ0 â poweroff.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ1 â rescue.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ2, 3, 4 â multi-user.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ5 â graphical.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ6 â reboot.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ´âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ
Thanks for the answer. First of all I wanna say sorry that I didn't get exactly as I'm new to Linux. My doubts are: 1. where are target files stored in ubuntu? 2. why is run level needed when there's a concept of targets? 3. when we enable any service will that service will be added in rcx.d files also? 4. when system boots from where it will fetch the list of services to start? Thank you.
â Shrey Kanna
Sep 7 at 6:27
add a comment |Â
up vote
0
down vote
As far as I know when we boot Linux system the services mentioned in runlevels (rcX.d) would be started.
This is not true anymore.
The systemd
init system does not natively use a concept of run-levels. Instead, it introduces a concept of "targets" which group other units by using the mechanism of dependencies.
What was a "default runlevel" becomes the default.target
unit which, when activated (started), can "pull in" (activate) other units via requirement dependencies.
(systemd
does provide some compatibility layer for the run-level concept, in form of giving some targets aliases with names like runlevelX.target
, which are then used by the tools like telinit
, but that's about it.
In systemd, a service or any other unit is not required to belong to any of these pseudo-runlevels.)
To enable a service (usually) is to create an artificial dependency between two units.
So, when you enable a service (or any unit), systemd takes a look at that unit's [Install]
section and performs actions specified therein. For example, let's take a look at sshd.service
on my machine:
# /usr/lib/systemd/system/sshd.service
[Unit]
Description=OpenSSH Daemon
Wants=sshdgenkeys.service
After=sshdgenkeys.service
After=network.target
[Service]
ExecStart=/usr/bin/sshd -D
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always
[Install]
WantedBy=multi-user.target
# This service file runs an SSH daemon that forks for each incoming connection.
# If you prefer to spawn on-demand daemons, use sshd.socket and sshd@.service.
When you write systemctl enable sshd.service
, systemd looks at this unit and adds a Wants=
dependency from multi-user.target
to sshd.service
according to the WantedBy=multi-user.target
directive.
(This dependency is physically stored as a symlink from /etc/systemd/system/multi-user.target.wants
to /usr/lib/systemd/system/sshd.service
.)
So, when you boot...
When you boot, default.target
gets activated, along with anything else it pulls in via dependencies. This is called "the initial transaction", and that's it.
Your default.target
is likely an alias to graphical.target
(which Wants=multi-user.target
) or to multi-user.target
directly. Either way, multi-user.target
gets activated and pulls in sshd.service
via the above-mentioned dependency.
thanks for the answer. I have some doubts please clarify it.1. where are target files stored in ubuntu? 2. why is run level needed when there's a concept of targets? 3. when we enable any service will that service will be added in rcx.d files also? 4. when system boots from where it will fetch the list of services to start? Thank you.
â Shrey Kanna
Sep 7 at 6:49
@ShreyKanna 1. Alongside other units, seeman systemd
. 2. It's not. 3. Not necessarily, because enablement is not restricted to WantedBy= from runlevel-mapped targets. 4. When system boots, it startsdefault.target
. Everything else is started by dependency.
â intelfx
Sep 7 at 17:11
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
Actually no, it does not but you can run:
systemctl show -p WantedBy service-name
to find that in which target it would be run, for example:
systemctl show -p WantedBy tlp.service
WantedBy=multi-user.target
which indicates that if I enable tlp
it would be started when I get into multi-user.target
.
Also worth to mention that run-levels are deprecated and systemd uses target instead:
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ‰ÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ
âÂÂRunlevel â Target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ0 â poweroff.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ1 â rescue.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ2, 3, 4 â multi-user.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ5 â graphical.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ6 â reboot.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ´âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ
Thanks for the answer. First of all I wanna say sorry that I didn't get exactly as I'm new to Linux. My doubts are: 1. where are target files stored in ubuntu? 2. why is run level needed when there's a concept of targets? 3. when we enable any service will that service will be added in rcx.d files also? 4. when system boots from where it will fetch the list of services to start? Thank you.
â Shrey Kanna
Sep 7 at 6:27
add a comment |Â
up vote
3
down vote
Actually no, it does not but you can run:
systemctl show -p WantedBy service-name
to find that in which target it would be run, for example:
systemctl show -p WantedBy tlp.service
WantedBy=multi-user.target
which indicates that if I enable tlp
it would be started when I get into multi-user.target
.
Also worth to mention that run-levels are deprecated and systemd uses target instead:
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ‰ÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ
âÂÂRunlevel â Target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ0 â poweroff.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ1 â rescue.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ2, 3, 4 â multi-user.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ5 â graphical.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ6 â reboot.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ´âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ
Thanks for the answer. First of all I wanna say sorry that I didn't get exactly as I'm new to Linux. My doubts are: 1. where are target files stored in ubuntu? 2. why is run level needed when there's a concept of targets? 3. when we enable any service will that service will be added in rcx.d files also? 4. when system boots from where it will fetch the list of services to start? Thank you.
â Shrey Kanna
Sep 7 at 6:27
add a comment |Â
up vote
3
down vote
up vote
3
down vote
Actually no, it does not but you can run:
systemctl show -p WantedBy service-name
to find that in which target it would be run, for example:
systemctl show -p WantedBy tlp.service
WantedBy=multi-user.target
which indicates that if I enable tlp
it would be started when I get into multi-user.target
.
Also worth to mention that run-levels are deprecated and systemd uses target instead:
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ‰ÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ
âÂÂRunlevel â Target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ0 â poweroff.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ1 â rescue.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ2, 3, 4 â multi-user.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ5 â graphical.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ6 â reboot.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ´âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ
Actually no, it does not but you can run:
systemctl show -p WantedBy service-name
to find that in which target it would be run, for example:
systemctl show -p WantedBy tlp.service
WantedBy=multi-user.target
which indicates that if I enable tlp
it would be started when I get into multi-user.target
.
Also worth to mention that run-levels are deprecated and systemd uses target instead:
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ‰ÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ
âÂÂRunlevel â Target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ0 â poweroff.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ1 â rescue.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ2, 3, 4 â multi-user.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ5 â graphical.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¼âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ¤
âÂÂ6 â reboot.target âÂÂ
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâ´âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ
edited Sep 6 at 20:54
answered Sep 6 at 20:41
Ravexina
27.4k146594
27.4k146594
Thanks for the answer. First of all I wanna say sorry that I didn't get exactly as I'm new to Linux. My doubts are: 1. where are target files stored in ubuntu? 2. why is run level needed when there's a concept of targets? 3. when we enable any service will that service will be added in rcx.d files also? 4. when system boots from where it will fetch the list of services to start? Thank you.
â Shrey Kanna
Sep 7 at 6:27
add a comment |Â
Thanks for the answer. First of all I wanna say sorry that I didn't get exactly as I'm new to Linux. My doubts are: 1. where are target files stored in ubuntu? 2. why is run level needed when there's a concept of targets? 3. when we enable any service will that service will be added in rcx.d files also? 4. when system boots from where it will fetch the list of services to start? Thank you.
â Shrey Kanna
Sep 7 at 6:27
Thanks for the answer. First of all I wanna say sorry that I didn't get exactly as I'm new to Linux. My doubts are: 1. where are target files stored in ubuntu? 2. why is run level needed when there's a concept of targets? 3. when we enable any service will that service will be added in rcx.d files also? 4. when system boots from where it will fetch the list of services to start? Thank you.
â Shrey Kanna
Sep 7 at 6:27
Thanks for the answer. First of all I wanna say sorry that I didn't get exactly as I'm new to Linux. My doubts are: 1. where are target files stored in ubuntu? 2. why is run level needed when there's a concept of targets? 3. when we enable any service will that service will be added in rcx.d files also? 4. when system boots from where it will fetch the list of services to start? Thank you.
â Shrey Kanna
Sep 7 at 6:27
add a comment |Â
up vote
0
down vote
As far as I know when we boot Linux system the services mentioned in runlevels (rcX.d) would be started.
This is not true anymore.
The systemd
init system does not natively use a concept of run-levels. Instead, it introduces a concept of "targets" which group other units by using the mechanism of dependencies.
What was a "default runlevel" becomes the default.target
unit which, when activated (started), can "pull in" (activate) other units via requirement dependencies.
(systemd
does provide some compatibility layer for the run-level concept, in form of giving some targets aliases with names like runlevelX.target
, which are then used by the tools like telinit
, but that's about it.
In systemd, a service or any other unit is not required to belong to any of these pseudo-runlevels.)
To enable a service (usually) is to create an artificial dependency between two units.
So, when you enable a service (or any unit), systemd takes a look at that unit's [Install]
section and performs actions specified therein. For example, let's take a look at sshd.service
on my machine:
# /usr/lib/systemd/system/sshd.service
[Unit]
Description=OpenSSH Daemon
Wants=sshdgenkeys.service
After=sshdgenkeys.service
After=network.target
[Service]
ExecStart=/usr/bin/sshd -D
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always
[Install]
WantedBy=multi-user.target
# This service file runs an SSH daemon that forks for each incoming connection.
# If you prefer to spawn on-demand daemons, use sshd.socket and sshd@.service.
When you write systemctl enable sshd.service
, systemd looks at this unit and adds a Wants=
dependency from multi-user.target
to sshd.service
according to the WantedBy=multi-user.target
directive.
(This dependency is physically stored as a symlink from /etc/systemd/system/multi-user.target.wants
to /usr/lib/systemd/system/sshd.service
.)
So, when you boot...
When you boot, default.target
gets activated, along with anything else it pulls in via dependencies. This is called "the initial transaction", and that's it.
Your default.target
is likely an alias to graphical.target
(which Wants=multi-user.target
) or to multi-user.target
directly. Either way, multi-user.target
gets activated and pulls in sshd.service
via the above-mentioned dependency.
thanks for the answer. I have some doubts please clarify it.1. where are target files stored in ubuntu? 2. why is run level needed when there's a concept of targets? 3. when we enable any service will that service will be added in rcx.d files also? 4. when system boots from where it will fetch the list of services to start? Thank you.
â Shrey Kanna
Sep 7 at 6:49
@ShreyKanna 1. Alongside other units, seeman systemd
. 2. It's not. 3. Not necessarily, because enablement is not restricted to WantedBy= from runlevel-mapped targets. 4. When system boots, it startsdefault.target
. Everything else is started by dependency.
â intelfx
Sep 7 at 17:11
add a comment |Â
up vote
0
down vote
As far as I know when we boot Linux system the services mentioned in runlevels (rcX.d) would be started.
This is not true anymore.
The systemd
init system does not natively use a concept of run-levels. Instead, it introduces a concept of "targets" which group other units by using the mechanism of dependencies.
What was a "default runlevel" becomes the default.target
unit which, when activated (started), can "pull in" (activate) other units via requirement dependencies.
(systemd
does provide some compatibility layer for the run-level concept, in form of giving some targets aliases with names like runlevelX.target
, which are then used by the tools like telinit
, but that's about it.
In systemd, a service or any other unit is not required to belong to any of these pseudo-runlevels.)
To enable a service (usually) is to create an artificial dependency between two units.
So, when you enable a service (or any unit), systemd takes a look at that unit's [Install]
section and performs actions specified therein. For example, let's take a look at sshd.service
on my machine:
# /usr/lib/systemd/system/sshd.service
[Unit]
Description=OpenSSH Daemon
Wants=sshdgenkeys.service
After=sshdgenkeys.service
After=network.target
[Service]
ExecStart=/usr/bin/sshd -D
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always
[Install]
WantedBy=multi-user.target
# This service file runs an SSH daemon that forks for each incoming connection.
# If you prefer to spawn on-demand daemons, use sshd.socket and sshd@.service.
When you write systemctl enable sshd.service
, systemd looks at this unit and adds a Wants=
dependency from multi-user.target
to sshd.service
according to the WantedBy=multi-user.target
directive.
(This dependency is physically stored as a symlink from /etc/systemd/system/multi-user.target.wants
to /usr/lib/systemd/system/sshd.service
.)
So, when you boot...
When you boot, default.target
gets activated, along with anything else it pulls in via dependencies. This is called "the initial transaction", and that's it.
Your default.target
is likely an alias to graphical.target
(which Wants=multi-user.target
) or to multi-user.target
directly. Either way, multi-user.target
gets activated and pulls in sshd.service
via the above-mentioned dependency.
thanks for the answer. I have some doubts please clarify it.1. where are target files stored in ubuntu? 2. why is run level needed when there's a concept of targets? 3. when we enable any service will that service will be added in rcx.d files also? 4. when system boots from where it will fetch the list of services to start? Thank you.
â Shrey Kanna
Sep 7 at 6:49
@ShreyKanna 1. Alongside other units, seeman systemd
. 2. It's not. 3. Not necessarily, because enablement is not restricted to WantedBy= from runlevel-mapped targets. 4. When system boots, it startsdefault.target
. Everything else is started by dependency.
â intelfx
Sep 7 at 17:11
add a comment |Â
up vote
0
down vote
up vote
0
down vote
As far as I know when we boot Linux system the services mentioned in runlevels (rcX.d) would be started.
This is not true anymore.
The systemd
init system does not natively use a concept of run-levels. Instead, it introduces a concept of "targets" which group other units by using the mechanism of dependencies.
What was a "default runlevel" becomes the default.target
unit which, when activated (started), can "pull in" (activate) other units via requirement dependencies.
(systemd
does provide some compatibility layer for the run-level concept, in form of giving some targets aliases with names like runlevelX.target
, which are then used by the tools like telinit
, but that's about it.
In systemd, a service or any other unit is not required to belong to any of these pseudo-runlevels.)
To enable a service (usually) is to create an artificial dependency between two units.
So, when you enable a service (or any unit), systemd takes a look at that unit's [Install]
section and performs actions specified therein. For example, let's take a look at sshd.service
on my machine:
# /usr/lib/systemd/system/sshd.service
[Unit]
Description=OpenSSH Daemon
Wants=sshdgenkeys.service
After=sshdgenkeys.service
After=network.target
[Service]
ExecStart=/usr/bin/sshd -D
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always
[Install]
WantedBy=multi-user.target
# This service file runs an SSH daemon that forks for each incoming connection.
# If you prefer to spawn on-demand daemons, use sshd.socket and sshd@.service.
When you write systemctl enable sshd.service
, systemd looks at this unit and adds a Wants=
dependency from multi-user.target
to sshd.service
according to the WantedBy=multi-user.target
directive.
(This dependency is physically stored as a symlink from /etc/systemd/system/multi-user.target.wants
to /usr/lib/systemd/system/sshd.service
.)
So, when you boot...
When you boot, default.target
gets activated, along with anything else it pulls in via dependencies. This is called "the initial transaction", and that's it.
Your default.target
is likely an alias to graphical.target
(which Wants=multi-user.target
) or to multi-user.target
directly. Either way, multi-user.target
gets activated and pulls in sshd.service
via the above-mentioned dependency.
As far as I know when we boot Linux system the services mentioned in runlevels (rcX.d) would be started.
This is not true anymore.
The systemd
init system does not natively use a concept of run-levels. Instead, it introduces a concept of "targets" which group other units by using the mechanism of dependencies.
What was a "default runlevel" becomes the default.target
unit which, when activated (started), can "pull in" (activate) other units via requirement dependencies.
(systemd
does provide some compatibility layer for the run-level concept, in form of giving some targets aliases with names like runlevelX.target
, which are then used by the tools like telinit
, but that's about it.
In systemd, a service or any other unit is not required to belong to any of these pseudo-runlevels.)
To enable a service (usually) is to create an artificial dependency between two units.
So, when you enable a service (or any unit), systemd takes a look at that unit's [Install]
section and performs actions specified therein. For example, let's take a look at sshd.service
on my machine:
# /usr/lib/systemd/system/sshd.service
[Unit]
Description=OpenSSH Daemon
Wants=sshdgenkeys.service
After=sshdgenkeys.service
After=network.target
[Service]
ExecStart=/usr/bin/sshd -D
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always
[Install]
WantedBy=multi-user.target
# This service file runs an SSH daemon that forks for each incoming connection.
# If you prefer to spawn on-demand daemons, use sshd.socket and sshd@.service.
When you write systemctl enable sshd.service
, systemd looks at this unit and adds a Wants=
dependency from multi-user.target
to sshd.service
according to the WantedBy=multi-user.target
directive.
(This dependency is physically stored as a symlink from /etc/systemd/system/multi-user.target.wants
to /usr/lib/systemd/system/sshd.service
.)
So, when you boot...
When you boot, default.target
gets activated, along with anything else it pulls in via dependencies. This is called "the initial transaction", and that's it.
Your default.target
is likely an alias to graphical.target
(which Wants=multi-user.target
) or to multi-user.target
directly. Either way, multi-user.target
gets activated and pulls in sshd.service
via the above-mentioned dependency.
edited Sep 7 at 0:41
answered Sep 7 at 0:34
intelfx
24515
24515
thanks for the answer. I have some doubts please clarify it.1. where are target files stored in ubuntu? 2. why is run level needed when there's a concept of targets? 3. when we enable any service will that service will be added in rcx.d files also? 4. when system boots from where it will fetch the list of services to start? Thank you.
â Shrey Kanna
Sep 7 at 6:49
@ShreyKanna 1. Alongside other units, seeman systemd
. 2. It's not. 3. Not necessarily, because enablement is not restricted to WantedBy= from runlevel-mapped targets. 4. When system boots, it startsdefault.target
. Everything else is started by dependency.
â intelfx
Sep 7 at 17:11
add a comment |Â
thanks for the answer. I have some doubts please clarify it.1. where are target files stored in ubuntu? 2. why is run level needed when there's a concept of targets? 3. when we enable any service will that service will be added in rcx.d files also? 4. when system boots from where it will fetch the list of services to start? Thank you.
â Shrey Kanna
Sep 7 at 6:49
@ShreyKanna 1. Alongside other units, seeman systemd
. 2. It's not. 3. Not necessarily, because enablement is not restricted to WantedBy= from runlevel-mapped targets. 4. When system boots, it startsdefault.target
. Everything else is started by dependency.
â intelfx
Sep 7 at 17:11
thanks for the answer. I have some doubts please clarify it.1. where are target files stored in ubuntu? 2. why is run level needed when there's a concept of targets? 3. when we enable any service will that service will be added in rcx.d files also? 4. when system boots from where it will fetch the list of services to start? Thank you.
â Shrey Kanna
Sep 7 at 6:49
thanks for the answer. I have some doubts please clarify it.1. where are target files stored in ubuntu? 2. why is run level needed when there's a concept of targets? 3. when we enable any service will that service will be added in rcx.d files also? 4. when system boots from where it will fetch the list of services to start? Thank you.
â Shrey Kanna
Sep 7 at 6:49
@ShreyKanna 1. Alongside other units, see
man systemd
. 2. It's not. 3. Not necessarily, because enablement is not restricted to WantedBy= from runlevel-mapped targets. 4. When system boots, it starts default.target
. Everything else is started by dependency.â intelfx
Sep 7 at 17:11
@ShreyKanna 1. Alongside other units, see
man systemd
. 2. It's not. 3. Not necessarily, because enablement is not restricted to WantedBy= from runlevel-mapped targets. 4. When system boots, it starts default.target
. Everything else is started by dependency.â intelfx
Sep 7 at 17:11
add a comment |Â
Shrey Kanna is a new contributor. Be nice, and check out our Code of Conduct.
Shrey Kanna is a new contributor. Be nice, and check out our Code of Conduct.
Shrey Kanna is a new contributor. Be nice, and check out our Code of Conduct.
Shrey Kanna is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1072884%2fwhen-we-enable-any-service-using-systemctl-in-which-runlevel-would-that-service%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password