开发者

"uninitialized constant Etc" when running Ruby application

A few applications on my server relying on Ruby and Ruby On Rails seem to have stopped working. Or atleast partially so. I managed to get the web gui of the application in question to start functioning again by reinstalling different part of Ruby. But I most likley broke something else in the process.

I have managed to track it down using some tests and it seems like Etc is somehow not found by the program when it runs.

I tested by

ruby -e 'puts Etc.getpwnam("apache").uid'

and got

uninitialized constant Etc

If I instead tested

ruby -r etc -e 'puts Etc.getpwnam("apache").uid'

I get the correct answer

48

This is running on an Amahi6 server (running Fedora Core 14 64bit).

Example on the code in question in the actual application that fails is

#!/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
...

this fails with the same

uninitialized constant Etc

Clarification: I have NOT changed this code at all and it has worked in it's current state before

What could it be that I have messed up? :)

UPDATE: Ruby installed now is version 1.8.7

UPDATE 2:

If I try to manually add a require for rubygems and etc it fails, but complains about another package. So I think there is something fundamentally messed up with the core of my ruby.

/usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:55: uninitialized constant ActiveSupport::Dependencies::Mutex (NameError) from /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:inrequire' from /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support.rb:56 from /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:inrequire' from /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record.rb:25 from /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:inrequire' from /var/hda/platform/html/script/install-app:70


Ended up being that the versions of rails and gems were to new. Downgraded to gems 1.3.7 and rails 2.3.8.

gem update --system 1.3.7

gem uninstall rails

gem install rails --version 2.3.8


You seem to be missing require 'rubygems' and require 'etc' (put them below require 'optparse')


remember about 'rubygems',

commandline:

ruby -rubygems -e 'puts Etc.getpwnam("apache").uid'

script:

require 'rubygems'
puts Etc.getpwnam("apache").uid
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