5

I start my window manager with systemd service units (following this tutorial). After I log in at tty1 the following gets executed in .zlogin (I'm using ZSH as a login shell):

if [[ -z "$DISPLAY" && $(tty) = /dev/tty1 ]]; then
  nohup systemd --user > ~/.xlog 2>&1 &
  disown %2
  logout
fi

Systemd starts a X server, a window manager, ... through service units.

The problem starts when I want to logout.
Should I simply execute kill $MANAGERPID to kill the systemd daemon ?
It seems much cleaner to do a loginctl terminate-session $XDG_SESSION_ID but this command requires further privileges.

Here's the question: What is the preferred way to log out with the setup described above ?

3

This is what I use to log out from using xmonad (after using wmctrl to close all open windows):

session=`loginctl session-status | head -n 1 | awk '{print $1}'`
loginctl terminate-session $session

I'm not sure why you need further privileges for loginctl terminate-session - this works for me without any such need.

Also note that there are different ways to obtain the session ID. In this example I simply take it directly from loginctl itself. There's also $XDG_SESSION_ID (as you wrote) and /proc/self/sessionid.

  • loginctl session-status | awk 'NR==1{print $1}'... – jasonwryan May 9 '17 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.