Wednesday, August 29, 2007

Making a program automatically restart

Mythbackend crashes a lot, well at least until you get your configuration stable (which has never happened to me). To create a usable system I wanted to configure myth to restart automatically when it crashes. Here's how I did it. First locate the mythbackend binary, mines in /usr/bin (Debian Lenny, install). Rename it to mythbackend.real. Create a file in the same directory called with the following contents:

while [ $myvar -ne 10 ]
echo $myvar
myvar=$(( $myvar + 1 ))

Make sure it's executable. This script runs our renamed mythbackend ten times in a row (we're only going to restart mythbackend 10times). Then create a file called mythbackend with the following contents:


Again make it executable. This just fires off our script in the backround. So there you go!

No comments: