1

我正在使用 jruby 开发一个 x 平台应用程序。在 Mac 上运行此应用程序时,我想使用 launchd 定期启动它。

我的问题是,launchd 似乎使用了系统 ruby​​ (/usr/bin/ruby),其中没有安装我所需的 gem。

有没有办法可以创建某种链接来强制launchd使用jruby而不是系统ruby?

谢谢, HS

4

1 回答 1

1

我在这里找到了答案:Watir scripts via launchd

这是我的 bash 脚本,它设置 rvm 然后使用指定的 ruby​​ 版本运行 ruby​​ 脚本:

############
#first arg is task_kind. Pass it on to the ruby script.
task_kind=$1

    # Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then

  # First try to load from a user install
  source "$HOME/.rvm/scripts/rvm"

elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then

  # Then try to load from a root install
  source "/usr/local/rvm/scripts/rvm"

else

  printf "ERROR: An RVM installation was not found.\n"

fi

echo "Launching TaskManagerRunner for $task_kind."
#first arg in the next line is the specific ruby needed for the script.
#second arg is the script.
#third arg is the script param.
/Users/haroldshields/.rvm/rubies/jruby-1.7.4/bin/ruby /Users/haroldshields/Documents/Ivey/Projects/WMS/Code/Task_Engine/TaskManager.rb $task_kind
##########

然后通过 launchd 使用以下 plist 启动 bash 脚本:

<?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>Disabled</key>
    <false/>
    <key>KeepAlive</key>
    <false/>
    <key>Label</key>
    <string>local.ivey.wms.TaskManager.SftpTasks</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/bash</string>
         <string>/Users/haroldshields/Documents/Ivey/Projects/WMS/Code/Task_Engine/TaskManagerRunner.sh</string>
        <string>SftpTasks</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>StartInterval</key>
    <integer>15</integer>
</dict>
</plist>
于 2013-07-17T17:12:19.380 回答