Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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

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

share|improve this question
    
You may be able to adapt this script posted by someone who answered a similar question on superuser: superuser.com/questions/223449/auto-restart-process-on-crash – user76204 Jul 15 '12 at 20:16

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.

share|improve this answer
    
What if I'm running Gnome 3 and I don't have "Startup Applications" and I want to put it in a .desktop file instead? What would I put for the "Exec=" line? – guttermonk Nov 9 '15 at 23:40
    
Got it! :) "Terminal=False" and "Exec=nohup bash -c '~/process_monitor.sh docky;$SHELL' &" – guttermonk Nov 10 '15 at 1:50
    
Thanks! I also use this for Dropbox and Synergy. Works great! – guttermonk Nov 10 '15 at 1:52
    
The script works excellently when I run it manually, but I have added /bin/bash ~/process_monitor.sh docky to startup applications, yet nothing happens. Actually I do see half a terminal window flash on the screen for a second after logging in, but that's all. The script doesn't kick in even if I added that command to the startup applications. What should I do? – Fiksdal Mar 29 at 12:04
    
@guttermonk Can you offer any help on my query in the comment above? I've posted this as as a seperate question also: askubuntu.com/questions/751465/… – Fiksdal Mar 29 at 12:37

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

share|improve this answer

I wrote a small "wrapper" script bellow. It will spawn docky and monitor it. Spawn this alone without docky in the Startup Applications.

#!/usr/bin/env bash
#
###########################################################
# Author: Serg Kolo , contact: 1047481448@qq.com 
# Date: March 31st, 2016
# Purpose: monitor script that respawns docky if it dies
# Written for: http://askubuntu.com/q/752478/295286
# Tested on: Ubuntu 14.04 LTS
###########################################################
# Copyright: Serg Kolo , 2016
#    
#     Permission to use, copy, modify, and distribute this software is hereby granted
#     without fee, provided that  the copyright notice above and this permission statement
#     appear in all copies.
#
#     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
#     THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
#     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
#     DEALINGS IN THE SOFTWARE.

ARGV0="$0"
ARGC=$#

monitor_pid ()
{
  if ps -p $1 > /dev/null ;
  then
    # Docky is there, no-op
    sleep 0.25
    continue
  else
    # Docky is gone,ask user if they want it back
    DOCKY_PID=$(ask_restart)
  fi
}

spawn_docky()
{
  docky &> /dev/null  &
  echo $! # return docky pid
}

ask_restart ()
{
   zenity --question --title="Docky Monitor"\
          --text="Docky has quit, do you want to restart it ?" > /dev/null
   if [ $? -eq 0  ] ;then
        spawn_docky
   else
       kill -SIGTERM $MYPID # exit the script 
   fi        
}

main()
{
  local MYPID=$$
  local DOCKY_PID=$(spawn_docky)
  while true;
  do
     monitor_pid $DOCKY_PID
  done
}

main
share|improve this answer

The ./process_monitor.sh works great.

But only if i use Terminal, or yakuake...so i can just open a new shell, when i use "~/process_monitor.sh docky" or "/bin/bash ~/process_monitor.sh docky"

But if I go to the "Startup Applications", click add and follow these instructions nothing happens when my Computer is starting up. I still have to run that command manually. And it won work, when i put in /home/"username"/process_monitor.sh docky, too.

I found, or created a solution (which hasn't been posted somewhere) to get it autostarted.

Instead of using the ~/process_monitor.sh docky create a new textfile:

  • gedit ~/start.sh
  • type following

#!/bin/bash

~/process_monitor.sh docky

done

  • Save file
  • Set permission:

chmod a+x ~/start.sh

Now you can run the program in your terminal/yakuake or whatever you prefer to use:

~/start.sh

and it will start the ~/process_monitor.sh docky. So it'll get startet and restarted if crashes.

You can choose any name you like for "process_monitor.sh" and "start.sh" only .sh is important. But be sure to change it in your textfiles as well.

Now go to your Dash, type in and open "Startup Applications".

  • Delete othe set Docky Startup settings
  • Create a new one
  • Name: Docky or whatever you want to name it
  • Command: /home/"your username"/start.sh (for me for ex. /home/kevin/startup.sh)
  • Comment: Whatever you like.
  • Go to your Docky settings and disable "Start at login"

Now you can restart your Computer and test it.

Videotutorial

share|improve this answer
    
Why not just create a (symbolic) link to process_monitor.sh? No file editing or permission changes required. – David Foerster Nov 1 '14 at 11:16
    
what do you mean with symbolic link? – Kevin Nov 1 '14 at 15:04
    
This: ln -s process_monitor.sh start.sh or ln -s ~/process_monitor.sh ~/Desktop/ – David Foerster Nov 1 '14 at 18:27

Your Answer

 
discard

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.