Merge lp:~3v1n0/unity/systemd-unit-fixes into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 4193
Proposed branch: lp:~3v1n0/unity/systemd-unit-fixes
Merge into: lp:unity
Diff against target: 967 lines (+538/-66)
31 files modified
data/CMakeLists.txt (+7/-1)
data/unity7.conf.in (+2/-19)
data/unity7.override (+1/-0)
data/unity7.service.in (+15/-0)
debian/control (+23/-21)
debian/libunity-core-6.0-9.install (+3/-2)
debian/unity-services.install (+4/-1)
debian/unity-services.links (+13/-0)
debian/unity.install (+4/-0)
debian/unity.links (+1/-0)
lockscreen/LockScreenController.cpp (+5/-0)
lockscreen/LockScreenController.h (+3/-0)
services/CMakeLists.txt (+31/-0)
services/unity-panel-service-lockscreen.conf.in (+3/-1)
services/unity-panel-service-lockscreen.override (+1/-0)
services/unity-panel-service-lockscreen.service.in (+2/-1)
services/unity-panel-service.conf.in (+3/-1)
services/unity-panel-service.override (+1/-0)
services/unity-panel-service.service.in (+10/-0)
services/unity-screen-locked.target (+5/-0)
tests/CMakeLists.txt (+1/-0)
tests/test_lockscreen_controller.cpp (+5/-2)
tests/test_systemd_wrapper.cpp (+110/-0)
tools/CMakeLists.txt (+6/-0)
tools/compiz-profile-selector.in (+19/-0)
tools/systemd-prestart-check (+29/-0)
tools/unity.cmake (+63/-17)
tools/upstart-prestart-check (+17/-0)
unity-shared/CMakeLists.txt (+1/-0)
unity-shared/SystemdWrapper.cpp (+96/-0)
unity-shared/SystemdWrapper.h (+54/-0)
To merge this branch: bzr merge lp:~3v1n0/unity/systemd-unit-fixes
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
Ted Gould (community) Approve
Iain Lane systemd-units Approve
Marco Trevisan (Treviño) Pending
Review via email: mp+304784@code.launchpad.net

This proposal supersedes a proposal from 2016-07-20.

Commit message

Unity: add systemd units for the shell and related services, mark unity7 a requirement for ubuntu-session

At it's core this MR is about making unity7 work with the systemd user sessions.
It required a larger change than expected, so some descriptions :-)

It moves the prestart scripts from Upstart into a shared shell script so that both
systemd and Upstart can use the same code.

Added a signal wrapper for Systemd, today we are sending both signals as both
will be running for the time being. In the future the Upstart signals should be
droppable.

For lock screen we created a target for when the lock screen is enabled.
We put the panel job in there, but other jobs can add themselves by
putting a symbolic link into the "unity-screen-locked.target.wants"
directory to their jobs if they want.

Description of the change

This is mainly based on lp:~ted/unity/systemd-unit. with some fixes applied on top

To post a comment you must log in.
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote : Posted in a previous version of this proposal

There have been changes recently to upstart job to change COMPIZ_CONFIG_PROFILE depending on the gfx environment. So please sync with upstream changes on that.

Also, please rebase on lp:~azzar1/unity/unity-active-plugins--safety-check, which will need to be ported too

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote : Posted in a previous version of this proposal

I don't see unity-compiz-profile in any .install file.

Please move that into unity.install together with systemd (and unity7.conf file). I don't remember why they were added there in the past (likely for some gsettings and unity8 dependency on libunity-core), but I think that is not the nicest places to be.

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote : Posted in a previous version of this proposal

Can you please merge this again with lp:~azzar1/unity/unity-active-plugins--safety-check?

It should be the last time :-)

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote : Posted in a previous version of this proposal

As per channel discussion:

15:15:38 <Trevinho> tedg: also, I was thinking... using that code in the current yakkety causes the Start/Stop calls to not happen since the proxy is not connected... They get queued though... Maybe you could avoid to call start/stop if the systemd_proxy_ is not connected?
15:16:37 <Trevinho> tedg: at the beginning I had the idea of just provinding one of the two wrappers, depending on what is running in the session, but... It's a little to annoying, and I didn't want you to create an abstract class just for that, but... Maybe...
15:16:55 <tedg> Trevinho: Oh, because it's connecting to the session bus instead of the user bus right now?
15:17:04 <Trevinho> tedg: yes
15:17:14 <tedg> Trevinho: We won't have the Upstart stuff for long hopefully, so I don't think it's worth abstracting.
15:18:18 <Trevinho> tedg: yeah, same I thought...
15:18:36 <Trevinho> tedg: but currently guess we'd get some "Timed out waiting for proxy" erros in unity logs
15:18:37 <Trevinho> so...
15:19:11 <Trevinho> tedg: is an env var available when systemd is there?
15:19:55 <tedg> tedg: I think checking if it's connected is fine. We can drop that too once we get migrated over if it's taking too long.
15:20:03 <Trevinho> ok...
15:20:30 <Trevinho> tedg: I mean, it might be not connected at the very start of the session... Like if starting with unity already locked (because of a crash) though
15:20:48 <Trevinho> but... Yeah, as you say, this is something we can get rid of
15:21:08 <Trevinho> or, juts check for an env var presency for both upstart and systemd wrappers
15:23:01 <Trevinho> tedg: also /usr/share/unity/unity-compiz-profile I'd prefer it to be in /usr/lib/unity
15:24:04 <Trevinho> tedg: and probably renamed unity-compiz-profile-set or -selector or... anything that explains better :-)
15:25:05 <tedg> K, I was avoiding changing the codebase too much, but since andyrock moved the .conf file into the build system we can move it to lib.
15:33:32 <Trevinho> tedg: yeah, that's nicer

Revision history for this message
Ted Gould (ted) wrote : Posted in a previous version of this proposal

K, I think that's everything :-)

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote : Posted in a previous version of this proposal

Still some conflicts with the parent branch, merge again please...

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote : Posted in a previous version of this proposal

Also, you want me to land this or you prefer to land the branch together with the other systemd branches?

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote : Posted in a previous version of this proposal

Looks good, just still wondering if you can get rid of that static list from the .service :)

Revision history for this message
Ted Gould (ted) wrote : Posted in a previous version of this proposal

So I removed the list and put it as a set of symbolic links in the packaging. At least then it is a packaging thing (when suggests change the links should change) more than an Upstream thing.

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote : Posted in a previous version of this proposal

Mh, this is better... I would have guessed this was done at each indicator level, but I can go with this too.

One only minor thing, it shouldn't never happen that the lockscreen is there without ups running, but... For safety I think it would be better to also add

/usr/lib/systemd/user/indicator-datetime.service /usr/lib/systemd/user/unity-panel-service-lockscreen.service.wants/indicator-datetime.service
/usr/lib/systemd/user/indicator-keyboard.service /usr/lib/systemd/user/unity-panel-service-lockscreen.service.wants/indicator-keyboard.service
/usr/lib/systemd/user/indicator-power.service /usr/lib/systemd/user/unity-panel-service-lockscreen.service.wants/indicator-power.service
/usr/lib/systemd/user/indicator-session.service /usr/lib/systemd/user/unity-panel-service-lockscreen.service.wants/indicator-session.service
/usr/lib/systemd/user/indicator-sound.service /usr/lib/systemd/user/unity-panel-service-lockscreen.service.wants/indicator-sound.service

