我的服务器上依赖 Ruby 和 Ruby On Rails 的一些应用程序似乎已停止工作。或至少部分如此。我设法通过重新安装Ruby的不同部分来获取有问题的应用程序的web gui以重新开始运行。但是我最喜欢在这个过程中打破了别的东西。
我已经设法使用一些测试来跟踪它,似乎 Etc 在程序运行时以某种方式找不到。
我测试了
ruby -e 'puts Etc.getpwnam("apache").uid'
得到了
未初始化的常数Etc
如果我改为测试
ruby -r etc -e 'puts Etc.getpwnam("apache").uid'
我得到了正确答案
48
这是在 Amahi6 服务器上运行(运行 Fedora Core 14 64位)。
实际应用程序中失败的代码示例
#!/usr/bin/env ruby
# Amahi Home Server
# Copyright (C) 2007-2010 Amahi
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License v3
# (29 June 2007), as published in the COPYING file.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# file COPYING for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Amahi
# team at http://www.amahi.org/ under "Contact Us."
require File.dirname(__FILE__) + '/../config/boot'
#require 'commands/runner'
require 'optparse'
# switch to apache:users first
uid = Etc.getpwnam("apache").uid
gid = Etc.getgrnam("users").gid
Process.gid = gid
Process.egid = gid
Process.uid = uid
Process.euid = uid
...
这失败了同样的
未初始化的常数Etc
澄清:我根本没有更改此代码,而且它已经处于当前状态
我搞砸了什么呢? :)
更新: 现在安装的Ruby是版本 1.8.7
更新2:
如果我尝试为 rubygems 和等手动添加 require ,则会失败,但会抱怨另一个包。所以我认为有一些东西从根本上搞砸了我的红宝石的核心。
/usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:55: 未初始化的常量ActiveSupport :: Dependencies :: Mutex(NameError) 从 /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in
gem_original_require' from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in
需要” 从 /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support.rb:56 从 /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:ingem_original_require' from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in
需要” 从 /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record.rb:25 从 /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:ingem_original_require' from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in
需要” 来自/ var / hda / platform / html / script / install-app:70
答案 0 :(得分:2)
结束了rails和gem的版本是新的。降级为宝石1.3.7 和 rails 2.3.8 。
gem update --system 1.3.7
gem uninstall rails
gem install rails --version 2.3.8
答案 1 :(得分:1)
您似乎缺少require 'rubygems'
和require 'etc'
(将它们放在require 'optparse'
下面)
答案 2 :(得分:0)
记住'rubygems',
命令行:
ruby -rubygems -e 'puts Etc.getpwnam("apache").uid'
脚本:
require 'rubygems'
puts Etc.getpwnam("apache").uid