| 1 |
#!/bin/sh |
| 2 |
set -e |
| 3 |
|
| 4 |
# clean-up upstart env, if the last session was run with upstart |
| 5 |
# without session systemd restart |
| 6 |
unset UPSTART_SESSION |
| 7 |
systemctl --user unset-environment UPSTART_SESSION |
| 8 |
|
| 9 |
# some old Qt programs still check this long-deprecated env var |
| 10 |
dbus-update-activation-environment --systemd GNOME_DESKTOP_SESSION_ID=this-is-deprecated |
| 11 |
|
| 12 |
# stop any lingering active units from a previous session |
| 13 |
systemctl --user stop graphical-session.target graphical-session-pre.target |
| 14 |
|
| 15 |
# robustness: if the previous graphical session left some failed units, |
| 16 |
# reset them so that they don't break this startup |
| 17 |
for unit in $(systemctl --user --no-legend --state=failed list-units | cut -f1 -d' '); do |
| 18 |
if [ "$(systemctl --user show -p PartOf --value $unit)" = "graphical-session.target" ]; then |
| 19 |
systemctl --user reset-failed $unit |
| 20 |
fi |
| 21 |
done |
| 22 |
|
| 23 |
# FIXME: synthesize After=graphical-session-pre.target dependencies until this |
| 24 |
# can be done declaratively (https://github.com/systemd/systemd/issues/3750) |
| 25 |
# This could be a generator, but we don't want to penalize non-graphical logins |
| 26 |
# with this. |
| 27 |
systemctl --user list-unit-files --no-legend | while read unit status _; do |
| 28 |
[ "${unit%.service}" != "$unit" ] || continue |
| 29 |
[ "$status" != "$disabled" ] || continue |
| 30 |
if [ "$(systemctl --user show -p PartOf --value $unit)" = "graphical-session.target" ]; then |
| 31 |
mkdir -p "$XDG_RUNTIME_DIR/systemd/user/${unit}.d" |
| 32 |
printf '[Unit]\nAfter=graphical-session-pre.target\n' > "$XDG_RUNTIME_DIR/systemd/user/${unit}.d/graphical-session-pre.conf" |
| 33 |
fi |
| 34 |
done |
| 35 |
systemctl --user daemon-reload |
| 36 |
|
| 37 |
systemctl --user start --wait "$1" |
| 38 |
|
| 39 |
dbus-update-activation-environment --systemd GNOME_DESKTOP_SESSION_ID= |
| 40 |
|
| 41 |
# Delay killing the X server until all graphical units stopped |
| 42 |
systemctl --user stop graphical-session-pre.target |