Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use Gnome Do as a launcher for most things. I have it set to run on login and for most of the time it sits in the background waiting for me to mash a keyboard shortcut. About once a week, it falls over. I mash my shortcut and nothing happens. I have to re-launch it.

It's not amazingly annoying but I would like to know if there are any good ways to make sure desktop applications keep running forever. If they die, they get re-launched (perhaps with a crash timeout so if it crashes on load, it doesn't keep trying to run it over and over and over again).

I know some applications do this. On Gnome2, if gnome-panel isn't running, the system forces it to load. Is there a simple way of tapping into this logic (of course, without breaking Gnome).

I don't want this question to be too specific to Gnome Do or even Gnome because I have more than one application for a solution (I run Boxee on an OpenBox desktop on our media centre) and I'm sure other people all have their own issues they'd like to fix through something like this.

share|improve this question
up vote 2 down vote accepted

Another not so elegant solution:



while true; do
    start=$(date +%s)
    stop=$(date +%s)
    if [[ ret_val -eq 0 ]]; then
        # normal exit, quit
        exit 0
        # abnormal exit, check runtime. if < threshold quit
        runtime=$((stop - start))
        if [[ runtime -lt $threshold ]]; then
            echo "crash on start"
            exit 1       

This will restart, if the program (first argument) exits with a return code != 0 and ran at least threshold seconds.

I tried to create an Upstart job using the respawn and respawn limit options, but that somehow failed.

share|improve this answer
I guess it's a bit complicated to add a correct $DISPLAY value to the upstart job... – JanC Jun 6 '11 at 16:55
Actually, it should be possible if you always start the job from inside X, and pass $DISPLAY as a parameter. – JanC Jun 6 '11 at 16:56
@JanC I tried and I failed. ;-) – htorque Jun 6 '11 at 21:30

A simple, if not particularly elegant, solution would be to launch the application from a script on loop, such that


while true
    gnome-do # or application of choice
    sleep 10 # prevent super-spawn rates

Although this may have to be checked per application, as bash does not halt for all programs...

You could also adapt it to check for errorcodes, so it only respawns if the application crashes, rather than closed.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.