[gnome-settings-daemon/benzea/systemd-3-36: 23/24] plugins: Update systemd unit design and generate them



commit 7997b6adeb4847cae5d31d865a3fe405f15a24cf
Author: Benjamin Berg <bberg redhat com>
Date:   Fri Dec 13 16:24:19 2019 +0100

    plugins: Update systemd unit design and generate them
    
    Rather than having per-plugin units, generate them from the meson build
    file using a common template.
    
    The unit layout is changed somewhat. The .target file now is solely a
    flag on whether the service is requested for the session type. The
    variosu requirements are all moved into the .service file.
    
    Instead of using an OnFailure and trying to contain the dependency
    errors in a separate unit, we now use ExecStopPost. It seems that the
    current approach has never worked anyway.
    
    The Conflict entries on certain session types are gone now. This is
    instead handled outside of gnome-settings-daemon.

 plugins/gsd.service.in | 25 ++++++++++++++++++++++
 plugins/gsd.target.in  | 12 +++++++++++
 plugins/meson.build    | 57 ++++++++++++++++++++++++++++++++++++++++----------
 3 files changed, 83 insertions(+), 11 deletions(-)
---
diff --git a/plugins/gsd.service.in b/plugins/gsd.service.in
new file mode 100644
index 00000000..1142ae17
--- /dev/null
+++ b/plugins/gsd.service.in
@@ -0,0 +1,25 @@
+[Unit]
+Description=@description@ service
+CollectMode=inactive-or-failed
+RefuseManualStart=true
+RefuseManualStop=true
+
+After=gnome-session-initialized.target
+
+# Requisite/PartOf means the dependency is not loaded automatically.
+# The ordering here also implies Before=gnome-session.target
+Requisite=gsd-@plugin_name@.target
+PartOf=gsd-@plugin_name@.target
+Before=gsd-@plugin_name@.target
+
+@plugin_gate_units_section@
+
+[Service]
+Type=dbus
+ExecStart=@libexecdir@/gsd-power
+Restart=@plugin_restart@
+BusName=@plugin_dbus_name@
+TimeoutStopSec=5
+# We cannot use OnFailure as e.g. dependency failures are normal
+# https://github.com/systemd/systemd/issues/12352
+ExecStopPost=@libexecdir@/gnome-session-ctl --exec-stop-check
diff --git a/plugins/gsd.target.in b/plugins/gsd.target.in
new file mode 100644
index 00000000..407207a4
--- /dev/null
+++ b/plugins/gsd.target.in
@@ -0,0 +1,12 @@
+[Unit]
+Description=@description@ target
+CollectMode=inactive-or-failed
+
+# Pull in the service
+Wants=gsd-@plugin_name@.service
+
+# Require GNOME session and specify startup ordering
+Requisite=gnome-session-initialized.target
+After=gnome-session-initialized.target
+PartOf=gnome-session-initialized.target
+Before=gnome-session.target
diff --git a/plugins/meson.build b/plugins/meson.build
index 885d3ffa..d8245980 100644
--- a/plugins/meson.build
+++ b/plugins/meson.build
@@ -40,11 +40,16 @@ if not enable_wwan
     disabled_plugins += ['wwan']
 endif
 
+# Specify futher required units, 'before' or 'after' may be specified if ordering is needed
 plugin_gate_units = {
-    'xsettings': ['gnome-session-x11-services.target'],
-#    'dummy': ['required-started.target.wants/'],
-#    'wacom': ['wacom.target.wants/'],
-#    'smartcard': ['smartcard.target.wants/'],
+    'xsettings': [['gnome-session-x11-services.target', 'before']],
+#    'wacom': [['wacom.target']],
+#    'smartcard': [['smartcard.target']],
+}
+
+# Restart=on-failure is the default
+plugin_restart_rule = {
+    'xsettings' : 'on-abnormal',
 }
 
 plugins_conf = configuration_data()
@@ -101,30 +106,60 @@ foreach plugin: all_plugins
         user_service = 'gsd-@0@.service'.format(plugin_name)
 
         unit_conf = configuration_data()
+        unit_conf.set('plugin_name', plugin_name)
+        unit_conf.set('description', plugin_description)
         unit_conf.set('libexecdir', gsd_libexecdir)
         unit_conf.set('plugin_dbus_name', plugin_dbus_name)
+        unit_conf.set('plugin_restart', plugin_restart_rule.get(plugin_name, 'on-failure'))
+
+        gates_all = []
+        gates_after = []
+        gates_before = []
+        foreach gate: plugin_gate_units.get(plugin_name, [])
+            gates_all += [gate[0]]
+            if gate.length() > 1
+                if gate[1] == 'before'
+                    gates_before += [gate[0]]
+                elif gate[1] == 'after'
+                    gates_after += [gate[0]]
+                else
+                    error('Ordering key must be either "before" or "after"')
+                endif
+            endif
+        endforeach
+        gate_unit_section = []
+        if gates_all.length() > 0
+            gate_unit_section += ['Requisite=' + ' '.join(gates_all)]
+            gate_unit_section += ['PartOf=' + ' '.join(gates_all)]
+
+            if gates_after.length() > 0
+                gate_unit_section += ['After=' + ' '.join(gates_after)]
+            endif
+            if gates_before.length() > 0
+                gate_unit_section += ['Before=' + ' '.join(gates_before)]
+            endif
+        endif
+        unit_conf.set('plugin_gate_units_section', '\n'.join(gate_unit_section))
 
         if enable_systemd
             configure_file(
-                input: join_paths(plugin_name, user_service + '.in'),
+                input: 'gsd.service.in',
                 output: user_service,
                 configuration: unit_conf,
                 install: true,
                 install_dir: systemd_userunitdir
             )
             configure_file(
-                input: join_paths(plugin_name, user_target + '.in'),
+                input: 'gsd.target.in',
                 output: user_target,
                 configuration: unit_conf,
                 install: true,
                 install_dir: systemd_userunitdir
             )
 
-            if plugin_name in plugin_gate_units
-                foreach target: plugin_gate_units[plugin_name]
-                    meson.add_install_script('meson-add-wants.sh', systemd_userunitdir, target, user_target)
-                endforeach
-            endif
+            foreach target: gates_all
+                meson.add_install_script('meson-add-wants.sh', systemd_userunitdir, target + '.wants/', 
user_target)
+            endforeach
         endif
 
         subdir(plugin_name)


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