| Mail |
You might also like: WoW Insider, Massively, and more

PatG

Member since: May 26th, 2006

PatG's Latest Comments

Blog Activity
Blog# of Comments
Joystiq2 Comments
TUAW.com5 Comments

Terminal Tips: bash cron script to keep an app running

Oct 21st 2010 10:17PM (TUAW.com)
Seems like my last couple of comments got lost. Here's a launchd plist without any absolute paths:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">;
<plist version="1.0">
<dict>
<key>Label</key>
<string>local.keep_dropbox_running</string>
<key>ProgramArguments</key>
<array>
<string>open</string>
<string>-W</string>
<string>-a</string>
<string>Dropbox</string>
</array>
<key>KeepAlive</key>
<true />
<key>RunAtLoad</key>
<true />
</dict>
</plist>

Terminal Tips: bash cron script to keep an app running

Oct 21st 2010 10:10PM (TUAW.com)
Should be:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">;
<plist version="1.0">
<dict>
<key>Label</key>
<string>local.keep_dropbox_running</string>
<key>ProgramArguments</key>
<array>
<string>open</string>
<string>-W</string>
<string>-a</string>
<string>Dropbox</string>
</array>
<key>KeepAlive</key>
<true />
<key>RunAtLoad</key>
<true />
</dict>
</plist>

Terminal Tips: bash cron script to keep an app running

Oct 21st 2010 10:09PM (TUAW.com)
There also happens to be an absolute path right here:
*/5 * * * * /Users/luomat/bin/keep-my-app-running.sh



Here's a launchd plist that should achieve the same without any absolute paths:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">;
<plist version="1.0">
<dict>
<key>Label</key>
<string>local.keep_dropbox_running</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/open</string>
<string>-W</string>
<string>-a</string>
<string>Dropbox</string>
</array>
<key>KeepAlive</key>
<true />
<key>RunAtLoad</key>
<true />
</dict>
</plist>

Terminal Tips: bash cron script to keep an app running

Oct 21st 2010 8:31PM (TUAW.com)
The Program key in a launchd plist has the same semantics as execvp. From the launchd.plist manpage:

Program
This key maps to the first argument of execvp(3). If this key is missing,
then the first element of the array of strings provided to the
ProgramArguments will be used instead.

According to the execvp manpage, a call to execvp uses the PATH environment variable if it is set. Otherwise, it searches /usr/bin and /bin. The absolute path is necessary because the directory containing the actual executable for a given application (usually /Contents/MacOS/) is unlikely to be in a user's PATH. Even if it were, it's possible that a user's PATH hasn't been set when launchd loads a given job (e.g. if .bash_profile is not read until after all launchd jobs have been loaded).

On another note, a big downside of the script above is that it cannot check the exit status of the application it is keeping alive. In other words, you cannot reliably quit an application (if you need to) without disabling the cron job.

Here are a couple of scripts that generate/install launchd jobs to relaunch a given application or executable if it exits unsuccessfully:

http://www2.uic.edu/~pgavli2/keep-running.sh
http://www2.uic.edu/~pgavli2/gen-keepalive-plist.sh

So long as an application is guaranteed to exit with a non-zero status when it crashes, these jobs should operate properly.

TUAW Retro Giveaway Part 2: Manuals, BASIC books and a printer

Apr 2nd 2009 1:49AM (TUAW.com)
Own and use (albeit very occasionally) an Apple ][+.

Pac-man + Mii = Pac-miin

Apr 4th 2007 3:21PM (Joystiq)
HAY GUYS DID JOO KNO THAT WII IS SAME AS NES??? LOLZ JOO R WASTING MONIES NINTENDO MORE LIKE SUCKTENDO


Seriously.

University of Washington plays the most WoW?

May 26th 2006 5:28PM (Joystiq)
As a current RIT student, I can definitely vouch for this. People out here play /way/ too much WoW.

Joystiq Archives

May 2012

SMTWTFS
 12345
6789101112
13141516171819
20212223242526
2728293031 

Featured Stories

Image

Now Playing: May 28 - June 3, 2012

Posted on May 29th 2012 11:59PM

Engadget

Engadget

TUAW

TUAW

Massively

Massively

WoW

WoW