Why does an Ubuntu Server have graphical.target as the default systemd target?
Despite the name of the target, there is nothing graphical running on Ubuntu Server 16.04. You can run this command to check and compare it with your desktop distro if you like:
systemctl list-dependencies graphical.target
On my Ubuntu 16.04 server, I see that the targets depend on "display-manager.service", but no display manager is installed or running.
I expect Ubuntu servers are set this way for some kind of consistency, although I agree it's confusing.
From the redhat manual:
For example, the graphical.target unit, which is used to start a graphical session, starts system services such as the GNOME Display Manager (gdm.service) or Accounts Service (accounts-daemon.service) and also activates the multi-user.target unit. Similarly, the multi-user.target unit starts other essential system services such as NetworkManager (NetworkManager.service) or D-Bus (dbus.service) and activates another target unit named basic.target.
So it is not wrong for it to be set since it does not activate the display manager when the service that handles the display service is not set.
For a server you can set it to multi-user.target
but it is not needed.
Looks like you end up on runlevel 4 if you do and runlevel 5 when you don't.
Runlevel Target Units Description
0 runlevel0.target, poweroff.target Shut down and power off the system.
1 runlevel1.target, rescue.target Set up a rescue shell.
2 runlevel2.target, multi-user.target Set up a non-graphical multi-user system.
3 runlevel3.target, multi-user.target Set up a non-graphical multi-user system.
4 runlevel4.target, multi-user.target Set up a non-graphical multi-user system.
5 runlevel5.target, graphical.target Set up a graphical multi-user system.
6 runlevel6.target, reboot.target Shut down and reboot the system.
Inspecting more in details the first level of the tree dependency of the target graphical.target
:
admin@server1604:~$ systemctl list-dependencies graphical.target
graphical.target
● ├─accounts-daemon.service
● ├─apache2.service
● ├─apport.service
● ├─display-manager.service (disabled)
● ├─grub-common.service
● ├─irqbalance.service
● ├─mdadm.service
● ├─ondemand.service
● ├─sysstat.service
● ├─systemd-update-utmp-runlevel.service (disabled)
● ├─ureadahead.service (disabled)
● └─multi-user.target
an comparing it with the first level of the multi-user.target
:
[email protected]:~$ systemctl list-dependencies multi-user.target
multi-user.target
● ├─apache2.service
● ├─apport.service
● ├─atd.service
● ├─cron.service
● ├─dbus.service
● ├─grub-common.service
● ├─irqbalance.service
● ├─lxcfs.service
● ├─lxd-containers.service
● ├─mdadm.service
● ├─networking.service
● ├─ondemand.service
● ├─open-vm-tools.service
...
I notice that if we remove the disabled targets in the graphical.target
tree (display-manager.service
, systemd-update-utmp-runlevel.service
, ureadahead.service
), almost all of the remaining ones :
apache2.service
apport.service
grub-common.service
grub-common.service
irqbalance.service
mdadm.service
ondemand.service
- and
sysstat.service
are already included in the first level of the dependency tree of the multi-user.target
.
Although, we should ask again about this fact, because the graphical.target
depends of the multi-user.target
, there is no need to all this stuff. It sound enough weird.
But after this reduction, it remains one service, the accounts-daemon.service
, like Rinzwind pointed out in its comment.
So we can assume that the graphical.target
is needed to load the accounts-daemon.service
.
However, in that case its again weird, because I thin it would make more sense to create a dedicated target for that purpose, perhaps something like accounts.target
or any correct term to describe it. Anyway, probably Canonical developers had their reasons to make thinks like that.
But I'm stay curious to know its reasons.