[gnome-session/wip/benzea/systemd-user-switch: 16/21] data: Add systemd user units



commit 68f31e094ade60edfa2f8460a5d8c95891a6bd06
Author: Benjamin Berg <bberg redhat com>
Date:   Sat Apr 20 01:49:21 2019 +0200

    data: Add systemd user units
    
    The main units are started in the following order:
     * graphical-session-pre.target (systemd special)
     * gnome-session-pre.target
     * gnome-session-initialized.target
         Signals gnome-session-binary using gnome-session-signal-init.service
     * gnome-session.target
     * graphical-session.target (systemd special)
    
    In addition, there are the following special units:
     * gnome-session-stable.timer and gnome-session-stable.target
         Can be used to modify failure behaviour when the session is
         considered stable
     * gnome-session-shutdown.target
         Should be started with replace-irreversibly when the session should
         be shut down; mostly useful internally by gnome-session with
         OnFailure/OnFailureJobMode
     * gnome-session-failed.target
         Should be start when an important session component failed. This
         can be used for OnFailure
    
    The following additional units can be used for depenencies/conflicts:
     * gnome-session@.target
         To depend/conflict a specific session type (e.g. gnome-login for GDM)
     * gnome-session-{wayland,x11}.target
         Started depending on the session type
     * gnome-session-manager.target
         Started when the session manager is running
         (This is only useful for the shell)
    
    The following additional targets exist:
     * gnome-session-{wayland,x11}@.target
         The initial target that is started, it has no further purpose
    
    Based on work by Iain Lane <iainl gnome org>.

 data/gnome-session-failed.service.in       | 19 ++++++++++++
 data/gnome-session-failed.target           | 12 ++++++++
 data/gnome-session-initialized.target      | 19 ++++++++++++
 data/gnome-session-manager.target          | 12 ++++++++
 data/gnome-session-manager  service in     | 19 ++++++++++++
 data/gnome-session-monitor.service.in      | 15 ++++++++++
 data/gnome-session-pre.target              | 14 +++++++++
 data/gnome-session-restart-dbus.service.in | 10 +++++++
 data/gnome-session-shutdown.service.in     |  9 ++++++
 data/gnome-session-shutdown.target         | 28 +++++++++++++++++
 data/gnome-session-signal-init.service.in  |  8 +++++
 data/gnome-session-stable.target           |  5 ++++
 data/gnome-session-stable.timer            | 11 +++++++
 data/gnome-session-wayland.target          | 17 +++++++++++
 data/gnome-session-wayland@.target         | 20 +++++++++++++
 data/gnome-session-x11.target              | 17 +++++++++++
 data/gnome-session-x11@.target             | 22 ++++++++++++++
 data/gnome-session.target                  | 18 +++++++++++
 data/gnome-session@.target                 | 16 ++++++++++
 data/gnome-wayland.desktop.in.in           |  7 +++++
 data/meson.build                           | 48 ++++++++++++++++++++++++++++++
 21 files changed, 346 insertions(+)
