Skip to content

Commit c92fcc4

Browse files
authored
units: add graphical-session.target user unit (systemd#3678)
This unit acts as a dynamic "alias" target for any concrete graphical user session like gnome-session.target; these should declare "BindsTo=graphical-session.target" so that both targets stop and start at the same time. This allows services that run in a particular graphical user session (e. g. gnome-settings-daemon.service) to declare "PartOf=graphical-session.target" without having to know or get updated for all/new session types. This will ensure that stopping the graphical session will stop all services which are associated to it.
1 parent 38b383d commit c92fcc4

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,8 @@ endif
573573
dist_userunit_DATA = \
574574
units/user/basic.target \
575575
units/user/default.target \
576-
units/user/exit.target
576+
units/user/exit.target \
577+
units/user/graphical-session.target
577578

578579
nodist_userunit_DATA = \
579580
units/user/systemd-exit.service

man/systemd.special.xml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,57 @@
878878
<filename>sound.target</filename>.</para>
879879
</refsect1>
880880

881+
<refsect1>
882+
<title>Special Passive User Units</title>
883+
884+
<refsect2>
885+
<title>graphical-session.target</title>
886+
887+
<para>This target is active whenever any graphical session is running. It
888+
is used to stop user services which only apply to a graphical (X,
889+
Wayland, etc.) session when the session is terminated. Such services
890+
should have <literal>PartOf=graphical-session.target</literal> in their
891+
<literal>[Unit]</literal> section. A target for a particular session
892+
(e. g. <filename>gnome-session.target</filename>) starts and stops
893+
<literal>graphical-session.target</literal> with
894+
<literal>BindsTo=graphical-session.target</literal>.</para>
895+
896+
<para>Which services are started by a session target is determined by the
897+
<literal>Wants=</literal> and <literal>Requires=</literal> dependencies.
898+
For services that can be enabled independently, symlinks in
899+
<literal>.wants/</literal> and <literal>.requires/</literal> should be
900+
used, see
901+
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
902+
Those symlinks should either be shipped in packages, or should be added
903+
dynamically after installation, for example using <literal>systemctl add-wants</literal>, see
904+
<citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
905+
</para>
906+
907+
<example>
908+
<title>Nautilus as part of a GNOME session</title>
909+
910+
<para><literal>gnome-session.target</literal> pulls in Nautilus as
911+
top-level service:</para>
912+
913+
<programlisting>[Unit]
914+
Description=User systemd services for GNOME graphical session
915+
Wants=nautilus.service
916+
BindsTo=graphical-session.target
917+
</programlisting>
918+
919+
<para><literal>nautilus.service</literal> gets stopped when the session stops:</para>
920+
921+
<programlisting>[Unit]
922+
Description=Render the desktop icons with Nautilus
923+
PartOf=graphical-session.target
924+
925+
[Service]
926+
...
927+
</programlisting>
928+
</example>
929+
</refsect2>
930+
</refsect1>
931+
881932
<refsect1>
882933
<title>Special Slice Units</title>
883934

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This file is part of systemd.
2+
#
3+
# systemd is free software; you can redistribute it and/or modify it
4+
# under the terms of the GNU Lesser General Public License as published by
5+
# the Free Software Foundation; either version 2.1 of the License, or
6+
# (at your option) any later version.
7+
8+
[Unit]
9+
Description=Current graphical user session
10+
Documentation=man:systemd.special(7)
11+
Requires=basic.target
12+
RefuseManualStart=yes
13+
StopWhenUnneeded=yes

0 commit comments

Comments
 (0)