v17 Occasional Segfault on launch Ubuntu 16.04 LTS Server
#1
I run this crontab daily at 330 am to keep  things fresh.
Code:
30 3 * * *        /usr/bin/kodi-send --action RestartApp

Last night kodi never came back up. I woke up to a black screen on my living room tv. 

I need to be able to restart Kodi on a schedule as it is currently the only way to fix an audio stutter that occurs after a few days of uptime.  I have posted logs on this with no replies, which tells me people here see nothing wrong in the log. I am trying to make this an appliance. If I have to manually intervene when the script fails, then it defeats the purpose of the call in the first place.

How can I make sure this fires and works every single time?
Reply
#2
Start kodi as a service, and then kill it from cron.

I have an appliance-like box where Kodi is really the only thing running on it (Ubuntu 14.04 minimal) so it's started from /etc/init/xbmc.conf
Code:
cat xbmc.conf
# xbmc standalone service

# starts XBMC on startup by using xinit.
# will try to auto respawn for 5 mins if it crashes
# launches xbmc in the "standalone mode" with no xcursor (cursor in xbmc still works)
# by default runs as xbmc, to change edit below.
env USER=xbmc

description     "XBMC standalone service"
author          "Matt Filetto"

start on (started dbus and started mountall and net-device-up IFACE!=lo)
stop on runlevel [016]

# tell upstart to respawn the process if abnormal exit
respawn
respawn limit 10 5

# nice level
limit nice 21 21

script
  exec su -c "xinit /usr/bin/xbmc --standalone -- -bs -nocursor :0" $USER
end script

Really ought to update that to Kodi as it's starting v16 these days and I think that script goes back to v12.  In any case, it works fine for me and a simple 'killall -9 kodi.bin' will kill it and respawn it.  I have tried SIGTERM rather than SIGKILL, but (for me at any rate) that doesn't work.

