Linux HOW TO: Minimal Ubuntu 16.04 with Kodi, Steam & EmulationStation
#14
Thanks for the guide, I've followed it and have everything working but on the occasions that Kodi crashes, how does one automatically restart Kodi?

From what I can gather, Kodi is running within LightDM/Openbox so the only way to get Kodi back up is to restart LightDM - but that's beyond the capabilities of my wife if I'm not at home.

When I used a systemd service for Kodi, it would automatically restart on crash, but now I've moved to the LightDM/Openbox method of launching Kodi, I have no idea how to automatically respawn Kodi (or relaunch LightDM) if/when Kodi crashes.

EDIT: I actually managed to work this out myself using a mixture of the kodi-openbox-session binary and the kodi.system systemd script.

If you want Kodi to automatically restart on crash, you will need to;

Code:
Remove (or comment out) the following from /etc/lightdm/lightdm.conf

[Seat:*]
autologin-user=[USER]
autologin-session=kodi-openbox

Disable the lightdm service
Code:
sudo systemctl disable lightdm

Create a new systemd file for kodi
Code:
sudo nano /etc/systemd/system/kodi.system

and enter the following code;
Code:
[Unit]
Description = Kodi Media Center

# if you don't need the MySQL DB backend, this should be sufficient
# After = systemd-user-sessions.service network.target sound.target

# if you need the MySQL DB backend, use this block instead of the previous
After = systemd-user-sessions.service network.target sound.target mysql.service # Remove mysql.service if you are not using the mysql backend for kodi or kodi and mysql are installed on different machines
Wants = mysql.service # Remove this line if you are not using the mysql backend for kodi or kodi and mysql are installed on different machines

[Service]
User = kodi2 # Use your kodi user here
Group = kodi2 # Use your kodi user here
Type = simple
ExecStart = /usr/bin/xinit /usr/bin/dbus-launch --exit-with-session /usr/bin/kodi-openbox-session -- :0 -nolisten tcp vt7
Restart = always # You may need to tweak this option, see https://www.freedesktop.org/software/systemd/man/systemd.service.html for the list of restart options. 'always' pretty much means you cannot exit kodi (gracefully or otherwise) without it restarting. This works for me but my kodi box is dedicated to kodi so I have no need to access X any other way.
RestartSec = 5

[Install]
WantedBy = multi-user.target

Be sure to check the inline comments in the service file above as some options are optional depending upon your setup (i.e. the mysql.service is only relevant IF you are using mysql for kodi AND both kodi and mysql are installed on the same physical machine)

Enable the new kodi service
Code:
sudo systemctl enable kodi.service

Reboot.

Now Kodi will launch (using openbox) via systemd and will relaunch if it crashes.
Reply


Messages In This Thread
RE: HOW TO: Minimal Ubuntu 16.04 with Kodi, Steam & EmulationStation - by DJBenson - 2016-08-08, 17:13
Logout Mark Read Team Forum Stats Members Help
HOW TO: Minimal Ubuntu 16.04 with Kodi, Steam & EmulationStation4