Shutdown/restart & mounting drives without display manager

Quite a long time ago I became unable to shutdown or restart my system from the Xfce logout dialog. I also couldn’t mount USB flash drives. Recently I tackled this issue which seems to be related to systemd + PolicyKit + Consolekit and found a solution. As written there I have created two files:

/etc/polkit-1/localauthority/50-local.d/consolekit.pkla:

[restart]
Identity=unix-user:<username>
Action=org.freedesktop.consolekit.system.restart
ResultAny=yes

[stop]
Identity=unix-user:<username>
Action=org.freedesktop.consolekit.system.stop
ResultAny=yes

/etc/polkit-1/localauthority/50-local.d/udisks.pkla:

[udisks]
Identity=unix-user:<username>
Action=org.freedesktop.udisks.*
ResultAny=yes

This finally gave me back full control over my system even though I didn’t bother digging deeper into the involved concepts.

After a recent update I once again lost these capabilities again though and had to give it another spin. Once again I found a solution and adapted my snippet for automatically launching the X server:

# Autostart X if not running
if [[ -z "$DISPLAY" ]] && [[ $(tty) = /dev/tty1 ]]; then
  startx -- vt1
fi