The reason I know it works is that I had a similar problem with Kodi locking up after a few days whereby it would be playing internet radio but was not responsive to either the remote (lirc) or to the json interface.  The web interface was generally accessible but this meant either going back downstairs (it's in our bedroom) or faffing around connecting with a phone and then hoping it worked.  Now, it is restarted every morning at 6.30AM and it never locks up.
Learning Linux the hard way !!
Reply
#3
Read and taken to heart. I'm trying not to run standalone as they say it isn't supported. I had posted a script in another thread but it also had the same problem. This is where I ended up at when you said run it as a service. This restarts the whole lot until Kodi is running properly. Using Lightdm to autostart openbox, which autostarts Kodi.
Code:
for seconds in 30 20 10 ; do
  kodi-send --action "Notification(kodi restart in ${seconds} seconds,standby!)"
  sleep 10
done
kodi-send --action RestartApp
sleep 30
if ! pgrep kodi ; then
  until pgrep kodi ; do
    for process in $(pgrep openbox) ; do
      kill "$process"
    done
    sleep 10
    systemctl restart lightdm
    sleep 30
  done
fi
Reply
#4
Nevermind. Above script still has same problem of Kodi occasionally not starting. Found it black screened this morning. Gonna put it on my calendar to manually restart every other day for now and see how it goes. I'd still like to know why it doesn't work every time though.

I'm sure a service file standalone would work but I have a PXE boot media center in the bedroom where that isn't an option so I'm stuck either way.
Reply
#5
(2018-09-18, 01:29)jmgibson1981 Wrote: Nevermind. Above script still has same problem of Kodi occasionally not starting. Found it black screened this morning. Gonna put it on my calendar to manually restart every other day for now and see how it goes. I'd still like to know why it doesn't work every time though.

I'm sure a service file standalone would work but I have a PXE boot media center in the bedroom where that isn't an option so I'm stuck either way.
 Can't you rebuild the image you're booting from with the service included ?.  Also, it's not like you need a big HDD to boot and run Kodi off.  My bedroom HTPC uses an 80G drive but if I was rebuilding it, I'd use an SSD for the speed and lack of noise - the HTPC is fanless and even with an HDD, doesn't really make much noise at all.

No idea why it doesn't work properly every time, but, if kodi-send uses the same interface as Kore, then that's possibly the reason.  I have had instances where that interface has become locked (after a timeout) and the ONLY way to get control of Kodi back was via the web interface.  I haven't however, looked at that code to see how it sends the 'back' command to Kodi, which then allows my phone to re-connect.

Anyway, the service method with cron to kill works 100% reliably for me.

Code:
xbmc@ruby:~$ uptime
 07:57:28 up 38 days,  7:22,  1 user,  load average: 0.12, 0.16, 0.20
  Kodi is running 24/7 on that box.
Learning Linux the hard way !!
Reply
#6
I haven't delved to much into custom services on my LTSP pxe machines. Right now I just have it's LDM display manager autologging into Openbox, which in turn auto starts Kodi. However I'm finding that the script I for it which runs daily at 3:30 is working every single time. I haven't had an issue yet.

Wondering if it's something else on my master server / htpc in the living room that is causing it to fail occasionally. Not sure where to start. Will be examining the logs.
Reply
#7
As an offshoot of this, (and partly for me to refer back to) I upgraded from 14.04 to 16.04 on that machine yesterday in preparation for putting V18 on it.  As usual, that broke stuff Angry   Biggest issue was I couldn't figure out how to get systemd to auto-login on a tty  and start X without a window manager.  I spent several fruitless hours attempting it, considered installing a WM, but then decided to sack off systemd and go back to using upstart, which works perfectly again with no WM or DE needed. Had an issue with init eating all the cpu and memory and discovered I needed to add "console none" to the init script as that's no longer the default. Now it appears all back to how it should be so I'll see if I can get another 4 years out of it before needing to upgrade it !!

It also broke my lirc config when the upgrade kindly re-wrote the conf files for me but managed to leave the custom network stuff alone.
Learning Linux the hard way !!
Reply
#8
https://paste.ee/p/7BHsl

Just got this log on a system reboot. I watched Kodi launch, then it died. This was in the /var/log/syslog

Code:
jason@megalith:~$ grep kodi.bin /var/log/syslog
Sep 19 07:34:53 megalith kernel: [   42.543032] kodi.bin[2447]: segfault at 19 ip 00007f918a07b512 sp 00007f91730dc010 error 4 in libc-2.23.so[7f9189ff7000+1c0000]

This may be the problem I've had with Kodi not launching. Rather it is launching but immediately segfaulting on occasion.
Reply
#9
Firstly, good catch !!   You're probably right that it _is_ launching but then segfaulting which could deceive you into thinking it isn't launching at all.  Error 4 is "a user-mode read resulting in no page being found".  Probably need a backtrace from gdb to pin it down further, but from the log you posted, EPG data would seem a likely candidate.  More help than that with diagnosing it, I'm afraid I cannot give.

However, as it seems that you can't launch Kodi as a service and thus have it auto respawn if it crashed, I wondered if you ran something like this from cron if it would help ?

Code:
#!/bin/bash
pidof  kodi-x11 >/dev/null
if [[ $? -ne 0 ]] ; then
        echo "Restarting Kodi    $(date)"  >> /path/to/logfile # if you want to monitor any crashes
        /usr/local/bin/kodi &
fi

Change kodi-x11 to kodi.bin for earlier versions.  If it crashes or you kill it, it should restart it.
Just a thought.
Learning Linux the hard way !!
Reply
#10
For the moment I'm trying to write a script that watches for a segfault and restarts until successful. Would be a workaround for the time being. Still figuring how I will do that.

I'm understanding why the systemd service worked now and I never had the problem. It would just respawn itself until it ran. I never knew this was happening until trying to run it in a supported way.
Reply
#11
(2018-09-19, 23:27)jmgibson1981 Wrote: For the moment I'm trying to write a script that watches for a segfault and restarts until successful. Would be a workaround for the time being. Still figuring how I will do that.

I'm understanding why the systemd service worked now and I never had the problem. It would just respawn itself until it ran. I never knew this was happening until trying to run it in a supported way.
 Yeah, either systemd or upstart will respawn on a crash until successful (or it hits a limit you may have set). 

If you use the script I posted above and call it every minute from cron, it will check to see if kodi is running or not.  If it is, it just exits.  If not, it'll start it and check after whatever interval you set in cron. If it's crashed or whatever by then, it'll start it again.  This will repeat until it starts successfully.  You could write some logic to count how many starts you have and bail out if it tries twenty times or something, but I'm assuming that generally, Kodi is well behaved and is more likely than not to start correctly.   No need to check for segfaults or whatever may have caused the crash.  If gdb is installed and you launch kodi via the supplied script (/usr/local/bin/kodi), you'll get a crashlog report anyway, but if you want it like my bedroom machine (as appliance-like as possible) then the issue is having kodi running, not what caused it to crash.

Of course, in an ideal world, it wouldn't crash but ........

Running as a service is a better way to do it, as the OS takes care of it but the above script does exactly the same thing in userland.

NOTE : Moving from V16 (possibly 17, dunno because never installed it) to 18 changes the name of the binary to check for.  I forgot to update my restart script yesterday to look for 'kodi-x11' instead of 'kodi.bin', so nothing got restarted this morning.  Decided to let 18 just run and see if it suffers the same lockup issues as 16 did.  If it does, I will amend the scripts accordingly.  If not, I'll disable logging on it and get cron to restart it once per week.
Learning Linux the hard way !!
Reply
#12
Update. Server uptime has hit 30 days and keeps going. I'm still learning bash and I hadn't got around to figuring out your script there, at least the $? part. However your script did give me an idea for my daily restart script.
Code:
kodi_start() {
                                for seconds in 30 20 10 ; do
                                        kodi-send --action "Notification(kodi restart in ${seconds} seconds,standby!)"
                                        sleep 10
                                done
                                for process in $(pgrep openbox) ; do
                                        kill "$process"
                                done
                                sleep 2
                                systemctl restart lightdm
                                sleep 30
                        }
                        kodi_start
                        until pidof kodi.bin ; do
                                kodi_start
                        done

Haven't had an issue when running this script in awhile now. Before changing to this I would have to manually restart once or twice a week to get it loaded properly in the mornings when I checked it. I will continue to research when I get time to do so. Maybe I can find the main issue. A few days ago my Mythtv-backend service segfaulted and restarted itself middle of me watching the local news. Something else to chase I guess.

Quote: Can't you rebuild the image you're booting from with the service included ?.  Also, it's not like you need a big HDD to boot and run Kodi off.  My bedroom HTPC uses an 80G drive but if I was rebuilding it, I'd use an SSD for the speed and lack of noise - the HTPC is fanless and even with an HDD, doesn't really make much noise at all.

I can I suppose. I did the pxe boot thing more to find out if I could than anything. That and it saved me the cost of a drive. My original deployment involved 4-5 pxe machines. 300 bucks or so on hard drives / ssds saved + I can manage them all from one central point. They are nothing more than kodi boxes so it seemed a good idea. I'm finding some limitations though admittedly.
Reply
#13
So, $? is the status of the last executed command, in this case, pidof  kodi-x11 >/dev/null. If kodi is running, that will return it's pid and then throw it away because we don't need it, we just need to know if it exists or not. If it does, pidof will exit with a status of 0 (zero), if it doesn't (on my machine anyway) it will exit with a status of 1.  We get that status via $? and check to see if it's not zero. If it's not, we restart Kodi, if it is zero, we just exit (because kodi is running).
Quote:I can I suppose. I did the pxe boot thing more to find out if I could than anything. That and it saved me the cost of a drive. My original deployment involved 4-5 pxe machines. 300 bucks or so on hard drives / ssds saved + I can manage them all from one central point. They are nothing more than kodi boxes so it seemed a good idea. I'm finding some limitations though admittedly.

Haha, I originally set up the bedroom PC to pxe boot for a similar reason (to see if I could!!) but to be honest, it was quite a pain to get working properly and apart from saving a drive, didn't really give me any benefits over the way it is now.  The drive was just an old one I had laying around but it does the job.  I manage all my boxes from one central point anyway as only one of them has a proper GUI to do things in so they are all administered over ssh.  Libraries are MySQL and shared between machines as is the main instance's userdata directory (adding a favourite replicates over all instances this way).  It took me a while to get it all working how I wanted it, and although I occasionally tweak things, it's pretty much 'right' now.

It has to be, as Kodi is the only means of watching live TV/listening to radio etc etc in all rooms but one.
Learning Linux the hard way !!
Reply
#14
Quote:Haha, I originally set up the bedroom PC to pxe boot for a similar reason (to see if I could!!) but to be honest, it was quite a pain to get working properly and apart from saving a drive, didn't really give me any benefits over the way it is now.  The drive was just an old one I had laying around but it does the job.  I manage all my boxes from one central point anyway as only one of them has a proper GUI to do things in so they are all administered over ssh.  Libraries are MySQL and shared between machines as is the main instance's 
userdata
 directory (adding a favourite replicates over all instances this way).  It took me a while to get it all working how I wanted it, and although I occasionally tweak things, it's pretty much 'right' now.

It has to be, as Kodi is the only means of watching live TV/listening to radio etc etc in all rooms but one.

Yes mine is similar. Main htpc in living room holds the mariadb database. I have a central playlists folder shared via nfs. Only thing I don't duplicate is the .kodi/userdata folder as with a guest room here it has it's own advancedsettings.xml for it's own database stuff. I do the pxe boot with LTSP. It just intrigued me. The other benefit to doing pxe boot that I like is I know *nix systems don't handle sudden power cuts well. This way as it's a read only system I don't have to worry about keeping a ups at each location.
Reply
#15
Think I've nailed it. Thank you much for your suggestion. After playing around for an hour or so, restarting Kodi, killing processes and what not I've finally cracked what I need to run with Openbox.

Kodi stop script

Code:
for seconds in 30 20 10 ; do
  kodi-send --action "Notification(kodi restart in ${seconds} seconds,standby!)"
  sleep 10
done
for app in kodi openbox ; do
  for process in $(pgrep "$app") ; do
    kill "$process"
  done
done
sleep 2
systemctl restart lightdm

Kodi restart, called from Openbox autostart

Code:
while true ; do
  pidof kodi.bin > /dev/null
  if [[ "$?" -ne 0 ]] ; then
    /usr/bin/kodi &
  fi
  sleep 30
done
Reply

Logout Mark Read Team Forum Stats Members Help
Occasional Segfault on launch Ubuntu 16.04 LTS Server0