“未初始化常量Etc”运行 Ruby 应用程序时
我的服务器上依赖 Ruby 和 Ruby 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:
如果我尝试为 rubygems 和 etc 手动添加 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:ingem_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:ingem_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:ingem_original_require'
require'
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in
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:ingem_original_require'
require'
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in
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:ingem_original_require'
require'
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in
from /var/hda/platform/html/script/install-app:70
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
结果是 Rails 和 Gems 的版本太新了。降级至 gems 1.3.7 和 rails 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.
您似乎缺少
require 'rubygems'
和require 'etc'
(将它们放在require 'optparse'
下面)You seem to be missing
require 'rubygems'
andrequire 'etc'
(put them belowrequire 'optparse'
)记住“rubygems”,
命令行:
脚本:
remember about 'rubygems',
commandline:
script: