macos - OSX 为 node forever 进程启动了 plist

标签 macos node.js osx-mountain-lion launchd forever

我正在尝试为我的 Node 服务器编写一个 launchd.plist 文件。我永远使用来运行我的 Node 服务器。我希望服务器在启动时启动。我也想等mongodb launchd plist先运行。

我使用自制软件安装了 mongobb,它已经附带了一个 launchd.plist。我执行了以下操作:

$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

mongodb 的 plist 是:

<!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>homebrew.mxcl.mongodb</string>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/local/opt/mongodb/mongod</string>
    <string>run</string>
    <string>--config</string>
    <string>/usr/local/etc/mongod.conf</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>KeepAlive</key>
  <false/>
  <key>WorkingDirectory</key>
  <string>/usr/local</string>
  <key>StandardErrorPath</key>
  <string>/usr/local/var/log/mongodb/output.log</string>
  <key>StandardOutPath</key>
  <string>/usr/local/var/log/mongodb/output.log</string>
  <key>HardResourceLimits</key>
  <dict>
    <key>NumberOfFiles</key>
    <integer>1024</integer>
  </dict>
  <key>SoftResourceLimits</key>
  <dict>
    <key>NumberOfFiles</key>
    <integer>1024</integer>
  </dict>
</dict>
</plist>

如果我关闭计算机并重新启动,mongodb 会正常启动。

但是我的 Node 服务器没有启动。有什么想法吗?

<?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>KeepAlive</key>
        <dict>
            <key>SuccessfulExit</key>
            <false/>
        </dict>
        <key>Label</key>
        <string>com.test.app</string>
        <key>ProgramArguments</key>
        <array>
            <string>/usr/local/bin/forever</string>
            <string>-a</string>
            <string>-l</string>
            <string>/var/log/app/app.log</string>
            <string>-e</string>
            <string>/var/log/app/app_error.log</string>
            <string>/data/server/app.js</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>StartInterval</key>
        <integer>3600</integer>
    </dict>
</plist>

编辑:

写入日志文件,我看到了:

env: node: No such file or directory

我认为这意味着找不到 Node 二进制文件。我可以回显 $PATH 并且/usr/local/bin 在我的路径中。我可以从终端启动 Node 。想法?

最佳答案

添加环境变量对我有用。

<key>EnvironmentVariables</key>
<dict>
  <key>PATH</key>
  <string>/usr/local/bin/:$PATH</string>
</dict>

您可能还需要将 WorkingDirectory 添加到您的 Node 应用程序中。

<key>WorkingDirectory</key>
<string>path/to/your/node/app</string>

关于macos - OSX 为 node forever 进程启动了 plist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18604119/

相关文章:

macos - mac终端ffmpeg批量递归转换保存目录结构

javascript - 获取 API 不通过 post 发送数据

ios-simulator - iOS 5.1 上的 Xcode 4.4 构建成功,但运行在模拟器上挂起,调试消息为 'Failed to attach to process id <pid>'

macos - textmate 不保存提交信息

python-3.x - dyld : Library not loaded:/System/Library/Frameworks/CoreFoundation.框架/版本/A/CoreFoundation

android - ADT Bundle for mac 已损坏

xcode - brew in 不适合我 OSX 10.7

node.js - html 到文件缓存的模块

android - 在 Node 中发送 GCM 推送

python - 使用 PyObjC 处理 Mountain Lion 的通知中心