How do I automatically restart docky after a crash?

docky crashes from time to time for me. How can I make it restart automatically after it crashed?


Solution 1:

First off, I'm not using docky. But I'm assuming docky is in your $PATH. If not, then specify the full path to the binary.

Here is the awesome use of Bash:

Start off with a file, such as (vim instead of gedit if you want):

  • gedit ~/process_monitor.sh
  • Type the following:

    #!/bin/bash
    
    if [[ -z "$1" ]];then
        echo "ERROR: must specify program"
        exit 1
    fi
    
    while (( 0 == 0 ));do
        $@ &
        pid=`jobs -l | awk '{print $2}'`
        wait $pid
    done
    
  • Save the file.

  • Set the permission:

    chmod a+x ~/process_monitor.sh
    

Now you can run a program like so:

~/process_monitor.sh docky

and it'll launch the program once, and make sure to restart the program if you ever choose to quit it or it chooses to crash.

To add an entry to system startup so it launches the program once you logged in and won't stop until you quit, do this:

  • Go to Unity Dash, type and look for "Startup Applications"
  • Click Add
  • Name: Docky or whatever you like
  • Command: /bin/bash ~/process_monitor.sh docky
  • Comment: Whatever you like

Make sure the new entry is checked. Log back out and in and you see docky all the time.

Solution 2:

This is similar to the process monitor method, using an until loop, but just for docky itself.

Simple script:

until docky; do
  sleep 1
done

Then, remove docky from your startup applications, and just add sh [path to file], such as:

sh /usr/wegsehen/Scripts/docky.sh