Signals

March 1, 2010

RefineryCMS Breakdown – Initialization Failures

Filed under: new — krisdthompson @ 11:15 am

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.

January 29, 2010

DSCP Markings for VoIP on CiscoIOS Switches

Filed under: new — krisdthompson @ 6:09 pm
QoS Packet and Frame Markings and Trust
VoIP QoS implementation will be based on the Cisco QoS Baseline. However, MGCP which is a call-signaling protocol will be left in the default DSCP (differentiated services code point) value of AF31.
Best practice is to classify, mark, and police as close to the traffic sources as possible.
Switches configured for QOS need to have the following configured on the switch interface:
VoIP Server:
qos trust dscp
VoIP Phone:
qos trust device cisco-phone
qos trust dscp
Note: If using trust COS, be sure to modify the switch defaults to map cos 5 to DSCP 46. Preference is to trust DSCP.
If switch is NOT configured for qos (or mls qos), all packets and frames go through with any DSCP and COS markings left unchanged.
Cisco CallManager, CiscoIOS Voice Gateway, and Unity use the following key protocols for VoIP.

  • RTP- EF – DSCP 46 (0x2E)
    Real-Time Protocol – Voice media
  • MGCP – AF31 – DSCP 26 (0x1A)
    Media Gateway Control Protocol – Voice Gateway Signaling
  • SCCP – CS3 – DSCP 24 (0×18)
    aka Skinny – IP Phone, Unity Ports, Media Resources signaling
  • TFTP – CS3 – DSCP 24 (0×18)
    Trival File Tansfer Protocol – SCCP and MGCP device configuration

The following protocols should also be evaluated for DSCP markings.

  • Interactive/Streaming Video
  • CTI (or JTAPI) – Computer Telephony Integration

Additional traffic flows will be classified at the WAN egress router and remarked for QoS treatment by the MPLS WAN infrastructure.

December 15, 2009

RefineryCMS Quick Deploy

Filed under: new — krisdthompson @ 9:43 am

Needing a web based WYSIWYG type content mgmt system built on rails for small business websites and knowledge repositories.

Decided to use RefineryCMS as it has a good looking model for extending it and a great looking editor (WYMIWG – What You Mean).

RefineryCMS Startup

www.refinerycms.org

http://github.com/resolve/refinerycms/blob/master/README

Ruby Gems install

Start by installing the refineryCMS gem.

gem install refinerycms --source http://gemcutter.org
...
Successfully installed refinerycms-0.9.5.28
...

create new project at new (aka /path/to/project)


refinery /path/to/project

Want ONLY system GEMs and use SUDO to manage them? Modify some settings in .bashrc


~$ grep GEM .bashrc
export GEM_HOME=/usr/lib/ruby/gems/1.8
export GEM_PATH=/usr/lib/ruby/gems/1.8


cd /path/to/project
rake gems:install

In my experience, this did not install the failing gems issues as needed for your platform. However, it does tell you what is missing.


sudo gem install friendly_id will_paginate aasm slim_scrooge
sudo gem install -v 0.8.1 hpricot


gem install rmagick

Lots of errors expressed during the ri and RDoc documentation install.

These required gems are called out in our environment.rb for RefineryCMS
friendly_id >= 2.2.2
will_paginate >= 2.3.11
aasm >= 2.1.3
unicode >= 0.1
slim_scrooge >= 1.0.3
hpricot = 0.8.1

Again, try “rake gems:install”.
Setup ~/config/database.yml for DB acces

DB Configuration

Edit database.yml to point to correct DB adapter and login.

You may need to create the databases from the Database console, or perhaps use “rake db:create”.

user@host:/var/rails/voip$ mysql -uroot -p
..
mysql> create database project_development;
mysql> create database project_production
mysql> grant all privileges on voip_production.* to ‘user’@'localhost’;
mysql> grant all privileges on voip_development.* to ‘user’@'localhost’;

Image Magick

You will need the ImageMagick libraries on the linux host.
You can then install the RMagick gem


sudo aptitude install imagemagick
sudo aptitude install libmagick9-dev
sudo gem install rmagick

Internet reports finding the correct parts to support rmagick in various debian packages. Find it with: sudo apt-cache search libmagick

We will also need to run out setup tasks in RAILS_ENV=production. i.e.:


export RAILS_ENV=production
rake gems:install

It now runs clean (no errors)

Next step is to load schema, then seed DB. Be sure you are running in Production DB mode.

One more fix for environment.rb