Revision history for this message
Ted Gould (ted) wrote : Posted in a previous version of this proposal

On Tue, 2016-08-09 at 16:09 +0000, Marco Trevisan (Treviño) wrote:
> Mh, this is better... I would have guessed this was done at each
> indicator level, but I can go with this too.
Yes, systemd is "backwards" to Upstart in that you define a state and
how to achieve that state instead of an event that you listen for. So
the state is panel-service running and you achieve that by starting the
indicators instead of the panel service asking the indicators to start.
I miss Upstart, I think it made more sense too :-(
> One only minor thing, it shouldn't never happen that the lockscreen is there without ups running, but... For safety I think it would be better to also add
>

Yup, good idea, added.

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote : Posted in a previous version of this proposal

Nice, I think we can land this now!

review: Approve
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote : Posted in a previous version of this proposal

Ouch, I'm getting this now:

dpkg: error processing archive /tmp/apt-dpkg-install-pcRES4/3-unity_7.5.0+16.10.20160823-0ubuntu1_amd64.deb (--unpack):
 trying to overwrite '/usr/lib/x86_64-linux-gnu/unity/makebootchart.py', which is also in package libunity-core-6.0-9:amd64 7.5.0+16.10.20160817.1-0ubuntu1

I guess this is because the unity.install +usr/lib/*/unity line, can you set it as it used to be please?

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) : Posted in a previous version of this proposal
review: Needs Fixing
Revision history for this message
Ted Gould (ted) wrote : Posted in a previous version of this proposal

Set them up to explicitly mention, looks like they end up in the right package now.

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote : Posted in a previous version of this proposal

I didn't generated scripts have wrong path, you should use FULL_LIBDIR.

[/usr/lib/systemd/user/unity7.service:10] Executable path is not absolute, ignoring: lib/x86_64-linux-gnu/unity/unity-compiz-profile-select

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote : Posted in a previous version of this proposal

The prefixes on the .service and .config files are still wrong... See the inline comments.

Also unity7 doesn't start automatically (it does if I use systemctl manually), and I also see this:

 indicator-application.service not-found inactive dead indicator-application.service
● indicator-bluetooth.service not-found inactive dead indicator-bluetooth.service
● indicator-datetime.service not-found inactive dead indicator-datetime.service
● indicator-keyboard.service not-found inactive dead indicator-keyboard.service
● indicator-messages.service not-found inactive dead indicator-messages.service
● indicator-power.service not-found inactive dead indicator-power.service
● indicator-session.service not-found inactive dead indicator-session.service
● indicator-sound.service not-found inactive dead indicator-sound.service
  unity-gtk-module.service loaded active exited Unity GTK Module Environment variables
  unity-panel-service.service loaded inactive dead Backing Service for the Unity Panel
  unity-settings-daemon.service loaded active running Unity Settings Daemon
  unity7.service loaded inactive dead Unity Shell v7
  indicators-pre.target loaded inactive dead

Revision history for this message
Iain Lane (laney) wrote : Posted in a previous version of this proposal

Missing:

  - symlink /usr/lib/systemd/user/ubuntu-session.target.requires/unity7.service -> ../unity7.service
  - Environment=COMPIZ_CONFIG_PROFILE=ubuntu

review: Needs Fixing
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote : Posted in a previous version of this proposal

> - Environment=COMPIZ_CONFIG_PROFILE=ubuntu

This isn't true anymore, since the profile could also be ubnutu-lowgfx, so this has to be done from the pre-start script

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote : Posted in a previous version of this proposal

> - Environment=COMPIZ_CONFIG_PROFILE=ubuntu

This isn't true anymore, since the profile could also be ubnutu-lowgfx, so this has to be done from the pre-start script

Revision history for this message
Iain Lane (laney) wrote : Posted in a previous version of this proposal

On Wed, Aug 31, 2016 at 10:54:22AM -0000, Marco Trevisan (Treviño) wrote:
> > - Environment=COMPIZ_CONFIG_PROFILE=ubuntu
>
> This isn't true anymore, since the profile could also be ubnutu-lowgfx, so this has to be done from the pre-start script

Then make that call dbus-update-activation-environment

--
Iain Lane [ <email address hidden> ]
Debian Developer [ <email address hidden> ]
Ubuntu Developer [ <email address hidden> ]

Revision history for this message
Iain Lane (laney) wrote : Posted in a previous version of this proposal

On Wed, Aug 31, 2016 at 11:03:38AM -0000, Iain Lane wrote:
> On Wed, Aug 31, 2016 at 10:54:22AM -0000, Marco Trevisan (Treviño) wrote:
> > > - Environment=COMPIZ_CONFIG_PROFILE=ubuntu
> >
> > This isn't true anymore, since the profile could also be ubnutu-lowgfx, so this has to be done from the pre-start script
>
> Then make that call dbus-update-activation-environment

instead of systemctl set-environment, that is. Most jobs do

  initctl set-env -g ...
  dbus-update-activation-environment --verbose --systemd VAR

--
Iain Lane [ <email address hidden> ]
Debian Developer [ <email address hidden> ]
Ubuntu Developer [ <email address hidden> ]

Revision history for this message
Iain Lane (laney) wrote :

I think the systemd bits themselves are sane now (don't fully understand the locked stuff though).

As discussed, I think ups and maybe bamf could be Wants instead of Requires, so the session can still somewhat work if they get broken.

review: Approve (systemd-units)
Revision history for this message
Ted Gould (ted) wrote :

Seems sane to me. Thanks for working on this Marco!

review: Approve
Revision history for this message
Andrea Azzarone (azzar1) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/CMakeLists.txt'
2--- data/CMakeLists.txt 2016-09-01 11:21:15 +0000
3+++ data/CMakeLists.txt 2016-09-06 14:17:05 +0000
4@@ -33,5 +33,11 @@
5 execute_process (COMMAND ${_glib_comple_schemas} ${CMAKE_BINARY_DIR}/settings)
6
7 # Upstart
8-configure_file(unity7.conf.in ${CMAKE_CURRENT_BINARY_DIR}/unity7.conf)
9+configure_file(unity7.conf.in ${CMAKE_CURRENT_BINARY_DIR}/unity7.conf @ONLY)
10 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/unity7.conf DESTINATION ${CMAKE_INSTALL_DATADIR}/upstart/sessions)
11+
12+# Systemd
13+configure_file(unity7.service.in ${CMAKE_CURRENT_BINARY_DIR}/unity7.service @ONLY)
14+pkg_get_variable(SYSTEMD_USER_DIR systemd systemduserunitdir)
15+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/unity7.service DESTINATION ${SYSTEMD_USER_DIR})
16+install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/unity7.override DESTINATION ${CMAKE_INSTALL_DATADIR}/upstart/systemd-session/upstart)
17
18=== modified file 'data/unity7.conf.in'
19--- data/unity7.conf.in 2016-08-31 15:22:57 +0000
20+++ data/unity7.conf.in 2016-09-06 14:17:05 +0000
21@@ -5,25 +5,8 @@
22 stop on desktop-end
23
24 pre-start script
25- # If gnome-session is going to start compiz,
26- # we don't want to be the ones doing it.
27-
28- if grep -q compiz /usr/share/gnome-session/sessions/ubuntu.session ; then
29- echo "GNOME Session is starting Compiz"
30- stop ; exit 0
31- fi
32-
33- compiz_profile="ubuntu"
34-
35- if ! /usr/lib/nux/unity_support_test -p; then
36- compiz_profile="ubuntu-lowgfx"
37- fi
38-
39- echo "Using compiz profile '$compiz_profile'"
40- initctl set-env -g COMPIZ_CONFIG_PROFILE="$compiz_profile"
41- export COMPIZ_CONFIG_PROFILE="$compiz_profile"
42-
43- ${UNITY_LIBDIR}/unity-active-plugins-safety-check
44+ @UNITY_LIBDIR@/upstart-prestart-check
45+ @UNITY_LIBDIR@/compiz-profile-selector
46 end script
47
48 respawn
49
50=== added file 'data/unity7.override'
51--- data/unity7.override 1970-01-01 00:00:00 +0000
52+++ data/unity7.override 2016-09-06 14:17:05 +0000
53@@ -0,0 +1,1 @@
54+manual
55
56=== added file 'data/unity7.service.in'
57--- data/unity7.service.in 1970-01-01 00:00:00 +0000
58+++ data/unity7.service.in 2016-09-06 14:17:05 +0000
59@@ -0,0 +1,15 @@
60+[Unit]
61+Description=Unity Shell v7
62+Requires=unity-settings-daemon.service unity-panel-service.service bamfdaemon.service
63+Wants=unity-gtk-module.service
64+After=unity-settings-daemon.service
65+PartOf=graphical-session.target
66+
67+[Service]
68+ExecStartPre=@UNITY_LIBDIR@/systemd-prestart-check
69+ExecStartPre=@UNITY_LIBDIR@/compiz-profile-selector
70+ExecStart=/usr/bin/compiz
71+Restart=on-failure
72+
73+[Install]
74+RequiredBy=ubuntu-session.target
75
76=== modified file 'debian/control'
77--- debian/control 2016-09-01 23:13:26 +0000
78+++ debian/control 2016-09-06 14:17:05 +0000
79@@ -37,7 +37,7 @@
80 libnux-4.0-dev (>= 4.0.6),
81 libpam0g-dev,
82 libpango1.0-dev,
83- libsigc++-2.0-dev,
84+ libsigc++-2.0-dev (>= 2.4.0),
85 libstartup-notification0-dev,
86 libunique-dev,
87 libunity-dev (>= 7.1.0),
88@@ -53,6 +53,7 @@
89 python3 (>= 3.4),
90 python-setuptools,
91 quilt,
92+ systemd,
93 xserver-xorg-video-dummy,
94 xsltproc,
95 Standards-Version: 3.9.5
96@@ -81,12 +82,31 @@
97 libxfixes3 (>= 1:5.0.1-1),
98 libxi6 (>= 2:1.7.1.901),
99 unity-scope-home,
100-Provides: indicator-renderer
101 Recommends: unity-control-center,
102 ${unity-default-masterscopes}
103 nautilus,
104 gnome-disk-utility,
105- indicator-appmenu (>= 15.02.0),
106+ hud,
107+ session-shortcuts,
108+Breaks: unity-lens-applications (<< 5.12.0-0ubuntu2),
109+ unity-lens-files (<< 5.10.0-0ubuntu2),
110+ unity-lens-music (<< 6.0.0),
111+ unity-lens-video (<< 0.3.6-0ubuntu2),
112+Description: Interface designed for efficiency of space and interaction.
113+ Unity is a desktop experience that sings. Designed by Canonical and the Ayatana
114+ community, Unity is all about the combination of familiarity and the future. We
115+ bring together visual design, analysis of user experience testing, modern
116+ graphics technologies and a deep understanding of the free software landscape
117+ to produce what we hope will be the lightest, most elegant and most delightful
118+ way to use your PC.
119+
120+Package: unity-services
121+Architecture: any
122+Depends: ${shlibs:Depends},
123+ ${misc:Depends},
124+ indicator-common,
125+Provides: indicator-renderer
126+Recommends: indicator-appmenu (>= 15.02.0),
127 indicator-application,
128 indicator-sound,
129 indicator-bluetooth,
130@@ -96,24 +116,6 @@
131 indicator-printers,
132 indicator-power,
133 indicator-session,
134- hud,
135- session-shortcuts,
136-Breaks: unity-lens-applications (<< 5.12.0-0ubuntu2),
137- unity-lens-files (<< 5.10.0-0ubuntu2),
138- unity-lens-music (<< 6.0.0),
139- unity-lens-video (<< 0.3.6-0ubuntu2),
140-Description: Interface designed for efficiency of space and interaction.
141- Unity is a desktop experience that sings. Designed by Canonical and the Ayatana
142- community, Unity is all about the combination of familiarity and the future. We
143- bring together visual design, analysis of user experience testing, modern
144- graphics technologies and a deep understanding of the free software landscape
145- to produce what we hope will be the lightest, most elegant and most delightful
146- way to use your PC.
147-
148-Package: unity-services
149-Architecture: any
150-Depends: ${shlibs:Depends},
151- ${misc:Depends},
152 Description: Services for the Unity interface
153 Unity is a desktop experience that sings. Designed by Canonical and the Ayatana
154 community, Unity is all about the combination of familiarity and the future. We
155
156=== modified file 'debian/libunity-core-6.0-9.install'
157--- debian/libunity-core-6.0-9.install 2016-07-26 16:45:34 +0000
158+++ debian/libunity-core-6.0-9.install 2016-09-06 14:17:05 +0000
159@@ -2,8 +2,9 @@
160 usr/lib/*/unity/*.py
161 usr/share/ccsm
162 usr/share/gnome-control-center/
163-usr/share/unity
164-usr/share/upstart/sessions/unity7.conf
165+usr/share/unity/icons
166+usr/share/unity/themes
167 debian/unity-crashdb.conf etc/apport/crashdb.conf.d/
168 debian/source_unity.py usr/share/apport/package-hooks
169 tools/convert-files/* usr/lib/compiz/migration/
170+usr/share/upstart/sessions/unity7.conf
171
172=== modified file 'debian/unity-services.install'
173--- debian/unity-services.install 2016-07-26 13:58:14 +0000
174+++ debian/unity-services.install 2016-09-06 14:17:05 +0000
175@@ -1,3 +1,6 @@
176 usr/lib/*/unity/*service
177-usr/share/upstart/sessions/unity-panel-service*.conf
178+usr/share/upstart/sessions/unity-panel*
179+usr/share/upstart/systemd-session/upstart/unity-panel*
180+usr/lib/systemd/user/unity-panel*
181+usr/lib/systemd/user/unity-screen-locked.target
182 usr/share/man/*/unity-panel-service.1
183
184=== added file 'debian/unity-services.links'
185--- debian/unity-services.links 1970-01-01 00:00:00 +0000
186+++ debian/unity-services.links 2016-09-06 14:17:05 +0000
187@@ -0,0 +1,13 @@
188+/usr/lib/systemd/user/indicator-application.service /usr/lib/systemd/user/unity-panel-service.service.wants/indicator-application.service
189+/usr/lib/systemd/user/indicator-bluetooth.service /usr/lib/systemd/user/unity-panel-service.service.wants/indicator-bluetooth.service
190+/usr/lib/systemd/user/indicator-datetime.service /usr/lib/systemd/user/unity-panel-service.service.wants/indicator-datetime.service
191+/usr/lib/systemd/user/indicator-keyboard.service /usr/lib/systemd/user/unity-panel-service.service.wants/indicator-keyboard.service
192+/usr/lib/systemd/user/indicator-messages.service /usr/lib/systemd/user/unity-panel-service.service.wants/indicator-messages.service
193+/usr/lib/systemd/user/indicator-power.service /usr/lib/systemd/user/unity-panel-service.service.wants/indicator-power.service
194+/usr/lib/systemd/user/indicator-session.service /usr/lib/systemd/user/unity-panel-service.service.wants/indicator-session.service
195+/usr/lib/systemd/user/indicator-sound.service /usr/lib/systemd/user/unity-panel-service.service.wants/indicator-sound.service
196+/usr/lib/systemd/user/indicator-datetime.service /usr/lib/systemd/user/unity-panel-service-lockscreen.service.wants/indicator-datetime.service
197+/usr/lib/systemd/user/indicator-keyboard.service /usr/lib/systemd/user/unity-panel-service-lockscreen.service.wants/indicator-keyboard.service
198+/usr/lib/systemd/user/indicator-power.service /usr/lib/systemd/user/unity-panel-service-lockscreen.service.wants/indicator-power.service
199+/usr/lib/systemd/user/indicator-session.service /usr/lib/systemd/user/unity-panel-service-lockscreen.service.wants/indicator-session.service
200+/usr/lib/systemd/user/indicator-sound.service /usr/lib/systemd/user/unity-panel-service-lockscreen.service.wants/indicator-sound.service
201
202=== modified file 'debian/unity.install'
203--- debian/unity.install 2016-07-26 16:45:34 +0000
204+++ debian/unity.install 2016-09-06 14:17:05 +0000
205@@ -2,6 +2,10 @@
206 usr/bin
207 usr/lib/*/compiz/libunity*.so
208 usr/lib/*/unity/unity-active-plugins-safety-check
209+usr/lib/*/unity/compiz-profile-selector
210+usr/lib/*/unity/*-prestart-check
211+usr/lib/systemd/user/unity7.service
212 usr/share/man/*/unity.1
213 usr/share/compiz
214 usr/share/locale
215+usr/share/upstart/systemd-session/upstart/unity7.override
216
217=== added file 'debian/unity.links'
218--- debian/unity.links 1970-01-01 00:00:00 +0000
219+++ debian/unity.links 2016-09-06 14:17:05 +0000
220@@ -0,0 +1,1 @@
221+/usr/lib/systemd/user/unity7.service /usr/lib/systemd/user/ubuntu-session.target.requires/unity7.service
222
223=== modified file 'lockscreen/LockScreenController.cpp'
224--- lockscreen/LockScreenController.cpp 2016-08-29 17:45:46 +0000
225+++ lockscreen/LockScreenController.cpp 2016-09-06 14:17:05 +0000
226@@ -41,6 +41,7 @@
227 const unsigned int IDLE_FADE_DURATION = 10000;
228 const unsigned int LOCK_FADE_DURATION = 400;
229 const unsigned int POST_LOCK_SCREENSAVER_WAIT = 2;
230+const std::string SYSTEMD_LOCK_TARGET = "unity-screen-locked.target";
231
232 class BlankWindow : public nux::BaseWindow
233 {
234@@ -56,6 +57,7 @@
235 Controller::Controller(DBusManager::Ptr const& dbus_manager,
236 session::Manager::Ptr const& session_manager,
237 key::Grabber::Ptr const& key_grabber,
238+ SystemdWrapper::Ptr const& systemd_wrapper,
239 UpstartWrapper::Ptr const& upstart_wrapper,
240 ShieldFactoryInterface::Ptr const& shield_factory,
241 bool test_mode)
242@@ -63,6 +65,7 @@
243 , dbus_manager_(dbus_manager)
244 , session_manager_(session_manager)
245 , key_grabber_(key_grabber)
246+ , systemd_wrapper_(systemd_wrapper)
247 , upstart_wrapper_(upstart_wrapper)
248 , shield_factory_(shield_factory)
249 , suspend_inhibitor_manager_(std::make_shared<SuspendInhibitorManager>())
250@@ -129,6 +132,7 @@
251 shields_.clear();
252
253 upstart_wrapper_->Emit("desktop-unlock");
254+ systemd_wrapper_->Stop(SYSTEMD_LOCK_TARGET);
255 accelerator_controller_.reset();
256 menu_manager_.reset();
257 }
258@@ -464,6 +468,7 @@
259 {
260 menu_manager_ = std::make_shared<menu::Manager>(std::make_shared<indicator::LockScreenDBusIndicators>(), key_grabber_);
261 upstart_wrapper_->Emit("desktop-lock");
262+ systemd_wrapper_->Start(SYSTEMD_LOCK_TARGET);
263
264 accelerator_controller_ = std::make_shared<AcceleratorController>(key_grabber_);
265 auto activate_key = WindowManager::Default().activate_indicators_key();
266
267=== modified file 'lockscreen/LockScreenController.h'
268--- lockscreen/LockScreenController.h 2016-08-29 17:45:46 +0000
269+++ lockscreen/LockScreenController.h 2016-09-06 14:17:05 +0000
270@@ -30,6 +30,7 @@
271 #include "SuspendInhibitorManager.h"
272 #include "ScreenSaverDBusManager.h"
273 #include "unity-shared/BackgroundEffectHelper.h"
274+#include "unity-shared/SystemdWrapper.h"
275 #include "unity-shared/UpstartWrapper.h"
276
277 namespace unity
278@@ -45,6 +46,7 @@
279 typedef std::shared_ptr<Controller> Ptr;
280
281 Controller(DBusManager::Ptr const&, session::Manager::Ptr const&, key::Grabber::Ptr const&,
282+ SystemdWrapper::Ptr const& systemd_wrapper = std::make_shared<SystemdWrapper>(),
283 UpstartWrapper::Ptr const& upstart_wrapper = std::make_shared<UpstartWrapper>(),
284 ShieldFactoryInterface::Ptr const& shield_factory = std::make_shared<ShieldFactory>(),
285 bool test_mode = false);
286@@ -87,6 +89,7 @@
287 menu::Manager::Ptr menu_manager_;
288 key::Grabber::Ptr key_grabber_;
289 AcceleratorController::Ptr accelerator_controller_;
290+ SystemdWrapper::Ptr systemd_wrapper_;
291 UpstartWrapper::Ptr upstart_wrapper_;
292 ShieldFactoryInterface::Ptr shield_factory_;
293 SuspendInhibitorManager::Ptr suspend_inhibitor_manager_;
294
295=== modified file 'services/CMakeLists.txt'
296--- services/CMakeLists.txt 2016-08-31 15:05:58 +0000
297+++ services/CMakeLists.txt 2016-09-06 14:17:05 +0000
298@@ -58,3 +58,34 @@
299
300 configure_file(unity-panel-service-lockscreen.conf.in ${CMAKE_CURRENT_BINARY_DIR}/unity-panel-service-lockscreen.conf)
301 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/unity-panel-service-lockscreen.conf DESTINATION ${CMAKE_INSTALL_DATADIR}/upstart/sessions)
302+
303+##
304+## Systemd Unit Files
305+##
306+
307+# where to install
308+# Uncomment when we drop Vivid
309+# pkg_get_variable(SYSTEMD_USER_DIR systemd systemduserunitdir)
310+set (SYSTEMD_USER_DIR "/usr/lib/systemd/user")
311+message (STATUS "${SYSTEMD_USER_DIR} is the systemd user unit file install dir")
312+
313+configure_file (unity-panel-service.service.in "${CMAKE_CURRENT_BINARY_DIR}/unity-panel-service.service")
314+configure_file (unity-panel-service-lockscreen.service.in "${CMAKE_CURRENT_BINARY_DIR}/unity-panel-service-lockscreen.service")
315+
316+install( FILES
317+ "${CMAKE_CURRENT_BINARY_DIR}/unity-panel-service.service"
318+ "${CMAKE_CURRENT_BINARY_DIR}/unity-panel-service-lockscreen.service"
319+ "${CMAKE_CURRENT_SOURCE_DIR}/unity-screen-locked.target"
320+ DESTINATION "${SYSTEMD_USER_DIR}")
321+
322+##
323+## Upstart systemd override Job File
324+##
325+
326+set (UPSTART_SYSTEMD_OVERRIDE_DIR "${CMAKE_INSTALL_FULL_DATADIR}/upstart/systemd-session/upstart")
327+message (STATUS "${UPSTART_SYSTEMD_OVERRIDE_DIR} is the Upstart override Job File for systemd dir")
328+
329+install (FILES
330+ unity-panel-service.override
331+ unity-panel-service-lockscreen.override
332+ DESTINATION "${UPSTART_SYSTEMD_OVERRIDE_DIR}")
333
334=== modified file 'services/unity-panel-service-lockscreen.conf.in'
335--- services/unity-panel-service-lockscreen.conf.in 2016-08-31 15:05:58 +0000
336+++ services/unity-panel-service-lockscreen.conf.in 2016-09-06 14:17:05 +0000
337@@ -4,5 +4,7 @@
338 start on desktop-lock
339 stop on desktop-unlock
340
341+pre-start exec @UNITY_LIBDIR@/upstart-prestart-check
342+
343 respawn
344-exec ${UNITY_LIBDIR}/unity-panel-service --lockscreen-mode
345+exec @UNITY_LIBDIR@/unity-panel-service --lockscreen-mode
346
347=== added file 'services/unity-panel-service-lockscreen.override'
348--- services/unity-panel-service-lockscreen.override 1970-01-01 00:00:00 +0000
349+++ services/unity-panel-service-lockscreen.override 2016-09-06 14:17:05 +0000
350@@ -0,0 +1,1 @@
351+manual
352
353=== modified file 'services/unity-panel-service-lockscreen.service.in'
354--- services/unity-panel-service-lockscreen.service.in 2016-08-31 15:05:58 +0000
355+++ services/unity-panel-service-lockscreen.service.in 2016-09-06 14:17:05 +0000
356@@ -3,5 +3,6 @@
357 PartOf=unity-screen-locked.target
358
359 [Service]
360-ExecStart=${UNITY_LIBDIR}/unity-panel-service --lockscreen-mode
361+ExecStartPre=@UNITY_LIBDIR@/systemd-prestart-check
362+ExecStart=@UNITY_LIBDIR@/unity-panel-service --lockscreen-mode
363 Restart=on-failure
364
365=== modified file 'services/unity-panel-service.conf.in'
366--- services/unity-panel-service.conf.in 2016-08-31 15:05:58 +0000
367+++ services/unity-panel-service.conf.in 2016-09-06 14:17:05 +0000
368@@ -11,8 +11,10 @@
369 start on desktop-start DESKTOP_SESSION=ubuntu
370 stop on desktop-end
371
372+pre-start exec @UNITY_LIBDIR@/upstart-prestart-check
373+
374 emits indicator-services-start
375 emits indicator-services-end
376
377 respawn
378-exec ${UNITY_LIBDIR}/unity-panel-service
379+exec @UNITY_LIBDIR@/unity-panel-service
380
381=== added file 'services/unity-panel-service.override'
382--- services/unity-panel-service.override 1970-01-01 00:00:00 +0000
383+++ services/unity-panel-service.override 2016-09-06 14:17:05 +0000
384@@ -0,0 +1,1 @@
385+manual
386
387=== added file 'services/unity-panel-service.service.in'
388--- services/unity-panel-service.service.in 1970-01-01 00:00:00 +0000
389+++ services/unity-panel-service.service.in 2016-09-06 14:17:05 +0000
390@@ -0,0 +1,10 @@
391+[Unit]
392+Description=Backing Service for the Unity Panel
393+After=unity7.service
394+PartOf=graphical-session.target
395+BindsTo=indicators-pre.target
396+
397+[Service]
398+ExecStartPre=@UNITY_LIBDIR@/systemd-prestart-check
399+ExecStart=@UNITY_LIBDIR@/unity-panel-service
400+Restart=on-failure
401
402=== added file 'services/unity-screen-locked.target'
403--- services/unity-screen-locked.target 1970-01-01 00:00:00 +0000
404+++ services/unity-screen-locked.target 2016-09-06 14:17:05 +0000
405@@ -0,0 +1,5 @@
406+[Unit]
407+Description=A target that, when running, represents the screen being locked
408+Requires=unity7.service
409+Wants=unity-panel-service-lockscreen.service
410+PartOf=graphical-session.target
411
412=== modified file 'tests/CMakeLists.txt'
413--- tests/CMakeLists.txt 2015-12-17 22:32:37 +0000
414+++ tests/CMakeLists.txt 2016-09-06 14:17:05 +0000
415@@ -286,6 +286,7 @@
416 test_switcher_controller_class.cpp
417 test_switcher_model.cpp
418 test_switcher_view.cpp
419+ test_systemd_wrapper.cpp
420 test_tabiterator.cpp
421 test_texture_cache.cpp
422 test_text_input.cpp
423
424=== modified file 'tests/test_lockscreen_controller.cpp'
425--- tests/test_lockscreen_controller.cpp 2016-08-29 17:45:46 +0000
426+++ tests/test_lockscreen_controller.cpp 2016-09-06 14:17:05 +0000
427@@ -83,9 +83,10 @@
428 , session_manager(std::make_shared<NiceMock<session::MockManager>>())
429 , key_grabber(std::make_shared<key::MockGrabber::Nice>())
430 , dbus_manager(std::make_shared<DBusManager>(session_manager))
431+ , systemd_wrapper(std::make_shared<SystemdWrapper>())
432 , upstart_wrapper(std::make_shared<UpstartWrapper>())
433 , shield_factory(std::make_shared<ShieldFactoryMock>())
434- , controller(dbus_manager, session_manager, key_grabber, upstart_wrapper, shield_factory)
435+ , controller(dbus_manager, session_manager, key_grabber, systemd_wrapper, upstart_wrapper, shield_factory)
436 {}
437
438 struct ControllerWrap : Controller
439@@ -93,9 +94,10 @@
440 ControllerWrap(DBusManager::Ptr const& dbus_manager,
441 session::Manager::Ptr const& session_manager,
442 key::Grabber::Ptr const& key_grabber,
443+ SystemdWrapper::Ptr const& systemd_wrapper,
444 UpstartWrapper::Ptr const& upstart_wrapper,
445 ShieldFactoryInterface::Ptr const& shield_factory)
446- : Controller(dbus_manager, session_manager, key_grabber, upstart_wrapper, shield_factory, /* test_mode */ true)
447+ : Controller(dbus_manager, session_manager, key_grabber, systemd_wrapper, upstart_wrapper, shield_factory, /* test_mode */ true)
448 {}
449
450 using Controller::shields_;
451@@ -112,6 +114,7 @@
452 session::MockManager::Ptr session_manager;
453 key::MockGrabber::Ptr key_grabber;
454 DBusManager::Ptr dbus_manager;
455+ unity::SystemdWrapper::Ptr systemd_wrapper;
456 unity::UpstartWrapper::Ptr upstart_wrapper;
457
458 ShieldFactoryMock::Ptr shield_factory;
459
460=== added file 'tests/test_systemd_wrapper.cpp'
461--- tests/test_systemd_wrapper.cpp 1970-01-01 00:00:00 +0000
462+++ tests/test_systemd_wrapper.cpp 2016-09-06 14:17:05 +0000
463@@ -0,0 +1,110 @@
464+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
465+/*
466+* Copyright (c) 2016 Canonical Ltd
467+*
468+* This program is free software: you can redistribute it and/or modify
469+* it under the terms of the GNU General Public License version 3 as
470+* published by the Free Software Foundation.
471+*
472+* This program is distributed in the hope that it will be useful,
473+* but WITHOUT ANY WARRANTY; without even the implied warranty of
474+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
475+* GNU General Public License for more details.
476+*
477+* You should have received a copy of the GNU General Public License
478+* along with this program. If not, see <http://www.gnu.org/licenses/>.
479+*
480+* Authored by: Ted Gould <ted@canonical.com>
481+*/
482+
483+#include <gtest/gtest.h>
484+using namespace testing;
485+
486+#include "unity-shared/SystemdWrapper.h"
487+
488+#include <UnityCore/GLibDBusServer.h>
489+#include <UnityCore/Variant.h>
490+
491+#include "test_utils.h"
492+
493+namespace
494+{
495+
496+const std::string SYSTEMD =
497+R"(<node>
498+ <interface name="org.freedesktop.systemd1.Manager">
499+ <method name="StartUnit">
500+ <arg name="name" type="s" direction="in" />
501+ <arg name="mode" type="s" direction="in" />
502+ <arg name="job" type="o" direction="out" />
503+ </method>
504+ <method name="StopUnit">
505+ <arg name="name" type="s" direction="in" />
506+ <arg name="mode" type="s" direction="in" />
507+ <arg name="job" type="o" direction="out" />
508+ </method>
509+ </interface>
510+</node>)";
511+
512+struct MockSystemdWrapper : unity::SystemdWrapper {
513+ MockSystemdWrapper()
514+ : SystemdWrapper(SystemdWrapper::TestMode())
515+ {}
516+};
517+
518+struct TestSystemdWrapper : public Test
519+{
520+ TestSystemdWrapper()
521+ {
522+ systemd_server_ = std::make_shared<unity::glib::DBusServer>("com.canonical.Unity.Test.Systemd");
523+ systemd_server_->AddObjects(SYSTEMD, "/org/freedesktop/systemd1");
524+
525+ Utils::WaitUntilMSec([this] { return systemd_server_->IsConnected(); });
526+ }
527+
528+ unity::glib::DBusServer::Ptr systemd_server_;
529+ MockSystemdWrapper systemd_wrapper_;
530+};
531+
532+
533+TEST_F(TestSystemdWrapper, Start)
534+{
535+ bool start_sent = false;
536+
537+ systemd_server_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant* par) -> GVariant* {
538+ if (method == "StartUnit")
539+ {
540+ start_sent = true;
541+
542+ std::string event_name = glib::Variant(g_variant_get_child_value(par, 0)).GetString();
543+ EXPECT_EQ("unity-screen-locked", event_name);
544+ }
545+
546+ return nullptr;
547+ });
548+
549+ systemd_wrapper_.Start("unity-screen-locked");
550+ Utils::WaitUntil(start_sent);
551+}
552+
553+TEST_F(TestSystemdWrapper, Stop)
554+{
555+ bool stop_sent = false;
556+
557+ systemd_server_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant* par) -> GVariant* {
558+ if (method == "StopUnit")
559+ {
560+ stop_sent = true;
561+
562+ std::string event_name = glib::Variant(g_variant_get_child_value(par, 0)).GetString();
563+ EXPECT_EQ("unity-screen-locked", event_name);
564+ }
565+
566+ return nullptr;
567+ });
568+
569+ systemd_wrapper_.Stop("unity-screen-locked");
570+ Utils::WaitUntil(stop_sent);
571+}
572+
573+}
574
575=== modified file 'tools/CMakeLists.txt'
576--- tools/CMakeLists.txt 2016-08-31 15:05:58 +0000
577+++ tools/CMakeLists.txt 2016-09-06 14:17:05 +0000
578@@ -28,3 +28,9 @@
579 add_executable(unity-active-plugins-safety-check unity_active_plugins_safety_check.cpp)
580 target_link_libraries(unity-active-plugins-safety-check ${LIBS})
581 install(TARGETS unity-active-plugins-safety-check DESTINATION ${UNITY_INSTALL_LIBDIR})
582+
583+configure_file (${CMAKE_CURRENT_SOURCE_DIR}/compiz-profile-selector.in ${CMAKE_CURRENT_BINARY_DIR}/compiz-profile-selector @ONLY)
584+install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/compiz-profile-selector DESTINATION ${UNITY_INSTALL_LIBDIR})
585+
586+install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/systemd-prestart-check DESTINATION ${UNITY_INSTALL_LIBDIR})
587+install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/upstart-prestart-check DESTINATION ${UNITY_INSTALL_LIBDIR})
588
589=== added file 'tools/compiz-profile-selector.in'
590--- tools/compiz-profile-selector.in 1970-01-01 00:00:00 +0000
591+++ tools/compiz-profile-selector.in 2016-09-06 14:17:05 +0000
592@@ -0,0 +1,19 @@
593+#!/bin/bash
594+
595+set -e
596+compiz_profile="ubuntu"
597+
598+if ! /usr/lib/nux/unity_support_test -p; then
599+ compiz_profile="ubuntu-lowgfx"
600+fi
601+
602+echo "Using compiz profile '$compiz_profile'"
603+
604+if [ -n "$UPSTART_SESSION" ]; then
605+ initctl set-env -g COMPIZ_CONFIG_PROFILE="$compiz_profile"
606+fi
607+
608+dbus-update-activation-environment --verbose --systemd COMPIZ_CONFIG_PROFILE="$compiz_profile"
609+
610+export COMPIZ_CONFIG_PROFILE="$compiz_profile"
611+exec @UNITY_LIBDIR@/unity-active-plugins-safety-check
612
613=== added file 'tools/systemd-prestart-check'
614--- tools/systemd-prestart-check 1970-01-01 00:00:00 +0000
615+++ tools/systemd-prestart-check 2016-09-06 14:17:05 +0000
616@@ -0,0 +1,29 @@
617+#!/bin/bash
618+
619+this_unit=$(sed -n "s,.*:name=systemd:.*/\([^/]\+\.service\)/\?.*,\1,p" /proc/self/cgroup)
620+
621+if [ -n "$this_unit" ] && [[ $this_unit == "unity"* ]]; then
622+ this_job=$(systemctl --user list-jobs $this_unit | sed -n "s,\([0-9]\+\)\s\+${this_unit//./\\.}.*,\1,p")
623+fi
624+
625+# If gnome-session is going to start compiz,
626+# we don't want to be the ones doing it.
627+if grep -q compiz /usr/share/gnome-session/sessions/ubuntu.session; then
628+ echo "GNOME Session is starting Compiz"
629+ [ -n "$this_job" ] && systemctl --user cancel $this_job
630+ exit 1
631+fi
632+
633+if [ -z "$UPSTART_SESSION" ]; then
634+ exit 0
635+fi
636+
637+upstart_status=$(initctl status unity7) || true
638+
639+if (echo "$upstart_status" | grep -q "start/running"); then
640+ echo "Unity is managed by Upstart"
641+ [ -n "$this_job" ] && systemctl --user cancel $this_job
642+ exit 1
643+fi
644+
645+exit 0
646
647=== modified file 'tools/unity.cmake'
648--- tools/unity.cmake 2016-07-12 18:43:50 +0000
649+++ tools/unity.cmake 2016-09-06 14:17:05 +0000
650@@ -27,6 +27,7 @@
651 import subprocess
652 import sys
653 import time
654+import xdg.BaseDirectory
655
656 DEFAULT_COMMAND = "compiz --replace"
657 home_dir = os.path.expanduser("~%s" % os.getenv("SUDO_USER"))
658@@ -74,8 +75,49 @@
659 '''Reset the default launcher icon and restart it.'''
660 subprocess.Popen(["gsettings", "reset" ,"com.canonical.Unity.Launcher" , "favorites"])
661
662+def call_silently(cmd):
663+ return subprocess.call(cmd.split(), stdout=open(os.devnull, 'w'), stderr=subprocess.STDOUT) == 0
664+
665+def session_manager_command(service, what):
666+ if is_systemd_session() and not is_running_in_upstart(service):
667+ return "systemctl --user {} {}.service".format(what, service)
668+ elif is_upstart_session():
669+ return "{} {}".format(what, service)
670+
671 def is_upstart_session():
672- return 'UPSTART_SESSION' in os.environ.keys() and len(os.environ['UPSTART_SESSION'])
673+ return 'UPSTART_SESSION' in os.environ.keys() and len(os.environ['UPSTART_SESSION'])
674+
675+def is_running_in_upstart(service):
676+ return is_upstart_session() and b'start/running' in subprocess.check_output("status {}".format(service).split())
677+
678+def is_unity_running_in_upstart():
679+ return is_running_in_upstart("unity7")
680+
681+def is_systemd_session():
682+ try:
683+ return os.path.exists(os.path.join(xdg.BaseDirectory.get_runtime_dir(), "systemd"))
684+ except:
685+ return False
686+
687+def is_unity_running_in_systemd():
688+ return is_systemd_session() and not is_unity_running_in_upstart() and \
689+ call_silently(session_manager_command("unity7", "is-active"))
690+
691+def is_unity_running_in_session_manager():
692+ return is_unity_running_in_systemd() or is_unity_running_in_upstart()
693+
694+def start_with_session_manager():
695+ return subprocess.Popen(session_manager_command("unity7", "start").split())
696+
697+def restart_with_session_manager():
698+ if is_unity_running_in_session_manager():
699+ return subprocess.Popen(session_manager_command("unity7", "restart").split())
700+ return start_with_session_manager()
701+
702+def stop_with_session_manager():
703+ if is_unity_running_in_session_manager():
704+ return call_silently(session_manager_command("unity7", "stop"))
705+ return False
706
707 def process_and_start_unity (compiz_args):
708 '''launch unity under compiz (replace the current shell in any case)'''
709@@ -108,9 +150,14 @@
710 if options.log:
711 cli.extend(['2>&1', '|', 'tee', options.log])
712
713- if is_upstart_session():
714- if b'start/running' in subprocess.check_output("status unity7".split()):
715- subprocess.call("stop unity7".split())
716+ run_command = " ".join(cli)
717+
718+ if run_command == DEFAULT_COMMAND and not options.ignore_session_manager and \
719+ (is_upstart_session() or is_systemd_session()):
720+ return restart_with_session_manager()
721+
722+ if is_unity_running_in_upstart():
723+ stop_with_session_manager()
724
725 # kill a previous compiz if was there (this is a hack as compiz can
726 # sometimes get stuck and not exit on --replace)
727@@ -128,15 +175,10 @@
728 except IOError:
729 continue
730
731- run_command = " ".join(cli)
732-
733- if is_upstart_session() and run_command == DEFAULT_COMMAND and not options.ignore_upstart:
734- return subprocess.Popen("start unity7".split())
735- else:
736- # shell = True as it's the simpest way to | tee.
737- # In this case, we need a string and not a list
738- # FIXME: still some bug with 2>&1 not showing everything before wait()
739- return subprocess.Popen(" ".join(cli), env=dict(os.environ), shell=True)
740+ # shell = True as it's the simpest way to | tee.
741+ # In this case, we need a string and not a list
742+ # FIXME: still some bug with 2>&1 not showing everything before wait()
743+ return subprocess.Popen(run_command, env=dict(os.environ), shell=True)
744
745
746 def run_unity (compiz_args):
747@@ -144,9 +186,9 @@
748
749 try:
750 options.debug_mode = 2 if options.advanced_debug else 1 if options.debug else 0
751- if is_upstart_session(): subprocess.call(["stop", "unity-panel-service"])
752+ session_manager_command("unity-panel-service", "stop")
753 unity_instance = process_and_start_unity (compiz_args)
754- if is_upstart_session(): subprocess.call(["start", "unity-panel-service"])
755+ session_manager_command("unity-panel-service", "start")
756 unity_instance.wait()
757 except KeyboardInterrupt as e:
758 try:
759@@ -199,8 +241,12 @@
760 help="Store log under filename.")
761 parser.add_option("--replace", action="store_true",
762 help="Run unity /!\ This is for compatibility with other desktop interfaces and acts the same as running unity without --replace")
763- parser.add_option("--ignore-upstart", action="store_true",
764- help="Run unity without upstart support")
765+ if is_systemd_session() and not is_unity_running_in_upstart():
766+ parser.add_option("--ignore-systemd", action="store_true", dest="ignore_session_manager",
767+ help="Run unity without systemd support")
768+ elif is_upstart_session():
769+ parser.add_option("--ignore-upstart", action="store_true", dest="ignore_session_manager",
770+ help="Run unity without upstart support")
771 parser.add_option("--reset", action="store_true",
772 help="(deprecated: provided for backwards compatibility)")
773 parser.add_option("--reset-icons", action="store_true",
774
775=== added file 'tools/upstart-prestart-check'
776--- tools/upstart-prestart-check 1970-01-01 00:00:00 +0000
777+++ tools/upstart-prestart-check 2016-09-06 14:17:05 +0000
778@@ -0,0 +1,17 @@
779+#!/bin/bash
780+
781+# If gnome-session is going to start compiz,
782+# we don't want to be the ones doing it.
783+if grep -q compiz /usr/share/gnome-session/sessions/ubuntu.session ; then
784+ echo "GNOME Session is starting Compiz"
785+ stop
786+ exit 1
787+fi
788+
789+if (systemctl --user is-active unity7 &> /dev/null); then
790+ echo "Unity instance is managed by Systemd, ignoring request..."
791+ stop
792+ exit 1
793+fi
794+
795+exit 0
796
797=== modified file 'unity-shared/CMakeLists.txt'
798--- unity-shared/CMakeLists.txt 2016-09-01 23:56:24 +0000
799+++ unity-shared/CMakeLists.txt 2016-09-06 14:17:05 +0000
800@@ -60,6 +60,7 @@
801 SpreadFilter.cpp
802 SpreadWidgets.cpp
803 StaticCairoText.cpp
804+ SystemdWrapper.cpp
805 TextureCache.cpp
806 TextInput.cpp
807 TextureThumbnailProvider.cpp
808
809=== added file 'unity-shared/SystemdWrapper.cpp'
810--- unity-shared/SystemdWrapper.cpp 1970-01-01 00:00:00 +0000
811+++ unity-shared/SystemdWrapper.cpp 2016-09-06 14:17:05 +0000
812@@ -0,0 +1,96 @@
813+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
814+/*
815+* Copyright © 2016 Canonical Ltd
816+*
817+* This program is free software: you can redistribute it and/or modify
818+* it under the terms of the GNU General Public License version 3 as
819+* published by the Free Software Foundation.
820+*
821+* This program is distributed in the hope that it will be useful,
822+* but WITHOUT ANY WARRANTY; without even the implied warranty of
823+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
824+* GNU General Public License for more details.
825+*
826+* You should have received a copy of the GNU General Public License
827+* along with this program. If not, see <http://www.gnu.org/licenses/>.
828+*
829+* Authored by: Ted Gould <ted@canonical.com>
830+*/
831+
832+#include "SystemdWrapper.h"
833+
834+#include <UnityCore/GLibDBusProxy.h>
835+
836+namespace unity
837+{
838+
839+//
840+// Start private implementation
841+//
842+
843+class SystemdWrapper::Impl
844+{
845+public:
846+ Impl(bool test);
847+
848+ void Start(std::string const& name);
849+ void Stop(std::string const& name);
850+ void CallMethod(std::string const& method, std::string const& unit);
851+
852+private:
853+ bool test_mode_;
854+ glib::DBusProxy::Ptr systemd_proxy_;
855+};
856+
857+SystemdWrapper::Impl::Impl(bool test)
858+ : test_mode_(test)
859+{}
860+
861+void SystemdWrapper::Impl::CallMethod(std::string const& method, std::string const& unit)
862+{
863+ auto const& busname = test_mode_ ? "com.canonical.Unity.Test.Systemd" : "org.freedesktop.systemd1";
864+ auto flags = static_cast<GDBusProxyFlags>(G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
865+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS);
866+ auto proxy = std::make_shared<glib::DBusProxy>(busname, "/org/freedesktop/systemd1",
867+ "org.freedesktop.systemd1.Manager",
868+ G_BUS_TYPE_SESSION, flags);
869+
870+ proxy->CallBegin(method, g_variant_new("(ss)", unit.c_str(), "replace"), [proxy] (GVariant*, glib::Error const& e) {});
871+}
872+
873+void SystemdWrapper::Impl::Start(std::string const& name)
874+{
875+ CallMethod("StartUnit", name);
876+}
877+
878+void SystemdWrapper::Impl::Stop(std::string const& name)
879+{
880+ CallMethod("StopUnit", name);
881+}
882+
883+//
884+// End private implementation
885+//
886+
887+SystemdWrapper::SystemdWrapper()
888+ : pimpl_(new Impl(false))
889+{}
890+
891+SystemdWrapper::SystemdWrapper(SystemdWrapper::TestMode const& tm)
892+ : pimpl_(new Impl(true))
893+{}
894+
895+SystemdWrapper::~SystemdWrapper()
896+{}
897+
898+void SystemdWrapper::Start(std::string const& name)
899+{
900+ pimpl_->Start(name);
901+}
902+
903+void SystemdWrapper::Stop(std::string const& name)
904+{
905+ pimpl_->Stop(name);
906+}
907+
908+}
909
910=== added file 'unity-shared/SystemdWrapper.h'
911--- unity-shared/SystemdWrapper.h 1970-01-01 00:00:00 +0000
912+++ unity-shared/SystemdWrapper.h 2016-09-06 14:17:05 +0000
913@@ -0,0 +1,54 @@
914+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
915+/*
916+* Copyright © 2016 Canonical Ltd
917+*
918+* This program is free software: you can redistribute it and/or modify
919+* it under the terms of the GNU General Public License version 3 as
920+* published by the Free Software Foundation.
921+*
922+* This program is distributed in the hope that it will be useful,
923+* but WITHOUT ANY WARRANTY; without even the implied warranty of
924+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
925+* GNU General Public License for more details.
926+*
927+* You should have received a copy of the GNU General Public License
928+* along with this program. If not, see <http://www.gnu.org/licenses/>.
929+*
930+* Authored by: Ted Gould <ted@canonical.com>
931+*/
932+
933+#ifndef UNITY_SYSTEMD_WRAPPER
934+#define UNITY_SYSTEMD_WRAPPER
935+
936+#include <memory>
937+
938+namespace unity
939+{
940+
941+class SystemdWrapper
942+{
943+public:
944+ typedef std::shared_ptr<SystemdWrapper> Ptr;
945+
946+ SystemdWrapper();
947+ ~SystemdWrapper();
948+
949+ void Start(std::string const& name);
950+ void Stop(std::string const& name);
951+
952+protected:
953+ struct TestMode {};
954+ SystemdWrapper(TestMode const&);
955+
956+private:
957+ // Noncopyable
958+ SystemdWrapper(SystemdWrapper const&) = delete;
959+ SystemdWrapper& operator=(SystemdWrapper const&) = delete;
960+
961+ class Impl;
962+ std::unique_ptr<Impl> pimpl_;
963+};
964+
965+}
966+
967+#endif