2012-11-14 85 views
0

我正在使用postgresql在debian服務器上部署我的第一個railsapp。rake db:由於postgresql_adapter.rb而重置失敗

的Rails 3.2.9 的Ruby 1.9.3-P327 第0.14.1

部署後,當我做了

bundle exec rake db:reset

失敗與以下錯誤:

/var/www/opf/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:1208: [BUG] Segmentation fault 

和一長串錯誤消息。

雖然我的database.yml的是在我的開發worksation正常工作:

爲什麼postgresql_adapter導致一個錯誤,我不能找到一個理由。

---更新

如果我把不正確的數據庫名稱,用戶名和密碼,結果是一樣的。 我測試了與psql my_db my_user的數據庫連接,它的工作原理。 如果我做了

bundle exec rake db:reset RAILS_ENV=production

我得到了一個錯誤:

undefined method `sass' for #<Rails::Application::Configuration:0x00000000dea738> 

雖然薩斯青菜護欄HAML護欄寶石出現在我的/ var/www/opf/shared/bundle/ruby​​/1.9.1/gems

====== UPDATE =======

這是我的database.yml:

development: 
    host: localhost 
    port: 5432 
    adapter: postgresql 
    encoding: utf8 
    database: mydevdb 
    pool: 5 
    username: myuser 
    password: mypass 

test: 
    host: localhost 
    port: 5432 
    adapter: postgresql 
    encoding: utf8 
    database: mytestdb 
    pool: 5 
    username: myuser 
    password: mypass 

production: 
    host: localhost 
    port: 5432 
    adapter: postgresql 
    encoding: utf8 
    database: myproddb 
    pool: 5 
    username: myuser 
    password: mypass 

這是我的Gemfile:

source 'https://rubygems.org' 

gem 'rails', '~>3.2' 
# Ressource : https://github.com/ged/ruby-pg 
gem 'pg', '>= 0.14' 
# https://github.com/indirect/haml-rails 
gem 'haml-rails', '~> 0.3' 

group :developpement do 
    # Ressource : https://github.com/rspec/rspec-rails 
    gem 'rspec-rails', '>= 2.11' 
    # Ressource : https://rvm.io//integration/capistrano/ 
    gem 'capistrano', '>= 2.12' 
    # Ressource : https://github.com/btelles/faker 
    gem 'faker', '>= 1.0' 
    # Ressource : https://rvm.io//integration/capistrano/ 
    gem 'rvm-capistrano' 
end 

group :test do 
    gem 'rspec', '>= 2.11' 
    gem 'webrat', '>= 0.7' 
    gem 'spork-rails', '>= 3.2' 
    gem 'factory_girl_rails', '>= 4.0' 
end 

group :assets do 
    # Faciliter la rédaction de feuilles de style CSS 
    # Ressource : http://sass-lang.com/ 
    gem 'sass-rails', '>= 3.2.3' 
    gem 'coffee-rails', '>= 3.2.1' 
    # Ressource : http://compass-style.org/ 
    gem 'compass-rails', '>= 1.0' 

    # See https://github.com/sstephenson/execjs 
    #readme for more supported runtimesa 
    # execjs and therubyracer are ncessary for compass-rails gem to work properly 
    gem 'execjs' 
    gem 'therubyracer', :platforms => :ruby 

    gem 'uglifier', '>= 1.0.3' 
end 

gem 'jquery-rails' 
# Ressource : https://github.com/ctran/annotate_models 
gem 'annotate' 
# Ressource : https://github.com/asanghi/excel_rails 
gem 'excel_rails', '~> 0.3' 
# Ressource : https://github.com/voraz/spreadsheet 
gem 'spreadsheet', '~> 0.7' 
# Ressource : https://github.com/lomba/schema_plus 
gem 'schema_plus', '~> 0.4' 
# Resource : https://github.com/tchandy/octopus 
gem 'ar-octopus', '~> 0.3' 
# Resource : https://github.com/ernie/squeel 
gem 'squeel', '~> 1.0' 
# Resource : https://github.com/plataformatec/devise 
gem 'devise', '~> 2.1' 
# Resource : https://github.com/martinrehfeld/role_model 
gem 'role_model' 
# Resource : https://github.com/stffn/declarative_authorization 
gem 'declarative_authorization' 
# Resource : https://github.com/francesc/rails-translate-routes 
gem 'rails-translate-routes', '~> 0.1' 

我做更多的測試,並意識到問題來自初始化過程。 在某些時候,我的應用的初始化會導致Ruby解釋器崩潰。 我刪除了我的config/application.rb的一些行。結果至少將崩潰更改爲關於「單元化常量設計」的錯誤。我搜索了一下,發現我添加了在我的application.rb中添加一個「require」devise'「。所以我做了,但錯誤和Ruby崩潰再次來了。

該問題似乎以某種方式與資產管道和初始化相關聯。 我注意到以下行讓我初始化崩潰Ruby解釋器,所以我評價它:

Bundler.require(*Rails.groups(:assets => %w(development test))) 

我的配置/應用。RB:

require File.expand_path('../boot', __FILE__) 

# Pick the frameworks you want: 
require "active_record/railtie" 
require "action_controller/railtie" 
require "action_mailer/railtie" 
require "active_resource/railtie" 
require "sprockets/railtie" 
# require "rails/test_unit/railtie" 

# Without this I got a "unitialized Constant Devise" error 
require 'devise' 

# THIS ALL STUFF MAKES CRASH RAILS INITIALIZATION, so I commented it. 
if defined?(Bundler) 
    # If you precompile assets before deploying to production, use this line 
    #Bundler.require(*Rails.groups(:assets => %w(development test))) 
    # If you want your assets lazily compiled in production, use this line 
    # Bundler.require(:default, :assets, Rails.env) 
end 

module Opf 
    class Application < Rails::Application 
    # Settings in config/environments/* take precedence over those specified here. 
    # Application configuration should go into files in config/initializers 
    # -- all .rb files in that directory are automatically loaded. 

    # Custom directories with classes and modules you want to be autoloadable. 
    # config.autoload_paths += %W(#{config.root}/extras) 

    # Only load the plugins named here, in the order given (default is alphabetical). 
    # :all can be used as a placeholder for all plugins not explicitly named. 
    # config.plugins = [ :exception_notification, :ssl_requirement, :all ] 

    # Activate observers that should always be running. 
    # config.active_record.observers = :cacher, :garbage_collector, :forum_observer 

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 
    # config.time_zone = 'Central Time (US & Canada)' 

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 
    # Pour utiliser la traduction française des messages d'erreur standards 
    config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 
    config.i18n.default_locale = 'fr' 

    # Configure the default encoding used in templates for Ruby 1.9. 
    config.encoding = "utf-8" 

    # Configure sensitive parameters which will be filtered from the log file. 
    config.filter_parameters += [:password] 

    # Enable escaping HTML in JSON. 
    config.active_support.escape_html_entities_in_json = true 

    # Use SQL instead of Active Record's schema dumper when creating the database. 
    # This is necessary if your schema can't be completely dumped by the schema dumper, 
    # like if you have constraints or database-specific column types 
    config.active_record.schema_format = :sql 

    # Enforce whitelist mode for mass assignment. 
    # This will create an empty whitelist of attributes available for mass-assignment for all models 
    # in your app. As such, your models will need to explicitly whitelist or blacklist accessible 
    # parameters by using an attr_accessible or attr_protected declaration. 
    config.active_record.whitelist_attributes = true 

    # Enable the asset pipeline 
    config.assets.enabled = true 

    # Version of your assets, change this if you want to expire all your assets 
    config.assets.version = '1.0' 

    # ======= DEBUG : without this, Capistrano Assets:precompile crash ======== 
    config.assets.initialize_on_precompile = false 
    # ============================================================== 

    # Make crashing Initialization, so I commented 
# config.generators do |g| 
#  g.test_framework :rspec 
#  g.fixture_replacement :factory_girl 
#  g.stylesheets false 
     # cette option ne doit pas être activée car elle est géré (et activée) par la gem 'haml-rails' 
#  # g.template-engine :haml 
# end 

# config.sass.preferred_syntax = :sass 

    # To replace 'div' by 'span' within error-feedbacks 
    config.action_view.field_error_proc = Proc.new do |html_tag, instance| 
     # Ressources : http://stackoverflow.com/questions/5267998/rails-3-field-with-errors-wrapper-changes-the-page-appearance-how-to-avoid-t 
     # Ressources : Railcast : http://railscasts.com/episodes/39-customize-field-error?autoplay=true 
     class_attr_index = html_tag.index('class="') 
     if class_attr_index 
     html_tag.insert class_attr_index+7, 'field_with_errors ' 
     else 
     html_tag.insert html_tag.index('>'), ' class="field_with_errors"' 
     end 
    end 
    end 
end 

的successfuls試驗的概要的myapp:

  • PostgreSQL數據庫用戶訪問和等於的database.yml = WORK
  • 在@global寶石
  • 寶石存在= CHECK
  • 創建直接在服務器上從頭開始「測試」應用程序= WORK
+0

發佈您的database.yaml文件,我可以問,你在本地開發運行服務器沒有問題? – Thanh

+0

您是否嘗試過在沒有bundle exec的情況下運行該命令?另外,你可以顯示你的Gemfile的內容嗎? –

+0

@ Kien:應用程序在我的開發站上像魅力一樣運行。我將用database.yml更新 – Douglas

回答

0

Ok af在進行一些非常糟糕的研究和測試之後,我找出了問題的原因。

有幾個錯誤:

  • 在這種execjs寶石正常工作秩序,

    gem 'therubyracer', :platforms => :ruby

必須在生產組或任何一組在外面的的Gemfile

  • 爲了預編譯嵌套的SASS-CSS資產(rake assets:precompile),清單(評論)必須在app/assets/stylesheets/application.css.sass的頂部被刪除(我使用sass-rails和haml -rails寶石),和I had to add the line

    @import screen.css.sass

在我的應用程序/資產/樣式表/ application.css.sass文件

  • 爲了打捆機工作正常,我在「創業板安裝捆綁」得到了一個消息添加在我的/ etc/profile文件和文件/root/.bashrc中對$PATH:服務器端。

  • 爲了使capistrano deploy:update任務正常工作,不要忘記在config/deploy.rb文件中添加require 'rvm/capistrano',以便capistrano能夠找到(並執行)bundle命令。

但與所有這些修正,我還是得到了同樣的錯誤在PostgreSQL:

/var/www/opf/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:1208: [BUG] Segmentation fault 

正如我爲了避免存儲的database.yml在github上正在使用此特殊recipe。 並使用此solution爲了capistrano找到我的食譜文件。 我爲這個配方構建了一個database.yml模板,但不知何故,我意識到問題來自於我的模板。

,我不得不刪除每個數據庫上這兩條線,以軌道初始化工作正常:

host: localhost 
    port: 5432 

也許造成的database.yml是腐敗的,我沒有測試重新添加這些(校正)兩條線。我已經花了數週時間...

---一般建議---

現在我給一些建議給開發商誰是desesparate找到解決他們的問題(像我)搜索解決方案的公平大寫金額後停止。

剛剛建立與rails new newapp --database=postgresql(數據庫參數使用rails new -h對於此命令的幫助)一個新的極軌基本應用程序,然後生成rails generate scaffold mymodel mycolumn一個簡單的支架。

在你的應用程序目錄,初始化的Git與git init和Capistrano的與capify . 然後,只需添加寶石爲您的數據庫(PG例如對PostgreSQL),運行捆綁安裝。 然後用你自己的基本database.yml將它連接到你的數據庫,讓你測試看看它在你的開發工作站上的工作。 提交併推送到您的Git存儲庫,然後部署與capistrano並檢查它在服務器端工作。

然後逐漸添加(gems,migrations和您自己的個人庫)到您的newapp,直到它不起作用。

並行地將工作從newapp工作的位添加到服務器端的失敗應用程序直到它工作(不要在您的開發工作站上更改應用程序上的任何內容)。

這會引導您遲早地找到解決方案。

相關問題