vi config/environment.rb
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION


rake db:load:schema
rake db:seed

To db:seed to the production DB, you may need:
rake db:seed RAILS_ENV=production

** Worked

Web Hosted Notes

Need to:
* add dispatch.fcgid
* edit .htaccess per:
** http://helpdesk.bluehost.com/index.php/kb/article/207


# General Apache options
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)/!$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
ErrorDocument 500 "

Application error

Application failed to start properly"

Link up your Web hosting directory (domain or sub-domain) to a softlink to your public directory.
ln -s ~/ror/appname/public ~/public_html/sitename

Also needed to add GEM_PATHS to: ~/ror/appname/config/environment.rb


ENV['GEM_PATH']='/home/penguin/ruby/gems:/usr/lib/ruby/gems/1.8'

Point to local GEMs first.

Apache SubDir

Using Apache - Phusion Passenger.

Create a softlink to the Public folder of the new target App.
/var/www$ sudo ln -s /var/rails/voip/public voip

And a corresponding RailsBaseURI in the site config:

/etc/apache2/sites-enabled$ grep voip 000-default
RailsBaseURI /voip

Restart the Apache daemon. Ubuntu style:
sudo invoke-rc.d apache2 restart

December 14, 2009

Ruby on Rails Setup for Mac-mini G4 (10.5)

Filed under: new — krisdthompson @ 10:35 am

Mac – Add Rails

Mac Rails Install (upgrade?)
Starting with mac-mini – G4 – 10.5.8 – Ruby 1.8.6 – Rails 1.2.6

From: http://developer.apple.com/tools/developonrailsleopard.html

sudo gem update –system
** takes a good while to complete

sudo gem install rails
** takes a long time to “start”
We get:
Successfully installed rake-0.8.7
Successfully installed activesupport-2.3.5
Successfully installed activerecord-2.3.5
Successfully installed rack-1.0.1
Successfully installed actionpack-2.3.5
Successfully installed actionmailer-2.3.5
Successfully installed activeresource-2.3.5
Successfully installed rails-2.3.5
8 gems installed
+ ri and RDoc for each.

gem sqlite3-ruby
================
sudo gem update sqlite3-ruby
** Need Ruby Headers. Install XCODE 3.1.4 for Leopard.
* Upgrade SQLITE3. Will also need xcode first.

$ curl -O http://sqlite.org/sqlite-amalgamation-3.6.21.tar.gz
$ tar xzf sqlite-amalgamation-3.6.21.tar.gz
$ cd sqlite-3.6.421
$ ./configure –prefix=/usr/local
$ make
$ sudo make install

Now this runs:
sudo gem update sqlite3-ruby

Seems we need RMagick which requires MacPorts and imagemagick.

X11 already installed with XCode 3.1.4 (Leopard – 10.5)

sudo port install tiff -macosx imagemagick +q8 +gs +wmf
- that took many hours to complete

sudo gem install rmagick
(ignore ? many No definition errors in RI install for this gem)

Installing ri documentation for rmagick-2.12.2…
No definition for Magick_colors
No definition for Magick_fonts
No definition for Magick_init_formats

Now ready for RefineryCMS Install (add link)

December 7, 2009

404 Not Found – your wiki is gone

Filed under: new — krisdthompson @ 3:36 pm

Just be sloppy with your scripts (especially plugins) and presto, no more Wiki automated by google bots and the need to know all.

66.249.68.116 – - [05/Dec/2009:16:32:27 -0700] “GET /wiki-bin/publish?file=wiki&verb=delete HTTP/1.1″ 200 11272 “-” “Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)”

And presto, no more “wiki” directory. Did I ever f**k up leaving that exposed.

Thanks for the help Google-bot!

In ecology terms, this would be part of the “Tragedy of the Commons”. For the good of the public, all the HTML form options had to be exercised thereby destorying a shared resource.

http://en.wikipedia.org/wiki/Tragedy_of_the_commons

The real problem here is the code and our stupidity to not put authentication on that script or disable the delete function altogether. If the script had respected RESTful design, a GET verb cannot lead to a destroy function on the host.

Critical Take Away:

  • Always consider that any code exposed to the internet is fair game for manipulation by external agents in any way for their purposes.
  • Be sure to keep backups.
  • Better be sure to review and lock down any new software introduced for potential vulnerabilities.

November 19, 2009

Cisco VPN Client: Where is my PCF?

Filed under: new — Tags: — krisdthompson @ 8:32 am

