Solved:How to install kodi as a service?

My os info:

uname -a
Linux debian 5.10.0-23-amd64 #1 SMP Debian 5.10.179-2 (2023-07-14) x86_64 GNU/Linux

Hass info:

hass --version
2023.7.2

I have already installed kodi.

sudo apt install kodi

Now to make it a service according to [GUIDE] Install HASSIO and KODI on same Raspberry Pi

sudo vim  /etc/systemd/system/kodi.service
[Unit]
Description = Kodi Media Center
After = remote-fs.target network-online.target
Wants = network-online.target
[Service]
User = pi
Group = pi
Type = simple
ExecStart = /usr/bin/kodi-standalone
Restart = on-abort
RestartSec = 5
[Install]
WantedBy = multi-user.target

To start it

sudo systemctl start kodi
sudo systemctl status kodi
● kodi.service - Kodi Media Center
     Loaded: loaded (/etc/systemd/system/kodi.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Mon 2023-08-07 20:13:01 HKT; 26s ago
    Process: 45054 ExecStart=/usr/bin/kodi-standalone (code=exited, status=217/USER)
   Main PID: 45054 (code=exited, status=217/USER)
        CPU: 1ms

Aug 07 20:13:01 debian systemd[1]: Started Kodi Media Center.
Aug 07 20:13:01 debian systemd[45054]: kodi.service: Failed to determine user credentials: No such process
Aug 07 20:13:01 debian systemd[45054]: kodi.service: Failed at step USER spawning /usr/bin/kodi-standalone: No such process
Aug 07 20:13:01 debian systemd[1]: kodi.service: Main process exited, code=exited, status=217/USER
Aug 07 20:13:01 debian systemd[1]: kodi.service: Failed with result 'exit-code'.

How to fix it?

What install home assistant type are you running?

Installed it in virtual environment.

    sudo apt-get update
    sudo apt-get upgrade -y
    sudo apt-get install -y python3 python3-dev python3-venv python3-pip   \
         bluez libffi-dev libssl-dev libjpeg-dev zlib1g-dev autoconf       \
         build-essential libopenjp2-7 libtiff5 libturbojpeg0-dev tzdata    \
         ffmpeg liblapack3 liblapack-dev libatlas-base-dev

    sudo useradd -rm homeassistant
    sudo mkdir /srv/homeassistant
    sudo chown homeassistant:homeassistant /srv/homeassistant
    sudo -u homeassistant -H -s
    cd /srv/homeassistant
    python3.11 -m venv .
    source bin/activate
    python3 -m pip install wheel
    pip3.11 install homeassistant==2023.7.3
    pip3.11 install git+https://github.com/boto/botocore

Start it:

hass

LOL you can’t run Kodi as a systemd system service. It has to be a session autostart program, which appears as soon as you log in.