我正在使用jruby开发一个x平台应用程序。在Mac上运行此应用程序时,我想使用launchd定期启动它。
我的麻烦是launchd似乎使用了系统ruby(/ usr / bin / ruby),其中没有安装我所需的宝石。
有没有办法可以创建某种链接来强制launchd do使用jruby而不是系统ruby?
谢谢, HS
答案 0 :(得分: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>