I am on Ubuntu GNOME 15.10 with GNOME 3.18, but I don't like the normal applications launcher so I have installed Docky, however often Docky suddenly closes and I am forced to manually restart it, so I was wondering how I could make a daemon which runs all the time in the background that would check at regular intervals if Docky is running, and if it is not, run it?
Asked
Active
Viewed 88 times
1
-
Do you not want to run a script kicked off by a cron job every 10-15 minutes to check it? – Terrance Mar 31 '16 at 23:18
-
@Terrance: That would probably be good. – Mar 31 '16 at 23:50
-
OK, let me throw something together for you here. :) – Terrance Mar 31 '16 at 23:54
-
Simple task, not too difficult to implement. What are requirements ? – Sergiy Kolodyazhnyy Apr 01 '16 at 00:10
-
I knew, because I answered this one: http://askubuntu.com/questions/751465/why-wont-this-script-run-on-startup/751480#751480 – Jacob Vlijm Apr 01 '16 at 03:11
-
Since your question is a duplicate, I've posted an answer on the dupe question. http://askubuntu.com/a/752531/295286 – Sergiy Kolodyazhnyy Apr 01 '16 at 04:30
-
What about supervisord? – Brian M. Hunt Apr 01 '16 at 10:33
1 Answers
1
Create a script anywhere you want it to be, preferably in your home directory. I like to call mine, check_docky.bsh
. In your script, do the following lines:
#!/bin/bash
ps -ef | grep -i docky.exe | grep -v grep >/dev/null
case $? in
1) sh -c "mono /usr/lib/docky/Docky.exe";;
0) exit 0;;
esac
In the above script, the ps -ef | grep
will look to see if Docky
is running. If it is not running the exit code that gets returned is 1
, so then the case statement would relaunch Docky
automatically. Else, the script would exit normally with a code 0
.
Make sure the script is executable:
chmod +x check_docky.bsh
Then create a cron
job for the script.
First, run crontab
as you:
$ crontab -e
Then as a new entry add the following so that it will check every 10 minutes starting at :00
of the hour:
# m h dom mon dow command
*/10 * * * * /home/<username>/check_docky.bsh
To show that this command works:
~$ ps -ef | grep wookie | grep -v grep
~$ echo $?
1
~$ ps -ef | grep wookie
terrance 20978 6976 0 13:53 pts/17 00:00:00 grep --color=auto wookie
~$ echo $?
0
Hope this helps!

Terrance
- 41,612
- 7
- 124
- 183
-
This answer is flawed as the exit code use will always be 0 due to
grep -v grep
always matching. You need to move that statement afterps -ef | grep -v grep
or something like that. – 13m5 May 10 '18 at 18:57 -
-
@13m5 There is nothing wrong with that statement. I don't write answers that I don't test.
grep -v grep
makes it so that grep doesn't find itself as a process because technically it is a process at the moment. I know that there are other ways to do this, but this method works fine. – Terrance May 11 '18 at 14:25