OSX LaunchAgent for app that launches another app
I'm trying to set up a local LaunchAgent for cassandra and am running into an issue since bin/cassandra
is just a shell script that launches:
/usr/bin/java -ea -javaagent:blah blah blah blah blah blah blah
My LaunchAgent launches the script but either never launches cassandra or doesn't allow it to spawn sub-processes, or, well I'm not entirely sure what's happening but it seems I've run into this issue before. The only way I know of to get this to work is to change my LaunchAgent from:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD开发者_如何学JAVA PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.cassandra.agent</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>UserName</key>
<string>root</string>
<key>ProgramArguments</key>
<array>
<string>/path/to/cassandra/bin/cassandra</string>
</array>
<key>WorkingDirectory</key>
<string>/path/to/cassandra/bin</string>
</dict>
</plist>
to...
...
<key>ProgramArguments</key>
<array>
<string>/usr/bin/java</string>
<string>-ea</string>
<string>-javaagent:blah</string>
<string>blah</string>
<string>blah</string>
<string>blah</string>
<string>blah</string>
<string>blah</string>
<string>blah</string>
</array>
I'm wondering if anyone knows how I can just reference the shell script from the LaunchAgent instead of pulling all the args from ps aux
I'm not specifically familiar with cassandra, but my guess is that it's daemonizing itself (i.e. dropping into the background). launchd doesn't like its children to daemonize themselves; it expects then to stay in the foreground where it can keep an eye on them. If one daemonizes itself, launchd thinks it's exited (which, technically, it has), cleans up any leftover subprocesses (including the now daemonized process), and relaunches it. Lather, rinse, repeat.
According to this entry in the cassandra wiki, you can pass cassandra the -f
flag to make it stay in the foreground, and keep launchd happy:
<key>ProgramArguments</key>
<array>
<string>/opt/local/bin/cassandra</string>
<string>-f</string>
</array>
精彩评论