Just upgraded from Ruby 1.9.1 to 1.9.2 and Passenger (mod_rails) was throwing some crazy errors. The “gem” command was also throwing some errors. Turns out rubygems is trying to read your gems from an old 1.9.1 directory. The fix is to delete everything rubygem-related in /usr/local/lib/ruby/site_ruby/1.9.1/.
Some links for further reading on the issue:
http://www.ruby-forum.com/topic/215219
http://bhuga.net/2010/08/gem-problems-when-upgrading-ruby-192-macports
http://www.ruby-forum.com/topic/213689
The Passenger (mod_rails) error:
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:103: warning: already initialized constant VERSION
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:103: warning: already initialized constant RubyGemsVersion
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:147: warning: already initialized constant MUTEX
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:149: warning: already initialized constant RubyGemsPackageVersion
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:155: warning: already initialized constant WIN_PATTERNS
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:1040: warning: already initialized constant MARSHAL_SPEC_DIR
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:1045: warning: already initialized constant YAML_SPEC_DIR
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:635:in `path': undefined local variable or method `default_path' for Gem:Module (NameError)
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/source_index.rb:68:in `installed_spec_directories'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/source_index.rb:58:in `from_installed_gems'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:883:in `source_index'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/gem_path_searcher.rb:81:in `init_gemspecs'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/gem_path_searcher.rb:13:in `initialize'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:841:in `new'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:841:in `block in searcher'
from :10:in `synchronize'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:840:in `searcher'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:479:in `find_files'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:983:in `load_plugins'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:1139:in `'
from :29:in `require'
from :29:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/passenger-2.2.7/lib/phusion_passenger/utils.rb:25:in `'
from :29:in `require'
from :29:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/passenger-2.2.7/bin/passenger-spawn-server:64:in `rescue in '
from /usr/local/lib/ruby/gems/1.9.1/gems/passenger-2.2.7/bin/passenger-spawn-server:29:in `'
[ pid=2450 file=ext/apache2/Hooks.cpp:725 time=2010-09-03 23:57:34.206 ]:
Unexpected error in mod_passenger: Cannot spawn application '/home/admin/yapruby.simande.com': The spawn server has exited unexpectedly.
Backtrace:
in 'virtual boost::shared_ptr<:application::session> Passenger::ApplicationPoolServer::Client::get(const Passenger::PoolOptions&)' (ApplicationPoolServer.h:471)
in 'int Hooks::handleRequest(request_rec*)' (Hooks.cpp:521)
You get this error message when running “gem” command:
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/source_index.rb:68:in `installed_spec_directories': undefined method `path' for Gem:Module (NoMethodError)
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/source_index.rb:58:in `from_installed_gems'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:883:in `source_index'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/gem_path_searcher.rb:81:in `init_gemspecs'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/gem_path_searcher.rb:13:in `initialize'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:841:in `new'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:841:in `block in searcher'
from :10:in `synchronize'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:840:in `searcher'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:479:in `find_files'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:983:in `load_plugins'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:1139:in `'
from :29:in `require'
from :29:in `require'
from /usr/local/bin/gem:8:in `'
Ever get really confused by the same thing for 10 minutes before realizing “OH I’VE DONE THIS 100 TIMES BEFORE!!!” I hope this note to self will fix it for next time.
Note to self: Before you waste 10 minutes figuring out why a flash[:notice] either a) isn’t working or b) is sticking around for one refresh too long, remember that flash.now works only for the current action and flash[:notice] = ‘forward’ is available for the next action. You know, like a redirect.
Was implementing nested_has_many_through and came across this error:
Cannot dissociate new records through 'Post#post_tags' on '#'. Both records must have an id in order to delete the has_many :through record associating them.
Apparently I needed to use the rails-2.3 branch, which you can install like so:
script/plugin install git://github.com/username/repo.git -r branch_name
Dear WordPress:
Why is there a field in your wp_posts table called guid of type varchar that stores the unique URL for a post? That’s like me hanging a sign on my dog that says “CAT” or painting my rosewill computer red and calling it an “apple.”
Sincerely, E
Gotta love software that’s humble and knows its place. With all these “innovative, industry shaking, market disrupting” social networking web 2.0 iPhone apps out there that are “simple, beautiful, easy-to-use, doesn’t get in the way,” its nice to be reminded by tar that software can be humble.
If you do this, it won’t tar hidden (like .htaccess) files:
tar -cf myfile.tar *
Instead do this:
tar -cf myfile.tar /home/meatloaf/jams
Here’s how to exclude those crazy backups you did:
tar cf sitearchive.tar --exclude=*.sql --exclude=*.gz *
Had to move our 1.5GB SVN repository from one server to another yesterday. Didn’t have enough room to tar, then gzip so I piped:
tar cvf - svn_repository/ | gzip -c > svn.tar.gz
One cool thing about wordpress is that you can get a feed of a specific category by going to /category/category-name/feed or a specific tag by going to /tag/tag-name/feed
require 'open-uri'
require 'hpricot'
doc = Hpricot.parse(open("http://myawesomeblog.com/category/welcome/feed"))
(doc/:item).each do |xml_product|
puts xml_product.search("/title").first.children.first.raw_string
puts xml_product.search("/pubDate").first.children.first.raw_string
end
My hatred of plain FTP is well documented, but I needed change the root directory of a new SFTP user to their home folder (/home/user) so they can’t navigate back to / on the server.
Do your usual create new user stuff:
mkdir /home/steveperry
useradd steveperry
chown root:steveperry /home/steveperry
chmod 755 /home/steveperry
Force the normal login directory just in case:
usermod -d /home/steveperry steveperry
Set the new user a dummy shell (so they don’t have real shell access).
usermod -s /bin/false steveperry
Now, steveperry should have read access to his home directory. Let’s give him a place to upload stuff:
mkdir /home/steveperry/jams
chown steveperry:steveperry /home/steveperry/jams
chmod 755 /home/steveperry/jams
In the file /etc/ssh/sshd_config comment out “Subsystem sftp /usr/lib/openssh/sftp-server” and add “Subsystem sftp internal-sftp”
# Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp internal-sftp
Also in /etc/ssh/sshd_config, add the following lines at the end of the file to force steveperry to be jailed into his home directory.
Match User steveperry
ChrootDirectory /home/steveperry
ForceCommand internal-sftp
Done! Restart the ssh daemon (run this any time you want changes to become effective):
sudo /etc/init.d/ssh restart
(credit, most of this stolen from: http://www.ericstockwell.com/?p=54)
php.ini file location on mac os x is /private/etc/php.ini
to fix this error:
warning: strtotime() [function.strtotime]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier.
add date.timezone = “America/New_York” to your php.ini file.
find / -type f -size +20000k -exec ls -lh {} \; | awk ‘{ print $8 “: ” $5 }’

