无法在upstart调用的ruby脚本中导入readline

时间:2013-06-04 16:53:56

标签: ruby ubuntu readline rbenv upstart

我正在尝试使用rails应用程序与upstart进行部署。作为其中的一部分,我使用的是rbenv红宝石(红宝石1.9.3p392,如果重要的话)。

通过一长串调试,我已经了解了我认为最小的测试用例。这个脚本:

require 'readline'
当我从命令行运行它时,

工作,但是当我通过upstart启动它时,如:

script
  env > /tmp/upstart.env
  gem environment > /tmp/gem.env
  /home/topshelf-deploy/.rbenv/shims/ruby bundle_test.rb > /tmp/bt.log 2>&1
end script

我的日志文件包含:

/home/topshelf-deploy/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rb-readline-0.4.2/lib/rbreadline.rb:1091:in `<module:RbReadline>': undefined method `+' for nil:NilClass (NoMethodError)
    from /home/topshelf-deploy/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rb-readline-0.4.2/lib/rbreadline.rb:13:in `<top (required)>'
    from /home/topshelf-deploy/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/topshelf-deploy/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/topshelf-deploy/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rb-readline-0.4.2/lib/readline.rb:8:in `<module:Readline>'
    from /home/topshelf-deploy/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rb-readline-0.4.2/lib/readline.rb:6:in `<top (required)>'
    from /home/topshelf-deploy/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
    from /home/topshelf-deploy/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
    from /home/topshelf-deploy/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
    from bundle_test.rb:1:in `<main>'

我的宝石环境看起来是相同的,这取决于我是通过暴发户还是交互式shell运行(再次,这样可以正常工作)。我已经将PATH设置为指向我的rbenv ruby​​。

有关如何使这项工作的任何建议?我的谷歌搜索没有发现类似的任何东西。我很困惑。

1 个答案:

答案 0 :(得分:3)

最后分解并查看rbreadline.rb的来源:1091告诉我:

ENV["HOME"] ||= ENV["HOMEDRIVE"]+ENV["HOMEPATH"]

阿。 rb-readline要求我设置HOME环境变量。因为,原因:P

在我的upstart配置中添加了env HOME=/home/topshelf-deploy,一切正常。