简体   繁体   中英

How do I get launchd to use jruby

I'm using jruby to develop a x-platform app. When running this app on a Mac I would like to use launchd to launch it periodically.

My trouble is that launchd seems to use the system ruby (/usr/bin/ruby) where none of my required gems are installed.

Is there a way I can create some sort of link to force the launchd do to use the jruby instead of the system ruby?

Thanks, HS

I found the answer here: Watir scripts via launchd

This is my bash script which sets rvm then runs the ruby script with the specified ruby version:

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

The bash script is then launched via launchd with the following 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM