tizen: Add additional unit for "unified" user session 63/204563/2 accepted/tizen/unified/20190503.110441 submit/tizen/20190503.060010
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Tue, 23 Apr 2019 11:10:19 +0000 (13:10 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Tue, 30 Apr 2019 10:42:20 +0000 (12:42 +0200)
The unified user session is about moving user session units, managed by
systemd --user, to main systemd, where it's managed as part of newly
created user@.target.

user@.target will contain same units as previously available in user/,
with same UID and environment setup.  systemd instance is used for unit
to be able to specify UID (inherited from user@.target).

The rationale behind this work is following:

* VD requirement to remove user session support
* boot time optimization requirements, due to:

   + 'systemd --user' taking 1s its own startup that could be used for
     unit startup
   + ability to better rearrange units if these managed by one systemd
     instance

Unit installed by this commit will not be used till user login mechanism
will be changed in systemd package (via changing pam_systemd to start
user@.target, rather than user@.service).

Change-Id: I2e5785094c90dd5860edf8e4f0f077a24edd023f

packaging/calendar-service.spec
packaging/calendar-serviced.service
packaging/calendar-serviced.service.tv [deleted file]
packaging/calendar-serviced@.service [new file with mode: 0644]
packaging/tv.conf [new file with mode: 0644]
server/CMakeLists.txt

index f9b610002b1dfa97f44d8b2b667ba4b69af86623..773574b920c0ddee8587f0bb40b3004a228e912c 100644 (file)
@@ -7,7 +7,8 @@ License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
 Source1:    %{name}d.service
 Source2:    org.tizen.CalendarService.dbus.service
-Source5:    %{name}d.service.tv
+Source5:    tv.conf
+Source6:    %{name}d@.service
 Source1001: %{name}.manifest
 Source1002: %{name}.conf.in
 Source2001: ALARM.a%{name}.service
@@ -34,7 +35,10 @@ BuildRequires: pkgconfig(contacts-service2)
 %endif
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
+Requires(post): %{_sbindir}/update-alternatives
+Requires(preun): %{_sbindir}/update-alternatives
 Provides: %{name}-compat = %{version}-%{release}
+Requires: %{name}-units
 
 %description
 Calendar Service for using Calendar DB
@@ -43,10 +47,10 @@ Calendar Service for using Calendar DB
 Summary:       for TV
 Provides:      %{name}-compat = %{version}-%{release}
 Conflicts:     %{name}
+Requires:       %{name}-units
 %description profile_tv
 for TV
 
-
 %package -n lib%{name}
 Summary:       client library
 %if "%{?profile}" != "tv"
@@ -58,9 +62,11 @@ Requires:    %{name}-profile_tv = %{version}-%{release}
 %description -n lib%{name}
 client library for calendar
 
+%package units
+Summary:        systemd and dbus-daemon units for %{name}
 
-
-%define _dbus_interface org.tizen.CalendarService.dbus
+%description units
+.
 
 %package devel
 Summary:    DB library for calendar
@@ -86,6 +92,8 @@ cp %SOURCE1001 .
 %endif
 
 %build
+%define _dbus_interface org.tizen.CalendarService.dbus
+
 CXXFLAGS="$CXXFLAGS -DU_USING_ICU_NAMESPACE=1"
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 %cmake . -DMAJORVER=${MAJORVER} -DFULLVER=%{version} -DBIN_INSTALL_DIR:PATH=%{_bindir} \
@@ -97,9 +105,15 @@ make %{?jobs:-j%jobs}
 rm -rf %{buildroot}
 %make_install
 
-mkdir -p %{buildroot}%{_unitdir_user}/default.target.wants
+mkdir -p %{buildroot}%{_unitdir_user}/%{name}d.service.d
 install -m 0644 %SOURCE1 %{buildroot}%{_unitdir_user}
-install -m 0644 %SOURCE5 %{buildroot}%{_unitdir_user}
+install -m 0644 %SOURCE5 %{buildroot}%{_unitdir_user}/%{name}d.service.d/
+
+mkdir -p %{buildroot}%{_unitdir}/user-default@.target.wants
+mkdir -p %{buildroot}%{_unitdir}/%{name}d@.service.d/
+install -m 0644 %SOURCE6 %{buildroot}%{_unitdir}
+install -m 0644 %SOURCE5 %{buildroot}%{_unitdir}/%{name}d@.service.d/
+ln -s ../calendar-serviced@.service %{buildroot}%{_unitdir}/user-default@.target.wants/calendar-serviced@.service
 
 mkdir -p %{buildroot}%{_datadir}/dbus-1/services
 install -m 0644 %SOURCE2 %{buildroot}%{_datadir}/dbus-1/services
@@ -112,41 +126,44 @@ install -m 0644 %SOURCE1002 %{buildroot}%{_sysconfdir}/dbus-1/session.d/%{name}.
 mkdir -p %{buildroot}%{_datadir}/dbus-1/services
 install -m 0644 %SOURCE2001 %{buildroot}%{_datadir}/dbus-1/services
 
-
 %post -n lib%{name} -p /sbin/ldconfig
 %postun -n lib%{name} -p /sbin/ldconfig
 
-%post profile_tv
-mv %{_unitdir_user}/calendar-serviced.service.tv %{_unitdir_user}/calendar-serviced.service
+%post
+%{_sbindir}/update-alternatives --install %{_bindir}/calendar-serviced %{name} %{_bindir}/calendar-serviced-common 100
+%pre
+%{_sbindir}/update-alternatives --remove %{name} %{_bindir}/calendar-serviced-common
 
-%preun profile_tv
-mv %{_unitdir_user}/calendar-serviced.service %{_unitdir_user}/calendar-serviced.service.tv
+%post profile_tv
+%{_sbindir}/update-alternatives --install %{_bindir}/calendar-serviced %{name} %{_bindir}/calendar-serviced-tv 200
+%pre profile_tv
+%{_sbindir}/update-alternatives --remove %{name} %{_bindir}/calendar-serviced-tv
 
+%files units
+%config %{_sysconfdir}/dbus-1/session.d/%{name}.conf
+%{_datadir}/dbus-1/services/%{_dbus_interface}.service
+%{_datadir}/dbus-1/services/ALARM.acalendar-service.service
+%{_unitdir_user}/%{name}d.service
+%{_unitdir}/%{name}d@.service
+%{_unitdir}/user-default@.target.wants/calendar-serviced@.service
 
 %files
-%{_unitdir_user}/%{name}d.service
+%manifest %{name}.manifest
+%defattr(-,root,root,-)
 # This is for backward-compatibility. This does not deteriorate 4.0 Configurability
 # TV profile does not have contacts-service2.
 # if wearable, ivi, common, mobile ||"undefined"
 %if "%{?profile}" != "tv"
-%manifest %{name}.manifest
-%defattr(-,root,root,-)
-%{_bindir}/calendar-serviced
-%{_datadir}/dbus-1/services/%{_dbus_interface}.service
-%config %{_sysconfdir}/dbus-1/session.d/%{name}.conf
-%{_datadir}/dbus-1/services/ALARM.acalendar-service.service
+%{_bindir}/calendar-serviced-common
 %license LICENSE.APLv2
 %endif
 
-
 %files profile_tv
 %manifest %{name}.manifest
 %defattr(-,root,root,-)
 %{_bindir}/calendar-serviced-tv
-%{_unitdir_user}/%{name}d.service.tv
-%{_datadir}/dbus-1/services/%{_dbus_interface}.service
-%config %{_sysconfdir}/dbus-1/session.d/%{name}.conf
-%{_datadir}/dbus-1/services/ALARM.acalendar-service.service
+%{_unitdir_user}/%{name}d.service.d/tv.conf
+%{_unitdir}/%{name}d@.service.d/tv.conf
 %license LICENSE.APLv2
 
 %files -n lib%{name}
index caffb63b2e319e95b97de08b233382a5f4885a8c..53ac6f75ab2d37afcabf2ace8f2697f5edb90526 100644 (file)
@@ -6,5 +6,5 @@ Requires=contacts-service.service
 [Service]
 Type=dbus
 BusName=org.tizen.CalendarService.dbus
-Environment="TIMEOUT=90"
+Environment=TIMEOUT=90
 ExecStart=/usr/bin/calendar-serviced $TIMEOUT
diff --git a/packaging/calendar-serviced.service.tv b/packaging/calendar-serviced.service.tv
deleted file mode 100644 (file)
index 57dfb0d..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-[Unit]
-Description=Calendar Service daemon
-
-[Service]
-Type=dbus
-BusName=org.tizen.CalendarService.dbus
-Environment="TIMEOUT=90"
-ExecStart=/usr/bin/calendar-serviced-tv $TIMEOUT
diff --git a/packaging/calendar-serviced@.service b/packaging/calendar-serviced@.service
new file mode 100644 (file)
index 0000000..658160b
--- /dev/null
@@ -0,0 +1,15 @@
+[Unit]
+PartOf=userlogin@%i.target
+Description=Calendar Service daemon
+After=contacts-service@%i.service
+Requires=contacts-service@%i.service
+
+[Service]
+User=%i
+Environment=DBUS_SESSION_BUS_ADDRESS=kernel:path=/sys/fs/kdbus/%i-user/bus;unix:path=/run/user/%i/bus
+Environment=XDG_RUNTIME_DIR=/run/user/%i
+SmackProcessLabel=User
+Type=dbus
+BusName=org.tizen.CalendarService.dbus
+Environment=TIMEOUT=90
+ExecStart=/usr/bin/calendar-serviced $TIMEOUT
diff --git a/packaging/tv.conf b/packaging/tv.conf
new file mode 100644 (file)
index 0000000..e1477bf
--- /dev/null
@@ -0,0 +1,3 @@
+[Unit]
+After=
+Requires=
index abd8e7af72713db62b38667ce1e520d5e8c74c2d..106725ebd6f5d3852240d454f9556c06e7a8e1f2 100644 (file)
@@ -40,10 +40,10 @@ SET(CONTACTS_CFLAGS "${CONTACTS_CFLAGS} -I${INCLUDE_DIR}")
 ENDFOREACH(INCLUDE_DIR)
 
 IF(${TIZEN_PROFILE_TV} EQUAL 0)
-ADD_EXECUTABLE(${DAEMON} ${DAEMON_SRCS})
-ADD_DEPENDENCIES(${DAEMON} GENERATED_DBUS_CODE)
-SET_TARGET_PROPERTIES(${DAEMON} PROPERTIES COMPILE_FLAGS ${CONTACTS_CFLAGS})
-TARGET_LINK_LIBRARIES(${DAEMON} ${daemon_pkgs_LIBRARIES} ${daemon_contacts_pkgs_LIBRARIES})
+ADD_EXECUTABLE(${DAEMON}-common ${DAEMON_SRCS})
+ADD_DEPENDENCIES(${DAEMON}-common GENERATED_DBUS_CODE)
+SET_TARGET_PROPERTIES(${DAEMON}-common PROPERTIES COMPILE_FLAGS ${CONTACTS_CFLAGS})
+TARGET_LINK_LIBRARIES(${DAEMON}-common ${daemon_pkgs_LIBRARIES} ${daemon_contacts_pkgs_LIBRARIES})
 ENDIF()
 
 
@@ -53,6 +53,6 @@ SET_TARGET_PROPERTIES(${DAEMON}-tv PROPERTIES COMPILE_FLAGS "-I${CMAKE_CURRENT_S
 TARGET_LINK_LIBRARIES(${DAEMON}-tv ${daemon_pkgs_LIBRARIES})
 
 IF(${TIZEN_PROFILE_TV} EQUAL 0)
-INSTALL(TARGETS ${DAEMON} DESTINATION ${BIN_INSTALL_DIR})
+INSTALL(TARGETS ${DAEMON}-common DESTINATION ${BIN_INSTALL_DIR})
 ENDIF()
 INSTALL(TARGETS ${DAEMON}-tv DESTINATION ${BIN_INSTALL_DIR})