---
diff --git a/data/gnome-session-failed.service.in b/data/gnome-session-failed.service.in
new file mode 100644
index 00000000..4e22ab76
--- /dev/null
+++ b/data/gnome-session-failed.service.in
@@ -0,0 +1,19 @@
+[Unit]
+Description=GNOME Session Failed lockdown screen (user)
+OnFailure=gnome-session-shutdown.target
+OnFailureJobMode=replace-irreversibly
+CollectMode=inactive-or-failed
+
+PartOf=gnome-session-failed.target
+
+# We could do this, but it requires an intermediate target for OnFailure
+# handling, so gnome-session-failed checks RUNNING_UNDER_GDM itself
+#Conflicts=gnome-session@gnome-login.target
+# or in the case of GDM and then not passing --allow-logout
+#Requisite=gnome-session@gnome-login.target
+
+[Service]
+Type=simple
+ExecStart=@libexecdir@/gnome-session-failed --allow-logout
+# The fail whale doesn't trigger a shutdown itself, so do it here
+ExecStopPost=-@libexecdir@/gnome-session-ctl --shutdown
diff --git a/data/gnome-session-failed.target b/data/gnome-session-failed.target
new file mode 100644
index 00000000..3ad2eb19
--- /dev/null
+++ b/data/gnome-session-failed.target
@@ -0,0 +1,12 @@
+[Unit]
+Description=GNOME Session Failed
+OnFailure=gnome-session-shutdown.target
+OnFailureJobMode=replace-irreversibly
+
+# We need an initialized session
+Requisite=gnome-session-initialized.target
+BindsTo=gnome-session-initialized.target
+After=gnome-session-initialized.target
+
+BindsTo=gnome-session-failed.service
+After=gnome-session-failed.service
diff --git a/data/gnome-session-initialized.target b/data/gnome-session-initialized.target
new file mode 100644
index 00000000..3ef2ecfe
--- /dev/null
+++ b/data/gnome-session-initialized.target
@@ -0,0 +1,19 @@
+[Unit]
+Description=GNOME Session is initialized
+OnFailure=gnome-session-shutdown.target
+OnFailureJobMode=replace-irreversibly
+DefaultDependencies=no
+RefuseManualStart=yes
+RefuseManualStop=yes
+
+Requires=gnome-session-pre.target
+After=gnome-session-pre.target
+
+Requisite=gnome-session.target
+PartOf=gnome-session.target
+Before=gnome-session.target
+
+# Signal gnome-session that we reached the initialized target and
+# that it may start applications.
+Requires=gnome-session-signal-init.service
+Before=gnome-session-signal-init.service
diff --git a/data/gnome-session-manager.target b/data/gnome-session-manager.target
new file mode 100644
index 00000000..a9d20531
--- /dev/null
+++ b/data/gnome-session-manager.target
@@ -0,0 +1,12 @@
+[Unit]
+Description=GNOME Session Manager is ready
+DefaultDependencies=no
+RefuseManualStart=yes
+RefuseManualStop=yes
+
+Requisite=gnome-session-pre.target
+After=gnome-session-pre.target
+
+Requisite=gnome-session-initialized.target
+PartOf=gnome-session-initialized.target
+Before=gnome-session-initialized.target
diff --git a/data/gnome-session-manager  service in b/data/gnome-session-manager  service in
new file mode 100644
index 00000000..0f64a1a9
--- /dev/null
+++ b/data/gnome-session-manager  service in
@@ -0,0 +1,19 @@
+[Unit]
+Description=GNOME Session Manager (session: %i)
+RefuseManualStart=yes
+RefuseManualStop=yes
+OnFailure=gnome-session-shutdown.target
+OnFailureJobMode=replace-irreversibly
+CollectMode=inactive-or-failed
+
+Requisite=gnome-session-pre.target
+After=gnome-session-pre.target
+
+Requires=gnome-session-manager.target
+PartOf=gnome-session-manager.target
+Before=gnome-session-manager.target
+
+[Service]
+Type=notify
+ExecStart=@libexecdir@/gnome-session-binary --debug --systemd --session=%i
+ExecStopPost=-@libexecdir@/gnome-session-ctl --shutdown
diff --git a/data/gnome-session-monitor.service.in b/data/gnome-session-monitor.service.in
new file mode 100644
index 00000000..5e5edb73
--- /dev/null
+++ b/data/gnome-session-monitor.service.in
@@ -0,0 +1,15 @@
+[Unit]
+Description=Monitor Session leader for GNOME Session
+CollectMode=inactive-or-failed
+
+# All services started after gnome-session-pre.target need to be torn down
+# before the session finish can be signalled back to the display manager.
+PartOf=gnome-session-pre.target
+Before=gnome-session-pre.target
+
+# No After, as we want this to start up immediately
+
+[Service]
+Type=notify
+ExecStart=@libexecdir@/gnome-session-ctl --monitor
+TimeoutStopSec=5
diff --git a/data/gnome-session-pre.target b/data/gnome-session-pre.target
new file mode 100644
index 00000000..b6cad85c
--- /dev/null
+++ b/data/gnome-session-pre.target
@@ -0,0 +1,14 @@
+[Unit]
+Description=Tasks to be run before GNOME Session starts
+OnFailure=gnome-session-shutdown.target
+OnFailureJobMode=replace-irreversibly
+DefaultDependencies=no
+RefuseManualStart=yes
+RefuseManualStop=yes
+
+Requires=graphical-session-pre.target
+After=graphical-session-pre.target
+
+Requisite=gnome-session-initialized.target
+PartOf=gnome-session-initialized.target
+Before=gnome-session-initialized.target
diff --git a/data/gnome-session-restart-dbus.service.in b/data/gnome-session-restart-dbus.service.in
new file mode 100644
index 00000000..e90f6bc8
--- /dev/null
+++ b/data/gnome-session-restart-dbus.service.in
@@ -0,0 +1,10 @@
+[Unit]
+Description=Restart DBus after GNOME Session shutdown
+
+# Allow exit.target to start even if this unit is started with replace-irreversibly
+# Also put it into a slice that doesn't have such implicit dependencies
+DefaultDependencies=no
+
+[Service]
+Type=notify
+ExecStart=@libexecdir@/gnome-session-ctl --restart-dbus
diff --git a/data/gnome-session-shutdown.service.in b/data/gnome-session-shutdown.service.in
new file mode 100644
index 00000000..f00a5e30
--- /dev/null
+++ b/data/gnome-session-shutdown.service.in
@@ -0,0 +1,9 @@
+[Unit]
+Description=Trigger shutdown of a GNOME Session
+CollectMode=inactive-or-failed
+
+PartOf=gnome-session.target
+
+[Service]
+Type=oneshot
+ExecStart=@libexecdir@/gnome-session-ctl --shutdown
diff --git a/data/gnome-session-shutdown.target b/data/gnome-session-shutdown.target
new file mode 100644
index 00000000..84afb001
--- /dev/null
+++ b/data/gnome-session-shutdown.target
@@ -0,0 +1,28 @@
+[Unit]
+Description=Shutdown running GNOME Session
+
+# Allow exit.target to start even if this unit is started with replace-irreversibly
+# The same is needed for all (weak) dependencies
+DefaultDependencies=no
+
+Conflicts=graphical-session.target graphical-session-pre.target
+After=graphical-session.target graphical-session-pre.target
+
+# Add explicit conflicts/after lines for gnome-session targets, technically
+# this should not be needed, but is an extra safety measure.
+Conflicts=gnome-session.target gnome-session-manager.target
+After=gnome-session.target gnome-session-manager.target
+
+Conflicts=gnome-session-pre.target gnome-session-initialized.target gnome-session-failed.target
+After=gnome-session-pre.target gnome-session-initialized.target gnome-session-failed.target
+
+# Could we set StopWhenUnneeded=true or would that prevent the service to start?
+
+# We trigger a restart of DBus after reaching the shutdown target this
+# is a workaround so that DBus services that do not connect to the
+# display server are shut down after log-out.
+# This should be removed when the relevant services add a
+# PartOf=graphical-session.target
+# Historic bug: https://bugzilla.gnome.org/show_bug.cgi?id=764029
+Wants=gnome-session-restart-dbus.service
+Before=gnome-session-restart-dbus.service
diff --git a/data/gnome-session-signal-init.service.in b/data/gnome-session-signal-init.service.in
new file mode 100644
index 00000000..e3d2c463
--- /dev/null
+++ b/data/gnome-session-signal-init.service.in
@@ -0,0 +1,8 @@
+[Unit]
+Description=Signal initialization done to GNOME Session Manager
+
+PartOf=gnome-session.target
+
+[Service]
+Type=oneshot
+ExecStart=@libexecdir@/gnome-session-ctl --signal-init
diff --git a/data/gnome-session-stable.target b/data/gnome-session-stable.target
new file mode 100644
index 00000000..383cc3c6
--- /dev/null
+++ b/data/gnome-session-stable.target
@@ -0,0 +1,5 @@
+[Unit]
+Description=GNOME Session is stable (running for >2 minutes)
+
+Requisite=gnome-session.target
+PartOf=gnome-session.target
diff --git a/data/gnome-session-stable.timer b/data/gnome-session-stable.timer
new file mode 100644
index 00000000..efa806b1
--- /dev/null
+++ b/data/gnome-session-stable.timer
@@ -0,0 +1,11 @@
+[Unit]
+Description=GNOME Session is not yet stable (running for <2 minutes)
+
+Requisite=gnome-session.target
+PartOf=gnome-session.target
+
+[Timer]
+OnActiveSec=120
+AccuracySec=5
+Unit=gnome-session-stable.target
+RemainAfterElapse=no
diff --git a/data/gnome-session-wayland.target b/data/gnome-session-wayland.target
new file mode 100644
index 00000000..8ddc97d0
--- /dev/null
+++ b/data/gnome-session-wayland.target
@@ -0,0 +1,17 @@
+[Unit]
+Description=GNOME Wayland Session
+# On wayland all is lost, do a shutdown
+OnFailure=gnome-session-shutdown.target
+OnFailureJobMode=replace-irreversibly
+# Avoid default After/Before rules
+DefaultDependencies=no
+
+Before=gnome-session.target
+
+PartOf=graphical-session.target
+RefuseManualStart=yes
+RefuseManualStop=yes
+
+# Always pull in the correct gnome-shell target
+BindsTo=gnome-shell-wayland.target
+After=gnome-shell-wayland.target
diff --git a/data/gnome-session-wayland@.target b/data/gnome-session-wayland@.target
new file mode 100644
index 00000000..ba2a9185
--- /dev/null
+++ b/data/gnome-session-wayland@.target
@@ -0,0 +1,20 @@
+[Unit]
+Description=GNOME Wayland Session (session: %i)
+DefaultDependencies=no
+# Start happens explicitly
+RefuseManualStart=no
+# Stop happens by starting gnome-session-shutdown.target
+RefuseManualStop=yes
+
+Conflicts=shutdown.target gnome-session-shutdown.target
+PartOf=graphical-session.target
+
+# As this is the main entry point, pull in the other toplevel gnome-session targets
+Requires=gnome-session@.target
+After=gnome-session@.target
+
+Requires=gnome-session-wayland.target
+After=gnome-session-wayland.target
+
+Requires=gnome-session.target
+After=gnome-session.target
diff --git a/data/gnome-session-x11.target b/data/gnome-session-x11.target
new file mode 100644
index 00000000..4a78c527
--- /dev/null
+++ b/data/gnome-session-x11.target
@@ -0,0 +1,17 @@
+[Unit]
+Description=GNOME X11 Session
+# On X11, try to show the fail screen
+OnFailure=gnome-session-failed.target
+OnFailureJobMode=replace
+# Avoid default After/Before rules
+DefaultDependencies=no
+
+Before=gnome-session.target
+
+PartOf=graphical-session.target
+RefuseManualStart=yes
+RefuseManualStop=yes
+
+# Always pull in the correct gnome-shell target
+BindsTo=gnome-shell-x11.target
+After=gnome-shell-x11.target
diff --git a/data/gnome-session-x11@.target b/data/gnome-session-x11@.target
new file mode 100644
index 00000000..ce5879b2
--- /dev/null
+++ b/data/gnome-session-x11@.target
@@ -0,0 +1,22 @@
+[Unit]
+Description=GNOME X11 Session (session: %i)
+OnFailure=gnome-session-failed.target
+OnFailureJobMode=replace
+DefaultDependencies=no
+# Start happens explicitly
+RefuseManualStart=no
+# Stop happens by starting gnome-session-shutdown.target
+#RefuseManualStop=yes
+
+Conflicts=shutdown.target gnome-session-shutdown.target
+PartOf=graphical-session.target
+
+# As this is the main entry point, pull in the other toplevel gnome-session targets
+BindsTo=gnome-session@.target
+After=gnome-session@.target
+
+BindsTo=gnome-session-x11.target
+After=gnome-session-x11.target
+
+BindsTo=gnome-session.target
+After=gnome-session.target
diff --git a/data/gnome-session.target b/data/gnome-session.target
new file mode 100644
index 00000000..55cfc751
--- /dev/null
+++ b/data/gnome-session.target
@@ -0,0 +1,18 @@
+[Unit]
+Description=GNOME Session
+OnFailure=gnome-session-failed.target
+OnFailureJobMode=replace
+DefaultDependencies=no
+RefuseManualStart=yes
+RefuseManualStop=yes
+
+BindsTo=graphical-session.target
+Before=graphical-session.target
+
+# gnome-session-monitor.service will quit with the session leader process
+# gnome-session.target pulls in graphical-session.target
+BindsTo=gnome-session-monitor.service
+After=gnome-session-monitor.service
+
+# Pull in timer to mark session as stable (and unstable as long as the timer is active)
+Requires=gnome-session-stable.timer
diff --git a/data/gnome-session@.target b/data/gnome-session@.target
new file mode 100644
index 00000000..536d9c0f
--- /dev/null
+++ b/data/gnome-session@.target
@@ -0,0 +1,16 @@
+[Unit]
+Description=GNOME Session (session: %i)
+OnFailure=gnome-session-failed.target
+OnFailureJobMode=replace
+DefaultDependencies=no
+RefuseManualStart=yes
+RefuseManualStop=yes
+
+Requires=gnome-session-initialized.target
+After=gnome-session-initialized.target
+
+Requisite=gnome-session.target
+PartOf=gnome-session.target
+Before=gnome-session.target
+
+Requires=gnome-session-manager@.service
diff --git a/data/gnome-wayland.desktop.in.in b/data/gnome-wayland.desktop.in.in
new file mode 100644
index 00000000..516c211e
--- /dev/null
+++ b/data/gnome-wayland.desktop.in.in
@@ -0,0 +1,7 @@
+[Desktop Entry]
+Name=GNOME
+Comment=This session logs you into GNOME
+Exec=@bindir@/gnome-session
+TryExec=@bindir@/gnome-session
+Type=Application
+DesktopNames=GNOME
diff --git a/data/meson.build b/data/meson.build
index b976e739..38f865d8 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -88,6 +88,54 @@ install_data(
   install_dir: join_paths(session_datadir, 'GConf', 'gsettings')
 )
 