On MacOS:

/private/etc/opt/cisco-vpnclient/Profiles/<ConnectionName>.pcf

On Windows:

C:\Program Files\Cisco Systems\VPN Client\Profiles\<ConnectionName>.pcf

October 21, 2009

Rails – Rake Legacy Production DB to Development

Filed under: new — krisdthompson @ 2:34 pm

In order to develop against production databases, I have several kinds of databases defined in database.yml


development:
  adapter: blah
  ..
test:
  adapter: blah
  ..
production:
  adapter: blah
  ..
legacya_development:
  adapter: blah
  ..
legacya_test:
  adapter: blah
  ..
legacya_production:
  adapter: blah

These are attached to from the Rails Models with something like:

class LegacyaCustomer < ActiveRecord::Base
  dbname = ("legacya_" + ENV['RAILS_ENV']).to_sym
  establish_connection dbname
  set_table_name "customer"
  ..
end

In order to enable migration from an existing DB Schema (legacy_production) to a Dev instance of same, I created two Rake tasks as follows:

RAILS_ROOT/lib/tasks/db-legacy.rake:

namespace :db do
  namespace :schema do
    desc "Create a db/_schema.rb from DBNAME_production. Append DBNAME=_nameindatabase.yml_ to Rake command execution."
    task :dump_legacyprod => :environment do
      dbname = ENV["DBNAME"]
      require 'active_record/schema_dumper'
      File.open("db/#{dbname}_schema.rb", "w") do |file|
        config = ActiveRecord::Base.configurations["#{dbname}_production"]
        ActiveRecord::Base.establish_connection(config)
        ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
      end
    end
    desc "Create a development database matching db/. Append DBNAME=_nameindatabase.yml_ to Rake command execution."
    task :load_legacydev => :environment do
      dbname = ENV["DBNAME"]
      file = "#{RAILS_ROOT}/db/#{dbname}_schema.rb"
      if File.exists?(file)
        config = ActiveRecord::Base.configurations["#{dbname}_development"]
        ActiveRecord::Base.establish_connection(config)
        load(file)
      else
        puts "Schema File Not Found: #{file}"
      end
    end
  end
end

Now, once the development database is created and configured in database.yml, you can create the matching schema with these two commands:

rake db:schema:dump_legacyprod DBNAME=legacya
rake db:schema:load_legacydev DBNAME=legacya

Next steps are load fixture (seed) data and sample data to aid in development.

Can Rails Test be made friendly to our Legacy_Test databases as well?

October 1, 2009

MSSQL (SQLSERVER) from the command-line

Filed under: new — krisdthompson @ 1:01 pm

TIPS for access to MSSQL (aka SQLSERVER in typical generic microsoft branding), from the command-line for us terminal bigots.

If using FreeTDS (no small task, a subject for another post after FreeTDS revisited), you should have the command line tool “tsql”.

Using tsql command line (isql ??) to access mssql.

tsql -H hostname -p portnum -U username -P password

Or


iodbctest "DSN=helpdeskprod;UID=svc_debugger;PWD=AndS0m3"

Check those ODBC names /Library/ODBC/odbc.ini as needed.

Using TSQL and IODBCTEST

Tip: When using tsql, use the “go” statement to terminate and execute your command.


1> sp_tables @table_name ="c%"
2> go

With IODBCTEST you do not need to use a “go” or a semi-colon.

List Tables

select TABLE_NAME from information_schema.tables where table_type='BASE TABLE'

Inspect columns

sp_columns puts out an incredible amount of data about each column (try sp_columns customer).

Here we ask for just the column name and data_type.


SELECT column_name, data_type
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name='customer'

Thanks for the mssql sp_stuff tips:

September 17, 2009

MySQL Admin: Create User – Grant Rights – Don’t Use Root

Filed under: new — krisdthompson @ 12:13 pm

Login to MySQL using your root user created during install (should have a password assigned).

mysql -u root -p mysql


CREATE USER 'goober'@'localhost' IDENTIFIED BY 'make_a_pass';
create database cat_dev;
GRANT all privileges ON cat_dev.* TO 'goober'@'localhost';

Linux Admin: Install Subversion and Git on Debian

Filed under: new — Tags: — krisdthompson @ 12:07 pm

This technote only covers install of the Subversion and Git clients.
Debian Version: 5.0.3

Opeongo.net tips pages for Subversion:

Install Subversion

sudo aptitude install subversion

Older Posts »

Powered by WordPress