Automatically restart Kodi when it crashes (while using a window manager)
#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
Reply
#2
Make a script to ping kodis jsonrpc server - if there is no response kill and restart kodi.
Reply
#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?
Reply
#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
Reply
#5
I do not use systemd, if I need to keep something alive I use daemontools.
Reply
#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.
Reply
#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.
Reply
#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
}&
Reply
#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
Reply

Logout Mark Read Team Forum Stats Members Help
Automatically restart Kodi when it crashes (while using a window manager)0