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, debianmultimedia.org install). Rename it to mythbackend.real. Create a file in the same directory called mythbackend.run with the following contents:

#!/bin/bash
myvar=0
while [ $myvar -ne 10 ]
do
echo $myvar
mythbackend.real
myvar=$(( $myvar + 1 ))
done


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:

#!/bin/bash
mythbackend.run&


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

No comments: