Automatically restart Kodi when it crashes (while using a window manager)

  Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
thos Offline
Member
Posts: 69
Joined: Dec 2011
Reputation: 1
Post: #1
Hi all,
I'm running Kodi on a server in my house to do database management and content scanning, with other nodes then around the house linking to this db.

Problem being that Kodi crashes from time to time, and sometimes my content isnt being scanned or updated.

The server runs Ubuntu 12.04, and I also use the desktop from time to time.
To automatically start Kodi, I have used a user who gets automatically logged in, then a ~/.config/autostart entry that runs start a script which just loops 'while /usr/bin/kodi; do; done' loop.

Problem being that sometimes when it crashes Ubuntu seems to kill my loop script, and I need to log out and log in again to restart it.

So, my question - how do I keep Kodi running, and restarting after crashes, while also using a desktop manager?

Thanks,
Tom
find quote
teeedubb Offline
Donor
Posts: 3,374
Joined: Mar 2010
Reputation: 97
Location: Down Under
Post: #2
Make a script to ping kodis jsonrpc server - if there is no response kill and restart kodi.
find quote
liebezeit Offline
Junior Member
Posts: 25
Joined: Feb 2015
Reputation: 0
Post: #3
(2015-11-11 23:46)teeedubb Wrote:  Make a script to ping kodis jsonrpc server - if there is no response kill and restart kodi.

Has anyone done this, and perhaps can share their code?
find quote
fatalkill3r Offline
Junior Member
Posts: 20
Joined: Jul 2015
Reputation: 0
Post: #4
Hi

You can try this below systemd script -

Create a service file - /lib/systemd/system/kodi.service

-------------------------------------

[Unit]
Description = start Kodi
Requires = lightdm.service
PartOf = lightdm.service

[Service]
User = xbmc
Group = xbmc
Environment = DISPLAY=:0.0
ExecStartPre = /bin/sleep 1
ExecStart = /usr/bin/kodi
ExecStop = /usr/bin/pkill -9 kodi.bin
Restart = on-failure

[Install]
WantedBy = multi-user.target
find quote
Segfault Offline
Member
Posts: 80
Joined: Dec 2009
Reputation: 0
Location: Saint Amant, Acadiana
Post: #5
I do not use systemd, if I need to keep something alive I use daemontools.
find quote
liebezeit Offline
Junior Member
Posts: 25
Joined: Feb 2015
Reputation: 0
Post: #6
(2017-07-15 18:07)fatalkill3r Wrote:  Hi

You can try this below systemd script -

Create a service file - /lib/systemd/system/kodi.service

-------------------------------------

[Unit]
Description = start Kodi
Requires = lightdm.service
PartOf = lightdm.service

[Service]
User = xbmc
Group = xbmc
Environment = DISPLAY=:0.0
ExecStartPre = /bin/sleep 1
ExecStart = /usr/bin/kodi
ExecStop = /usr/bin/pkill -9 kodi.bin
Restart = on-failure

[Install]
WantedBy = multi-user.target

Thanks fatalkill3r. I am using xfce4 (on standard Xubuntu) though. Can it be modified? My understanding is that it is hard to use init programs to run things in an existing GUI context.
find quote
DaVu Offline
Team-Kodi Member
Posts: 2,717
Joined: Jan 2011
Reputation: 51
Location: Germany
Post: #7
Probably I misunderstood something. But what about using a cronjob which runs a written bash- or python-script every now and then. The script could handle the ping to kodis webserver and kill and restart Kodi if needed.
find quote
liebezeit Offline
Junior Member
Posts: 25
Joined: Feb 2015
Reputation: 0
Post: #8
(2017-07-18 09:34)DaVu Wrote:  Probably I misunderstood something. But what about using a cronjob which runs a written bash- or python-script every now and then. The script could handle the ping to kodis webserver and kill and restart Kodi if needed.

The ping would be better (how to do it?) but for now I'm just doing this in my xfce4 startup script:
Code:
{
        while true; do
                if [ ! `pgrep kodi` ] ; then
                        kodi
                fi
                sleep 30
        done
}&
(This post was last modified: 2017-07-18 12:38 by liebezeit.)
find quote
fatalkill3r Offline
Junior Member
Posts: 20
Joined: Jul 2015
Reputation: 0
Post: #9
upstart or systemd are very good in running programs in UI. Try the script which I have given above. The main ingredient is to set the appropriate DISPLAY env variable. What is your OS based on systemd or upstart ? @liebezeit

For xfce you can replace lighdm with display-manager


[Unit]
Description = start Kodi
Requires = display-manager.service
PartOf = display-manager.service

[Service]
User = xbmc
Group = xbmc
Environment = DISPLAY=:0.0
ExecStartPre = /bin/sleep 1
ExecStart = /usr/bin/kodi
ExecStop = /usr/bin/pkill -9 kodi.bin
Restart = on-failure

[Install]
WantedBy = multi-user.target
find quote