This weekend I’m oncall for work, so between me and my girlfriend we decided to take a few chores off our to-do lists. One of the things for me was to run the now episodic maintenance over the software and firmware of the devices we own at home. I call it episodic, because I no longer spend every evening looking after servers, whether at home or remote, but rather look at them when I need to.
In this case, I honestly forgot when it was the last time that I ran updates on the HTPC I use for Kodi and for the UniFi controller software. And that meant that after the full update I reached the now not uncommon situation that Kodi refused to start at boot. Or even when SSH’ing into the machine and starting the service by hand.
The error message, for ease of Googling, is:
[ 2092.606] (EE) Fatal server error: [ 2092.606] (EE) xf86OpenConsole: Cannot open virtual console 7 (Permission denied)
What happens in this case is that the method I have been using to boot-to-Kodi was to use a systemd unit lifted from Arch Linux, that started a new session, X11, and Kodi all at once. This has stopped working now, because Xorg no longer can access the TTY, because systemd does not think it should access the console.
There supposedly are ways to convince systemd that it should let the user run X11 without so much fluff, but after an hour trying a number of different combinations I was not getting anywhere. I finally found one way to do it, and that’s what I’m documenting here: use lightdm.
I have found a number of different blog posts out there that try to describe how to do this, but none of them appear to apply directly to Gentoo.
These are the packages that would be merged, in order: Calculating dependencies... done! [ebuild R ] x11-misc/lightdm-1.26.0-r1::gentoo USE="introspection -audit -gnome -gtk -qt5 -vala" 0 KiB
You don’t need Gtk, Qt or GNOME support for lightdm to work. But if you install it this way (which I’m surprised is allowed, even by Gentoo) it will fail to start! To configure what you need, you would have to manually write this to /etc/lightdm/lightdm.conf
:
[Seat:*] autologin-user=xbmc user-session=kodi session-wrapper=/etc/lightdm/Xsession
In this case, my user is called xbmc
(this HTPC was set up well before the rename), and this effectively turns lightdm into a bridge from systemd to Kodi. The kodi
session is installed by the media-tv/kodi
package, so there’s no other configuration needed. It just… worked.
I know that some people would find the ability to do this kind of customization via “simple” text files empowering. For me it’s just a huge waste of time, and I’m not sure why there isn’t just an obvious way for systemd and Kodi to get along. I would hope somebody builds one in the future, but for now I guess I’ll leave with that.
I am using this:
[Service]
Type=idle
Restart=always
RestartSec=15
User=xbmc
Group=xbmc
PAMName=login
ExecStart=/usr/local/bin/kodi-start
ExecStop=/usr/local/bin/kodi-stop
TTYPath=/dev/tty1
StandardInput=tty
StandardOutput=journal
And in kodi-start, there is:
tty=$(tty)
tty=${tty#/dev/tty}
export AE_SINK=ALSA
exec /usr/bin/xinit /usr/bin/kodi-standalone — :0 -nolisten tcp vt$tty