0

就像标题所说的那样,我正在尝试在 OS X Yosemite 中使用 launchd/launchctl 自动启动 zookeeper。

这是我的 plist 文件“/Library/LaunchDaemons/com.test.zookeeper.plist”,它归 root:wheel 所有。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>com.test.zookeeper</string>
        <key>RunAtLoad</key>
        <true/>
        <key>ProgramArguments</key>
        <array>
            <string>/opt/zookeeper/bin/zkServer.sh</string>
            <string>start</string>
        </array>
    <key>StandardInPath</key>
    <string>/var/log/zookeeper_stdin.log</string>
    <key>StandardOutPath</key>
    <string>/var/log/zookeeper_stdout.log</string>
    <key>StandardErrorPath</key>
    <string>/var/log/zookeeper_stderr.log</string>
    </dict>
</plist>

执行“sudo launchctl load com.test.zookeeper.plist”后,这是“/var/log/system.log”中的内容,用户名已替换为星号。

Apr 17 11:13:22 ***-03 sudo[97284]:  ****.** : TTY=ttys003 ; PWD=/Library/LaunchDaemons ; USER=root ; COMMAND=/bin/launchctl load com.test.zookeeper.plist
Apr 17 11:13:22 ***-03 com.apple.xpc.launchd[1] (com.apple.xpc.launchd.domain.system): Session adoption is only allowed in user domains.
Apr 17 11:13:22 ***-03 nohup[97299]: Could not adopt Background session: 125: Domain does not support specified action

“/var/log/zookeeper_stdout.log”

Starting zookeeper ... STARTED

“/var/log/zookeeper_stderr.log”

JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg

所以看起来这项工作是由launchd执行的,但是当我执行“ps -ef | grep zoo”来检查服务时,实际服务不存在,我通常会看到我是否使用“sudo / 手动启动zookeeper” opt/zookeeper/bin/zkServer.sh 启动"

有人能帮我吗?谢谢你。

4

1 回答 1

0

我有一个ping由 launchd 运行的简单程序,我会得到

会话采用仅允许在用户域中。

在系统日志中 - 并且该进程不会运行。

我的猜测是由于日志中的该问题而被阻止。


如果你这样做launchctl list |grepplist name并且它显示-在第一列(应该是 PID)中,那么作业永远不会运行。

下面是一个运行 bash 脚本的工作 plist示例。

#launchctl 列表 |grep ping

549 0 com.pingServers

于 2016-03-16T17:35:03.523 回答