+if enable_systemd_session
+  unit_conf = configuration_data()
+  unit_conf.set('libexecdir', session_libexecdir)
+
+  # XXX: Once https://github.com/systemd/systemd/issues/9595 is fixed and we can
+  # depend on this version, replace with something like:
+  #  dep_systemd = dependency('systemd', required: true)
+  #  systemd_userunitdir = dep_systemd.get_pkgconfig_variable('systemduserunitdir')
+  # and uncomment systemd_dep below
+  systemd_userunitdir = join_paths(session_prefix, 'lib', 'systemd', 'user')
+
+  systemd_service = ['gnome-session-manager@.service',
+                     'gnome-session-signal-init.service',
+                     'gnome-session-restart-dbus.service',
+                     'gnome-session-monitor.service',
+                     'gnome-session-failed.service']
+
+  foreach service: systemd_service
+    configure_file(
+      input: service + '.in',
+      output: service,
+      install: true,
+      install_dir: systemd_userunitdir,
+      configuration: unit_conf
+    )
+  endforeach
+
+  systemd_target = files('gnome-session-wayland@.target',
+                         'gnome-session-wayland.target',
+                         'gnome-session-x11@.target',
+                         'gnome-session-x11.target',
+                         'gnome-session@.target',
+                         'gnome-session.target',
+                         'gnome-session-pre.target',
+                         'gnome-session-manager.target',
+                         'gnome-session-initialized.target',
+                         'gnome-session-shutdown.target',
+                         'gnome-session-failed.target',
+                         'gnome-session-stable.target',
+                         'gnome-session-stable.timer',
+                         )
+
+  install_data(
+    systemd_target,
+    install_dir: systemd_userunitdir
+  )
+endif
+
 data = files('hardware-compatibility')
 
 if enable_session_selector


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]