5

This script works perfectly when I launch it manually. How can I get it to run on startup? The function of the script is to get Docky to auto relaunch in the case of a crash.

I created the script like this:

  • gedit ~/process_monitor.sh

Pasted in the following (found it on Ask Ubuntu):

#!/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
  • Saved the file.

  • Set the permission:

    chmod a+x ~/process_monitor.sh
    

Now, when I run it like this, it works perfectly:

~/process_monitor.sh docky

However, when I add the following to startup applications, that does not make the script launch on startup. Well, maybe it does, but the script doesn't work.

/bin/bash ~/process_monitor.sh docky

enter image description here

Basically there's some sort of graphical element that flashes on the screen for half a second, but no other sign of the script to be seen, and Docky does not relaunch if it's killed.

How to make this work? I'm sure it's extremely basic.

I'm on Ubuntu 14.04.

  • Pipe your command to a tmp file when you add it to your startup, that will let you see if you the command is executing, and when it is, drop the error message. – user508889 Mar 29 '16 at 12:46
10

Using paths in a .desktop file

The issue is that Startup Applications creates a .desktop file in ~/.config/autostart

In a .desktop file, you cannot use relative- or variable paths like ~. Use absolute paths instead:

/bin/bash /absolute/path/to/process_monitor.sh docky
  • 1
    Fiksdal : As we talked about it a few minutes ago ... please give this solution a try - it most probably will solve your problem ... +1 ! :) – cl-netbox Mar 29 '16 at 13:26
  • 1
    @cl-netbox it did :) – Revetahw Mar 29 '16 at 13:46
  • 2
    @Fiksdal always glad it works :) – Jacob Vlijm Mar 29 '16 at 13:47
0

This is better approach

run crontab -e insert this line at the bottom

*/2 * * * * if [ ! `pgrep docky` ] ; then /usr/bin/docky; fi

check if /usr/bin/docky command starts docky, that's it. This will check if docky is running every 2 minutes, if not it will start docky.

  • 1
    This would make the assumption you're running a gui 100% of the time, or don't have a multi user system. While that's fine for most, I find it best to not set something that will be system wide regardless of the current state. – user508889 Mar 29 '16 at 12:49
  • @MRX The other answer worked perfectly, so I don't see any reason to try this. – Revetahw Mar 29 '16 at 13:47
  • 1
    Almost certainly, this will break from cron like this, since you need the DISPLAY -variable on GUI stuff. – Jacob Vlijm Mar 29 '16 at 14:42
  • 1
    Also, if Docky has crashed, I don't want to wait for up to 2 minutes for it to relaunch. It would then be quicker to launch it manually. – Revetahw Mar 29 '16 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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