“未初始化常量Etc”运行 Ruby 应用程序时

发布于 2024-12-01 06:23:41 字数 2900 浏览 2 评论 0原文

我的服务器上依赖 RubyRuby On Rails 的一些应用程序似乎已停止工作。或者至少部分如此。通过重新安装 Ruby 的不同部分,我设法让相关应用程序的 Web GUI 重新开始运行。但我很可能在这个过程中打破了其他东西。

我已经设法使用一些测试来追踪它,并且似乎 Etc 在程序运行时没有被程序找到。

我测试了

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

并得到了

未初始化常量等

如果我进行测试,

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
...

这样失败的

未初始化常量等

澄清:我根本没有更改此代码,并且它以前在当前状态下工作过

我搞砸了可能是什么? :)

更新: 现在安装的 Ruby 版本是 1.8.7

更新 2:

如果我尝试为 rubygemsetc 手动添加 require > 它失败了,但抱怨另一个包。所以我认为我的红宝石核心有一些根本性的混乱。

/usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependency.rb:55: 未初始化常量 ActiveSupport::Dependency::Mutex (NameError) 从 /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in gem_original_require' 从 /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:in gem_original_require' 从 /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:in gem_original_require' 从 /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in需要' 来自 /var/hda/platform/html/script/install-app:70

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:in
require'
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:in
require'
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:in
require'
from /var/hda/platform/html/script/install-app:70

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

吲‖鸣 2024-12-08 06:23:41

结果是 Rails 和 Gems 的版本太新了。降级至 gems 1.3.7rails 2.3.8

gem update --system 1.3.7

gem uninstall rails

gem install rails --version 2.3.8

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
南冥有猫 2024-12-08 06:23:41

您似乎缺少 require 'rubygems'require 'etc' (将它们放在 require 'optparse' 下面)

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

芯好空 2024-12-08 06:23:41

记住“rubygems”,

命令行:

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

脚本:

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

remember about 'rubygems',

commandline:

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

script:

require 'rubygems'
puts Etc.getpwnam("apache").uid
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文