Restart mythbackend when it crashes

Registered by Don Smith

Mythbackend crashes from time to time, it would be nice if it would autorestart.

Blueprint information

Status:
Complete
Approver:
None
Priority:
High
Drafter:
None
Direction:
Needs approval
Assignee:
Dave Walker
Definition:
Approved
Series goal:
Accepted for 9.04
Implementation:
Implemented
Milestone target:
None
Started by
Thomas Mashos
Completed by
Thomas Mashos

Related branches

Sprints

Whiteboard

On my gentoo system I've used monit for this:
prospero ~ # cat /etc/monit.d/mythbackend
check process mythbackend with pidfile /var/run/mythbackend.pid
        start program = "/etc/init.d/mythbackend restart"
        stop program = "/etc/init.d/mythbackend stop"
        if failed host prospero.snafu.local port 6544 then restart
        if 5 restarts within 5 cycles then timeout
Much more flexible than cron if you ask me - have run into situations where myth fails ungracefully (such as failing to listen on 6544 for some reason). Would a mythbuntu-monit package dumping a file in /etc/monit.d/ fit the bill? Debconf script might be needed to make defualt monit install a bit more friendly.

On myPVR we use a script based on http://www.thornsoft.com/Misc/babysit_backend.sh

This gets run out of cron every minute

* * * * * root /usr/local/bin/babysit_backend.sh >>/var/log/mythtv/babysit_backend.log 2>&1

Plus we have a logrotate script to manage and clean up the generated log files.

ALTERNATE

I currently use a simple bash script that is run as a daemon and catches mythbackend failing within a second. It then restarts mythbackend. Furthermore, it check mythfrontend (using telnet) where it is, if it is in LiveTV mode, resets it to LiveTV, so it re-connects to the backend and begins playing livetv again. This process takes about ten seconds, but I also have a small C application (that uses libxosd) that displays "Please Wait: \n Restarting mythbackend" on the screen. It works pretty well - and could be expanded to support multiple front-ends.

I'm not sure why this has no priority: mythbackend dies a lot, it would be nice for something to be in place to catch it by default.

Another possibility is to use upstart to keep it running

upstart-script that has been working for me for about a year:

# mythbackend
#
# This service maintains a mythbackend from the point the mysql-server is
# started until it is shut down again.

start on mysql-start

stop on mysql-stop

respawn
pre-start script
        mkdir -p /var/run/mythtv
        chown -R mythtv /var/run/mythtv
end script

exec su mythtv -c "exec mythbackend --logfile /var/log/mythtv/mythbackend.log --pidfile /var/run/mythtv/mythbackend.pid"

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.