[gnome-online-accounts/wip/dbus-services-as-systemd-services] data: Set up D-Bus session services as systemd user services




commit dd79fe6583c85ef28fa7a593b1e8ca192b97bbdb
Author: Simon McVittie <smcv collabora com>
Date:   Thu Dec 3 12:13:58 2020 +0000

    data: Set up D-Bus session services as systemd user services
    
    This allows them to be managed by `systemd --user` on systems that use
    it, meaning they can be manipulated by `systemctl --user`, placed into a
    slice for resource management purposes, configured with drop-in
    configuration in {/etc,/usr/lib}/systemd/user/goa-daemon.service.d/*.conf
    and so on.
    
    On systems that do not launch dbus-daemon as a `systemd --user` service,
    including systems that do not use systemd at all, the SystemdService
    field is ignored and the dbus-daemon will continue to use the
    traditional activation mechanism. In this case the GOA services will
    continue to be child processes of the dbus-daemon.
    
    Signed-off-by: Simon McVittie <smcv collabora com>

 data/Makefile.am                         |  9 +++++++++
 data/goa-daemon.service.in               |  7 +++++++
 data/goa-identity-service.service.in     |  7 +++++++
 data/meson.build                         | 12 ++++++++++++
 data/org.gnome.Identity.service.in       |  1 +
 data/org.gnome.OnlineAccounts.service.in |  1 +
 meson.build                              | 14 ++++++++++++++
 meson_options.txt                        |  1 +
 8 files changed, 52 insertions(+)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index e3608a12..76741349 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -11,12 +11,17 @@ gsettings_SCHEMAS = $(gsettings_schema_files)
 
 servicedir       = $(datadir)/dbus-1/services
 service_in_files = org.gnome.OnlineAccounts.service.in
+systemduserunitdir = $(prefix)/lib/systemd/user
+systemd_service_in_files = goa-daemon.service.in
 
 if BUILD_KERBEROS
 service_in_files += org.gnome.Identity.service.in
+systemd_service_in_files += goa-identity-service.service.in
 endif
 
 service_DATA     = $(service_in_files:.service.in=.service)
+systemduserunit_DATA = $(systemd_service_in_files:.service.in=.service)
+
 %.service: %.service.in Makefile
        @sed -e "s|\@libexecdir\@|$(libexecdir)|" $< > $@
 endif
@@ -24,11 +29,15 @@ endif
 EXTRA_DIST =                                           \
        $(gsettings_schema_files)                       \
        dbus-interfaces.xml                             \
+       goa-daemon.service.in                           \
+       goa-identity-service.service.in                 \
        org.gnome.Identity.service.in                   \
        org.gnome.OnlineAccounts.service.in             \
        $(NULL)
 
 CLEANFILES =                                           \
+       goa-daemon.service                              \
+       goa-identity-service.service                    \
        org.gnome.OnlineAccounts.service                \
        org.gnome.Identity.service                      \
        $(NULL)
diff --git a/data/goa-daemon.service.in b/data/goa-daemon.service.in
new file mode 100644
index 00000000..c612656f
--- /dev/null
+++ b/data/goa-daemon.service.in
@@ -0,0 +1,7 @@
+[Unit]
+Description=GNOME Online Accounts service
+
+[Service]
+ExecStart=@libexecdir@/goa-daemon
+Type=dbus
+BusName=org.gnome.OnlineAccounts
diff --git a/data/goa-identity-service.service.in b/data/goa-identity-service.service.in
new file mode 100644
index 00000000..7bf8cf6c
--- /dev/null
+++ b/data/goa-identity-service.service.in
@@ -0,0 +1,7 @@
+[Unit]
+Description=GNOME identity service for Kerberos
+
+[Service]
+ExecStart=@libexecdir@/goa-identity-service
+Type=dbus
+BusName=org.gnome.Identity
diff --git a/data/meson.build b/data/meson.build
index a62f8e8d..42cb8ffa 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -9,8 +9,10 @@ if enable_goabackend
   )
 
   services = ['org.gnome.OnlineAccounts.service']
+  systemd_services = ['goa-daemon.service']
   if enable_kerberos
     services += 'org.gnome.Identity.service'
+    systemd_services += ['goa-identity-service.service']
   endif
 
   service_conf = configuration_data()
@@ -25,4 +27,14 @@ if enable_goabackend
       install_dir: dbus_service_dir
     )
   endforeach
+
+  foreach service: systemd_services
+    configure_file(
+      input: service + '.in',
+      output: service,
+      configuration: service_conf,
+      install: true,
+      install_dir: systemd_userunitdir
+    )
+  endforeach
 endif
diff --git a/data/org.gnome.Identity.service.in b/data/org.gnome.Identity.service.in
index bd3b0322..f70948e8 100644
--- a/data/org.gnome.Identity.service.in
+++ b/data/org.gnome.Identity.service.in
@@ -1,3 +1,4 @@
 [D-BUS Service]
 Name=org.gnome.Identity
 Exec=@libexecdir@/goa-identity-service
+SystemdService=goa-identity-service.service
diff --git a/data/org.gnome.OnlineAccounts.service.in b/data/org.gnome.OnlineAccounts.service.in
index ff2b976a..9d8df111 100644
--- a/data/org.gnome.OnlineAccounts.service.in
+++ b/data/org.gnome.OnlineAccounts.service.in
@@ -1,3 +1,4 @@
 [D-BUS Service]
 Name=org.gnome.OnlineAccounts
 Exec=@libexecdir@/goa-daemon
+SystemdService=goa-daemon.service
diff --git a/meson.build b/meson.build
index c3d54c8f..f3cffc72 100644
--- a/meson.build
+++ b/meson.build
@@ -86,6 +86,20 @@ dbus_dep = dependency('dbus-1')
 dbus_service_dir = dbus_dep.get_pkgconfig_variable('session_bus_services_dir',
                                                    define_variable: ['datadir', goa_datadir])
 
+systemd_userunitdir = get_option('systemduserunitdir')
+
+if systemd_userunitdir == ''
+  systemd_dep = dependency('systemd', required: false)
+
+  if systemd_dep.found()
+    systemd_userunitdir = systemd_dep.get_pkgconfig_variable('systemduserunitdir')
+  else
+    # Fall back to the upstream default.
+    # Note that this is always 'lib', even if libdir is something else
+    systemd_userunitdir = join_paths(goa_prefix, 'lib', 'systemd', 'user')
+  endif
+endif
+
 # Libraries
 # introspection support
 enable_introspection = get_option('introspection')
diff --git a/meson_options.txt b/meson_options.txt
index 08c65ecd..6cd6219b 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -39,3 +39,4 @@ option('introspection', type: 'boolean', value: true, description: 'Enable GObje
 option('man', type: 'boolean', value: false, description: 'enable man pages')
 option('template_file', type: 'string', value: '', description: 'Path to the template file')
 option('vapi', type: 'boolean', value: true, description: 'build Vala binding')
+option('systemduserunitdir', type: 'string', value: '', description: 'Override systemd user unit directory')


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