2013-07-16 40 views
1

我正在使用jruby開發x平臺應用程序。在Mac上運行此應用程序時,我想使用launchd定期啓動它。如何獲得launchd以使用jruby

我的問題是,launchd似乎使用系統ruby(/ usr/bin/ruby​​),其中沒有安裝我所需的gem。

有沒有一種方法可以創建某種鏈接來強制launchd使用jruby而不是系統ruby?

感謝, HS

回答

1

我找到了答案在這裏:Watir scripts via launchd

這是我的bash腳本這臺RVM然後運行與指定的紅寶石版本的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 
########## 

的bash腳本然後通過launchd通過以下plist啓動:

<?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>