用于启动另一个应用程序的应用程序的 OSX LaunchAgent
我正在尝试为 cassandra 设置本地 LaunchAgent,但遇到了一个问题,因为 bin/cassandra
只是一个启动的 shell 脚本:
/usr/bin/java -ea -javaagent:blah blah blah blah blah blah blah
我的 LaunchAgent 启动了脚本,但要么从不启动 cassandra,要么不启动不允许它产生子进程,或者,我不完全确定发生了什么,但似乎我以前遇到过这个问题。我知道要让它工作的唯一方法是将我的 LaunchAgent 从:更改
<?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>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>
为...
...
<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>
我想知道是否有人知道我如何可以从 LaunchAgent 引用 shell 脚本,而不是从 中提取所有参数ps辅助
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 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对 cassandra 不是特别熟悉,但我的猜测是它正在将自身守护化(即进入后台)。 launchd 不喜欢它的子进程自己守护进程;然后它希望留在前台,可以监视它们。如果一个进程自行守护进程,launchd 会认为它已退出(从技术上讲,它已经退出),清理所有剩余的子进程(包括现在守护进程),然后重新启动它。起泡沫,冲洗,重复。
根据 cassandra wiki 中的此条目,您可以将
-f 传递给 cassandra 标志使其留在前台,并保持 launchd 快乐:
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: