One day, one of my refineryCMS installations stopped working.
Application error
Rails application failed to start properly
This was working fine, no changes on my side, but hosted (BlueHost).
The built in Rails Plugins in RefineryCMS (i.e. NewsItem) are not being recognized in the name space.
This should be setup during RefineryCMS Initialization. Need to debug this script:
~/ruby/gems/gems/refinerycms-0.9.5.26/vendor/plugins/refinery/lib/refinery/initializer.rb
Decided to do some reading on rails init process. The web is great eh!
Now back to the problem. Here is the error we see:
~/rap_root# script/console Loading production environment (Rails 2.3.5) ~/ruby/gems/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:105:in `const_missing':NameError: uninitialized constant Rails::Plugin::NewsItem
NewsItem is a RefineryCMS provided object. Something is failing during initialization.
How to debug initialization? Not able to use RAILS_DEFAULT_LOGGER
Time to go back under-cover with Rails.
NewsItem is defined here:
- ~/ruby/gems/gems/refinerycms-0.9.5.26/vendor/plugins/news/app/models/news_item.rb
So, is that being called?
Trying to boot a production server from the terminal shell, we see the top of the stack as:
[~/app_root]# script/server => Booting WEBrick => Rails 2.3.5 application starting on http://0.0.0.0:3000 ~/ruby/gems/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:105:in `const_missing': uninitialized constant Rails::Plugin::NewsItem (NameError) from ~/ruby/gems/gems/refinerycms-0.9.5.26/vendor/plugins/news/rails/init.rb:6:in `evaluate_init_rb' from ~/ruby/gems/gems/refinerycms-0.9.5.26/vendor/plugins/refinery/lib/refinery/plugin.rb:5:in `register' from ~/ruby/gems/gems/refinerycms-0.9.5.26/vendor/plugins/news/rails/init.rb:1:in `evaluate_init_rb' from~/ruby/gems/gems/rails-2.3.5/lib/rails/plugin.rb:158:in `evaluate_init_rb'
Need to get into Rails Debugger and see what is going on.
Refinery copy to Working Host
Since this is getting ugly, we are going to do a quick re-deploy on another Refinery CMS host. Connect to the working Refinery host. Create new repository, setup permissions.
refinery thorstor cd thorstor chgrp -R www-data * chmod -R g+rw *
Before you can get ready for a test on a blank Refinery app, you need to get the DB setup. We will be working with Production only at this time.
mysqladmin -u root create thorstor_production -p
We can also login to the DB and provide access to our DB userID.
mysql -u root -p thorstor_production
Now provide access to your DB login user as configured in RAILS_APP/config/database.yml
CREATE USER 'thorstor'@'localhost' IDENTIFIED BY 'make_a_pass';
GRANT all privileges ON thorstor_production.* TO 'thorstor'@'localhost';
Configure your config/database.yml file to login with the new credentials to the new DB.
vi config/database.yml
Now run “rake db:setup” and test a blank refinery.
Lots of setup takes place:
kthompson@webber:/var/rails/thorstor$ rake db:setup
(in /var/rails/thorstor)
thorstor_production already exists
– create_table(“images”, {:force=>true})
-> 0.3624s
– add_index(“images”, ["parent_id"], {:name=>”index_images_on_parent_id”})
-> 0.0074s
– create_table(“inquiries”, {:force=>true})
-> 0.0871s
– create_table(“inquiry_settings”, {:force=>true})
-> 0.0881s
– create_table(“news_items”, {:force=>true})
-> 0.1044s
– create_table(“page_parts”, {:force=>true})
-> 0.0592s
– add_index(“page_parts”, ["id"], {:name=>”index_page_parts_on_id”})
-> 0.0362s
– add_index(“page_parts”, ["page_id"], {:name=>”index_page_parts_on_page_id”})
-> 0.0873s
– create_table(“pages”, {:force=>true})
-> 0.0881s
– add_index(“pages”, ["custom_title_image_id"], {:name=>”index_pages_on_custom_title_image_id”})
-> 0.0948s
– add_index(“pages”, ["id"], {:name=>”index_pages_on_id”})
-> 0.0090s
– add_index(“pages”, ["image_id"], {:name=>”index_pages_on_image_id”})
-> 0.0882s
– add_index(“pages”, ["parent_id"], {:name=>”index_pages_on_parent_id”})
-> 0.0931s
– create_table(“refinery_settings”, {:force=>true})
-> 0.0038s
– add_index(“refinery_settings”, ["name"], {:name=>”index_refinery_settings_on_name”})
-> 0.0926s
– create_table(“resources”, {:force=>true})
-> 0.0856s
– create_table(“slugs”, {:force=>true})
-> 0.0045s
– add_index(“slugs”, ["name", "sluggable_type", "scope", "sequence"], {:unique=>true, :name=>”index_slugs_on_name_and_sluggable_type_and_scope_and_sequence”})
-> 0.0956s
– add_index(“slugs”, ["sluggable_id"], {:name=>”index_slugs_on_sluggable_id”})
-> 0.0860s
– create_table(“user_plugins”, {:force=>true})
-> 0.0044s
– add_index(“user_plugins”, ["title"], {:name=>”index_user_plugins_on_title”})
-> 0.0116s
– add_index(“user_plugins”, ["user_id", "title"], {:unique=>true, :name=>”index_unique_user_plugins”})
-> 0.0182s
– create_table(“users”, {:force=>true})
-> 0.0065s
– add_index(“users”, ["id"], {:name=>”index_users_on_id”})
-> 0.0082s
– initialize_schema_migrations_table()
-> 0.0111s
– assume_migrated_upto_version(20091207033335)
-> 0.0028s
Attempt to fire up the new rails refinery app. From the shell:
export RAILS_ENV=production
kthompson@webber:/var/rails/thorstor$ script/server
Beauty, that test worked (http://newhost:3000).
Now, to move the official DB from the old host to the new host.
mysqldump -u username -ppassword database_name > dump.sql
Now get the Rails folder from the broken host:
tar -cvf thorstor_20100301a thorstor
Copy that to the new host
scp thorstor_20100301a.tar user@new.host.net:/var/rails/thorstor
scp thorstor_dump-20100301.sql user@new.host.net:/home/user
Now, over to the new host.
First, the restore of the MySQL DB:
mysql -u thorstor -p thorstor_production < thorstor_dump-20100301.sql
Move the tar ball into place and untar it. Update database config as needed.
Hey, it works.