This is an updated recipe to install Kodi as a media center on a Debian machine. The service will start automatically at bootstrap and will run under an unprivileged user. A login manager (e.g. LightDM) and a window system (e.g. X11 or Wayland) are not required.
During the Debian install, the tasksel will ask you what environment do you want to install. Deselect all the Debian desktop environments and enable only the SSH server.
Debian packages to install:
It is advisable to run the Kodi media player under an unprivileged user, it is common practice to create the user kodi:
adduser kodi
Add the user to the standard Debian groups, to allow using the hardware (mainly the video and the input groups):
cdrom:x:24:kodi floppy:x:25:kodi audio:x:29:kodi dip:x:30:kodi video:x:44:kodi plugdev:x:46:kodi users:x:100:kodi input:x:102:kodi netdev:x:106:kodi
You can start Kodi from a console virtual terminal just executing kodi-standalone; the script will launch the program without a window manager and the windowing method will be the Generic Buffer Manager (GBM), because we did not install X11 nor Wayland.
There is an obsolete recipe that suggests to install Kodi as a systemd service under the control of the kodi user. Using polkit and acpi-support you should be able also to enable the Power off System and Reboot options in the Kodi exit menu. This seems no longer possibile, because the systemd-logind.service imposes that you have a full terminal session to do things like poweroff the system.
This means that if you run Kodi as a systemd service under the kodi user, you cannot give enough permissions to the process to let the Power off System and Reboot options appear in the Exit menu of Kodi.
So the recommended way to run Kodi as a startup service and as unprivileged user, is to enable the aoutlogin of the kodi user on a virtual terminal of the console and create a .profile script that will launch the kodi-standalone program.
/etc/systemd/system/getty@tty1.service.d/autologin.conf
[Service] ExecStart= ExecStart=-/sbin/agetty --autologin kodi --noclear %I $TERM
The first ExecStart=
line will clear the eventually existing definition inherited by the getty@.service
service. The second ExecStart=-
(with the dash) instructs systemd to execute the program agetty and threat any error as non fatal. The %I placeholder is replaced by the terminal name (tty1 in our example). Finally the environment variable $TERM
is passed to agetty, hopely it is initailized by the system to the correct value.
/home/kodi/.profile
# Start the Kodi media center, only if text console on VT1. if [ -z "$DISPLAY" -a "$(tty)" = "/dev/tty1" ]; then while true; do kodi-standalone echo "Sleeping 15 seconds before restarting Kodi; press Ctrl-C to interrupt..." sleep 15 done fi