Snippet 0x07: Restart Docky from a cronjob (when it crashed)
I recently updated from Linux Mint 16 Petra to Linux Mint 17 Qiana. Everything went smoothly, except for my dock Docky. For some reason, Docky decides to crash every once in a while with some error message.
Instead of fixing this error or reporting it, I decided to find the easy way out and simple set up a cronjob to restart Docky every minute (if it has crashed).
Because it took me a bit (and you might have trouble with it too), this tiny post shows you how to do that. Simply add this to your crontab to let cron run this command every minute. Open the crontab via crontab -e:
* * * * * if [ -z "$(ps aux | grep -E DocX?ky.exe)" ]; then DISPLAY=:0.0 dbus-launch docky > /tmp/docky 2>&1; fi
This command solves a few issues:
- It checks if Docky is already running by
ps-ing andgrep-ing for theDocky.exeprocess. TheX?prevents thegrepfrom showing up in the results. - If Docky isn’t running, it sets the
DISPLAYvariable to the first display (:0.0in most cases). - It launches Docky via
dbus-launch docky, because Docky requires dbus to run.
That’s all the magic. Works like a charm for me.