1

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

inquam
  • 12,664
  • 15
  • 61
  • 101
  • What do you mean exactly by "reinstalling different part of Ruby"? And it would help if you would put the ruby version as well (ruby -v). – Benoit Garret Aug 25 '11 at 11:43
  • It was quite a bit of time ago so a bit blurry I'm afraid. But I think I reinstalled ruby and libs using yum. So **yum reinstall ruby** and **yum reinstall ruby-libs**. Maybe something with the gems to but I don't think so. – inquam Aug 25 '11 at 11:48
  • You can try to reinstall the gems required with "rake gems:install" (in the directory where the rails app is). I'm afraid your best bet is to reinstall Amahi as the install script looks quite complicated. – Benoit Garret Aug 25 '11 at 12:00
  • That would suck :)... I have tons of stuf finstalled... hehe... When trying to run the rake command I also get an error: **uninitialized constant ActiveSupport::Dependencies::Mutex** – inquam Aug 25 '11 at 12:02
  • Look at http://stackoverflow.com/questions/5176782/uninitialized-constant-activesupportdependenciesmutex-nameerror, it should allow you to go ahead. – Benoit Garret Aug 25 '11 at 12:19
  • Did you manage to solve this? I'd be interested in knowing the root cause. – Benoit Garret Aug 29 '11 at 13:22
  • Didn't have time to look at it but last night I sat down to fix it. Ended up being that the versions of rails and gems were to new. Downgraded to **gems 1.3.7** and **rails 2.3.8**. – inquam Aug 30 '11 at 11:15

3 Answers3

2

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
inquam
  • 12,664
  • 15
  • 61
  • 101
1

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

Benoit Garret
  • 14,027
  • 4
  • 59
  • 64
  • But I have not changed the Amahi ruby code at all. It just stopped working. Very strange that I all of a sudden would have to go through code and add require statements that weren't needed before? It's not that there could be a conf file that tells ruby to ALWAYS include these that I might have removed or overwritten or something? – inquam Aug 25 '11 at 11:29
  • I'm afraid I can't help you on that one. I don't know how Amahi works. In fact, I didn't even know it existed before answering your question :-) – Benoit Garret Aug 25 '11 at 11:43
0

remember about 'rubygems',

commandline:

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

script:

require 'rubygems'
puts Etc.getpwnam("apache").uid
dfens
  • 5,413
  • 4
  • 35
  • 50