0

I am using Linux Mint 20.3 Cinnamon

$ systemctl --user get-default
default.target
$ ls -al /lib/systemd/system/default.target
lrwxrwxrwx 1 root 16 Jan 10 05:56 /lib/systemd/system/default.target -> graphical.target
$ \cat /lib/systemd/system/default.target
#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit] Description=Graphical Interface Documentation=man:systemd.special(7) Requires=multi-user.target Wants=display-manager.service Conflicts=rescue.service rescue.target After=multi-user.target rescue.service rescue.target display-manager.service AllowIsolate=yes

  • I have default.target located in 2 different locations with different contents as follows:
$ \cat ~/.config/systemd/user/default.target
#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit] Description=Main User Target Documentation=man:systemd.special(7) Requires=basic.target After=basic.target AllowIsolate=yes

Question

  1. How to specify /lib/systemd/system/default.target inside a service unit file, for a user unit?
  2. How to know which default target is used by a particular service unit file?
  3. systemctl --user get-default refers to which of these default.target?
Porcupine
  • 1,892

1 Answers1

1

For knowing the current locations of a target, just query the status, e.g.:

systemctl --user status default.target

● default.target - Main User Target Loaded: loaded (/usr/lib/systemd/user/default.target; static) [...]

systemctl status default.target ● graphical.target - Graphical Interface Loaded: loaded (/lib/systemd/system/graphical.target; indirect; vendor preset: enabled) [...]

The order of where units are searched is given in the manuals (as system/user unit search path)

That means if I just create a dummy target in my local .config-dir and start it, it gets loaded first, as its position is higher in the search path:

$cat ~/.config/systemd/user/default.target

[Unit] Description=just exists

$systemctl --user daemon-reload $systemctl --user start default.target $systemctl --user status default.target

● default.target - just exists Loaded: loaded (/home/felixjn/.config/systemd/user/default.target; static)

I.e. the unit serach path is just like the $PATH variable from shells: the first for a unit match will be taken.

The important part is to know, that user and system paths differ and do not overlap!

FelixJN
  • 13,566
  • I am trying to start Firefox (user service file saved at ~/.config/systemd/user), if I write WantedBy=default.target and enable the service, which of these default target is this referring to? Basically its a GUI application so I want it to start after the GUI has loaded. – Porcupine Jan 14 '22 at 11:39
  • As said: it is a user service so it uses the user default.target -> systemctl --user status default.target .... should be /usr/lib/systemd/user/default.target – FelixJN Jan 14 '22 at 11:47
  • 1
    It is mentioned in https://wiki.archlinux.org/title/Systemd/User that User units can not reference or depend on system units or units of other users. So, is /usr/lib/systemd/user/default.target, a user or a system unit file? – Porcupine Jan 14 '22 at 11:49
  • 1
    It is a user unit, as it is in the /usr/lib/systemd/**user**/default.target. But it is a system-wide one that would apply to all users - I assume that is source of your confusion? – FelixJN Jan 14 '22 at 11:51