This repository has been archived by the owner on Mar 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstartsystemd
executable file
·89 lines (78 loc) · 3.08 KB
/
startsystemd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/sh
LOGFILE=~/startsystemd.log
function log() {
# Uncomment the following line to enable logging for debugging purposes
#echo "["$(date '+%F %T')"] "$@ >> ${LOGFILE}
true
}
if [ -f ${LOGFILE} ]; then
rm ${LOGFILE}
fi
if [ -f ${SESSION_ENV_FILE} ]; then
# reset the session environment file
log "Removing session environment file"
rm ${SESSION_ENV_FILE}
log "Touching session environment file"
touch ${SESSION_ENV_FILE}
fi
# import selected session environment variables into the systemd user
# environment
log "Importing existing environment variables"
for ENV_VAR in DESKTOP_SESSION \
DISPLAY \
XAUTHORITY \
SESSION_MANAGER \
XDG_CONFIG_DIRS \
XDG_DATA_DIRS \
XDG_RUNTIME_DIR \
XDG_SEAT_PATH \
XDG_SEAT \
XDG_SESSION_CLASS \
XDG_SESSION_ID \
XDG_SESSION_PATH \
XDG_SESSION_TYPE \
XDG_VTNR;
do
systemctl --user import-environment ${ENV_VAR}
done
# set selected session environment variables in the systemd user environment
log "Setting new environment variables"
for KEY_VAL in KDE_FULL_SESSION=true \
XDG_CURRENT_DESKTOP=KDE \
XDG_SESSION_DESKTOP=KDE \
KDE_SESSION_VERSION=5;
do
systemctl --user set-environment ${KEY_VAL}
done
export QT_MESSAGE_PATTERN='%{category} %{function}: %{message}'
systemctl --user import-environment QT_MESSAGE_PATTERN
# if plasma-workspace.target is not enabled bail out
log "Checking availability of plasma-workspace.target"
systemctl --user is-enabled plasma-workspace.target || { xmessage "Please enable plasma-workspace.target"; exit 1; }
log "Starting plasma-workspace.target"
systemctl --user start plasma-workspace.target
# this is a hackish workaround to solve a yet unclear behaviour:
# after starting the plasma-workspace.target, one would expect all dependent services
# to be starting/started and therefore to be returned as "true" by "systemctl is-active",
# but it seems that's not the case and ksmserver.service will only be reported as active
# once it fully started.
# So before we start watching the state of ksmserver.service, we'll give it some time to
# fully start
# I'm aware this is a non-deterministic approach and a hack, but for now this will work
# until the 'is-active' issue has been solved
log "Sleeping for 25 seconds"
sleep 25
# now we're waiting for ksmserver.service to stop
# once ksmserver.service stopped, we'll stop the plasma-workspace.target as well
log "Waiting for ksmserver.service to terminate"
while systemctl --user is-active ksmserver.service;
do
log "ksmserver.service is still running"
# not really nice, but still better than blindly waiting for 'read' as before :)
# it would be even better if there was something like 'systemctl wait-for stop ksmserver.service'
# to prevent having to spawn a new 'sleep' every 5 seconds, but just as the hack above, this will
# work for now
sleep 5
done
log "ksmserver.service stopped running"
exit 0