Ruby prog不会作为LaunchDaemon运行

时间:2010-12-07 03:29:38

标签: ruby macos plist

我有一个ruby程序,非常简单,只需在一堆主机上进行DNS查找。该程序从终端(Mac OS X 10.6.5),Ruby 1.9.2使用RVM运行良好。

我想按计划运行它,并希望加载LaunchDaemon来执行此操作。该程序不作为LauanchDaemon运行,并且输出文件已创建,但为空,因此我无法看到错误。我怀疑它与包含有关。

这是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>Label</key>
    <string>com.jsw.ping</string>
    <key>RunAtLoad</key>
    <true/>
    <key>Debug</key>
    <true/>
    <key>StandardOutPath</key>
    <string>/var/jsw/logs/ping.txt</string>
    <key>EnvironmentVariables</key>
        <dict>
            <key>PATH</key>
                <string>/Users/scott/.rvm/gems/ruby-1.9.2-p0/bin:/Users/scott/.rvm/gems/ruby-1.9.2-p0@global/bin:/Users/scott/.rvm/rubies/ruby-1.9.2-p0/bin:/Users/scott/.rvm/gems/ruby-1.9.2-p0@rails3/bin:/Users/scott/.rvm/gems/ruby-1.9.2-p0@global/bin:/Users/scott/.rvm/rubies/ruby-1.9.2-p0/bin:/Users/scott/.rvm/bin:/usr/local/maven/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin</string>
        </dict>
    <key>StandardErrorPath</key>
    <string>/var/jsw/logs/ping.err.txt</string>
    <key>ProgramArguments</key>
    <array>
        <string>ping.rb</string>
    </array>
    <key>StartInterval</key>
      <integer>1800</integer>
    <key>WorkingDirectory</key>
        <string>/Library/WebServer/vHosts/scripts/ping/</string>
   <key>UserName</key>
       <string>scott</string>
  </dict>
</plist>

Ruby程序是:

#!/Users/scott/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
require 'rubygems'  
require 'active_record'
require 'yaml'  
require 'dnsruby'
include Dnsruby


dbconfig = YAML::load(File.open('database.yml'))
ActiveRecord::Base.establish_connection(dbconfig)

# flush cache
rslt = `dscacheutil -flushcache`

Dnsruby::DNS.open 
rslvr = Dnsruby::DNS.new

now = DateTime.now.to_s
mysqlDT = now.gsub("T", " ")
puts mysqlDT


class Host < ActiveRecord::Base  
end  
class Ip < ActiveRecord::Base  
end  

Host.find_each do |svr|
  ip = rslvr.getaddress(svr.host).to_s
  svr.lastIP = ip
  svr.save
  Ip.create(:ip => ip, :host => svr.host, :DT => mysqlDT, :hostID => svr.id)
end

1 个答案:

答案 0 :(得分:0)

根本问题是LaunchDaemon作业是从没有正确设置RVM的shell运行的,因此无法找到包含的类。由于我的系统上没有任何遗留的Ruby程序,我删除了RVM并在我的系统上的/ usr / local / bin中安装了Ruby 1.9.2,然后重新安装了宝石。

第二个问题(没有记录)是由于权限错误造成的。