Autorestart
Added by Anton Bungin almost 11 years ago
Can anyone help me with a script to restart TVHeadend right upon failure?
From time to time it crashes on my Ubuntu 12.04 and I have to start it manually in the console.
Replies (21)
RE: Autorestart - Added by Adam Sutton almost 11 years ago
really? it's an upstart job that should be auto restarted, certainly mine has auto-restarted in the past on crash. Though admittedly its been months since mine crashed, though plenty of chance for that now I've just updated to master.
Adam
RE: Autorestart - Added by Anton Bungin almost 11 years ago
I built the last github version manually several weeks ago and it crashes 2-3 times a week and never starts again.
RE: Autorestart - Added by Adam Sutton almost 11 years ago
Ah, well master is a whole other ball game And yes a few crashes wouldn't surprise me.
How are you starting it? upstart job or manual?
Adam
RE: Autorestart - Added by Anton Bungin almost 11 years ago
Manually in terminal.
"sudo /etc/init.d/tvheadend" is not working, so just "tvheadend"
RE: Autorestart - Added by Adam Sutton almost 11 years ago
Ah, well if you're running manually then no you won't get any auto-restarting. However if you install a package and run from upstart then that will, by default, auto restart.
Adam
RE: Autorestart - Added by Anton Bungin almost 11 years ago
I maybe misunderstood you.
TVheadend starts automatically with PC starting (Ubuntu option to start programms).
That's me who starts TVH manually upon crash.
What do you mean saying 'upstart'?
RE: Autorestart - Added by Adam Sutton almost 11 years ago
Upstart is Ubuntu's job control mechanism (replacement for sysvinit) or starting services. It's how TVH is normally started if you installed one of the pre-packaged deb's. Upstart provides the option, which TVH uses, to have services automatically restart should they crash.
This was definitely working the last time my system crashed, or at least I think it was (it's been over a year), and nothing should have changed in that area. I'm using my system atm so can't force it to crash to test. but I'll try and remember to check later.
Adam
RE: Autorestart - Added by Anton Bungin almost 11 years ago
Can't you "killall -9 tvheadend" to emulate my problem?
I've been using Ubuntu not more than 2 years, so I'm still not an expert in Linux, but before that on Windows I made a script using nnCron to check if the process (Mediaportal TVServer) existed and tested it simply by killing the process.
But probably on NIX it's different.
RE: Autorestart - Added by Anton Bungin almost 11 years ago
Ooops!
I always forget that only crazy people like me have 5 PCs at home.
Sorry!
OK! I'll be waiting for the results.
Thanks in advance
RE: Autorestart - Added by Anton Bungin almost 11 years ago
Thanks for the answer.
But Monit works out of the box only when pidfiles are generated.
TVHeadend (and XBMC) have no pidfiles.
Writing scripts may be difficult for regular users.
RE: Autorestart - Added by Adam Sutton almost 11 years ago
A few things:
1. I've had the misfortune to use monit for several years (at work, never at home). It's used to monitor all processes on our Radio platform. I've had several years of fun working around its many foibles. Every time one of our engineers suggests we upgrade to the latest version it sends shivers down my spine what new wonderful workaround will be needed to keep things working. Not really what you want for a software watchdog system, suffice to say when I needed a simple SW watchdog for a small emedded project I wrote my own (and one day I'll junk monit and do the same for this system). But apart from all that its a lovely idea!
2. Tvheadend does provide a PID file, check /var/run/tvheadend.pid. Obviously the generation of this does depend somewhat on how you start TVH, you need to start in daemon mode.
3. AS previously pointed out, and apologies if this is not relevant (I've not read the full thread). If you're running a standard package on Ubuntu, that will be started using upstart which has its own monitoring built in and will auto restart on crash (but TVH never crashes ofc!).
Adam
RE: Autorestart - Added by Anton Bungin almost 11 years ago
Thanks, Adam.
Just few things.
2. Hmmm... I looked in /var/run/, but didn't find the pidfile. TVH is automatically started by Ubuntu ("Start up appliations" menu > "Add Startup Program").
3. Unfortunately, TVH crashes from time to time. Too sad if I'm away from home and can't start TVH through console. That's why I asked about any way of restarting the app.
RE: Autorestart - Added by Adam Sutton almost 11 years ago
Anton,
3 was a joke Though have to admit I think my 3.4 system ran about a year without a crash (admittedly it probably got restarted a handful of times during that period due to my messing with / upgrading the hardware). Since switching to master before Xmas, I've had 1 crash (not nice). But problem is many of the crashes can depend on very particular setup's so mine not crashing is certainly not a suggestion that it never crashes. It's more an indication that anything that does cause my system to crash (during dev) is always fixed
2 sounds wrong. By default all you should need to do is apt-get install tvheadend. It will automatically enable the service (in upstart). It should generate a PID file, mine certainly does. And it should auto-restart, which on the 1 occasion mine crashed over Xmas (that bug has been fixed ) it certainly did.
So really not sure what's happened with your system
Adam
RE: Autorestart - Added by Anton Bungin almost 11 years ago
I'll check the things this evening on coming back home.
To be frank, TVH was installed on June.
I just upgraded from the latest stable version to the latest GIT before the New Year.
RE: Autorestart - Added by Anton Bungin almost 11 years ago
I've just looked at my TVH.
Version: HTS Tvheadend 3.5.246~gd600a40
Ubuntu starting command: /usr/local/bin/tvheadend
No pidfile in /var/run
I will look the logfile if TVH crashes to post it here.
RE: Autorestart - Added by Adam Sutton almost 11 years ago
If you start just like that, then:
1. Why are you not installing a package?
2. If you start with no options, the process will not daemonise and therefore will not create a PID file.
3. What happens if you a) install the package and b) run "start tvheadend"
Adam
RE: Autorestart - Added by Anton Bungin almost 11 years ago
1. I failed to patch the stable version for working with BISS and manually built github sources.
2. Do you meen the "-f" option?
Do I need to type Ubuntu starting command like "/usr/local/bin/tvheadend -f"?
I killed TVH in console and typed "tvheadend -f" and got "[ ALERT] START: setgid() failed, do you have permission?".
I think, something is wrong with the permissions granted to user.
Typing "tvheadend" works perfectly for me.
If I type "sudo tvheadend -f" TVH starts, but I can't access Web GUI.
How can I fix it?
3. It will be too painful for my family to play such games right now with the dedicated server with 4 tuners.
A bit later
RE: Autorestart - Added by Adam Sutton almost 11 years ago
Build and install a package, job done. Please read Packaging. Doing manual installation is always fraught problems as you remove all the effort made to ensure things start properly/cleanly etc...
Adam
RE: Autorestart - Added by Anton Bungin almost 11 years ago
Great help!
Now I see my mistake following buiding instruction from some XBMC forum.
After making and installing *.deb from github right as you wrote on test PC I see pidfile and folder /home/hts (in my case I have only /home/(name_of_user) for TVH).
Just one more question left - what exact starting command should be for Ubuntu - "/usr/local/bin/tvheadend -f"?