Archive for the ‘Uncategorized’ Category

My Upgrade to Snow Leopard Journey

After the upgrade I had a ton of issues getting my rails environment back online which I could have avoided IF I just would have uninstalled all my ports.

The problem was that I had both Ruby 1.8.6 and 1.8.7 installed as ports and that was conflicting to the new 1.8.7 that was installed from the upgrade. I could not get passenger to boot after the upgrade…

SO what I did was upgrade xcode, upgrade port then force uninstall ALL ports and install the ports that I wanted. (Reboot 🙂 ) and then I installed the passenger gem using the native 1.8.7 Ruby install.

Getting paperclip to work with passenger not running under root

After moving from Thin to passenger to save memory on one of my VM (with only 256mb every byte counts… ) I could not get paperclip to re-size images.

This was the error I got:
[paperclip] An error was received while processing: #
[paperclip] Processing medium # in the thumbnail processor.
[paperclip] An error was received while processing: #

The problem was permissions on the rails tmp directory. When I deploy using Capistrano the RAILS_ROOT/tmp directory is cleared-out so the .ruby_inline setup is re-initialized by the root user. Since I don’t run Passenger as root this throws the error above. Here is how I get around this without logging in to the server after deploy and executing a chown command:

In my RAILS_ROOT/config/environments/production.rb file I added this to the bottom:

temp =‘ruby_inline’, ‘/tmp’)
dir = temp.path
Dir.mkdir(dir, 0755)

This replaced the old setup that I had:
ENV[‘INLINEDIR’] = File.join(RAILS_ROOT, ‘tmp’)

So now I delete the .ruby_rails directory with the wrong permissions and create a new directory with the rails user… nice!

where does the php.ini file go?

The Problem

I needed to add more memory to php but by default php installed from source (configure && make && make install) does NOT install the php.ini file. So where is waldo?

The Fix

Here is a code snip that shows what configuration file IS loaded when php is executed:

[root@mybox php-5.2.10]# php -r "phpinfo();" | grep Configuration
Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => (none)

This shows that the php.ini path is in /usr/local/lib. So I grabbed the php.ini-recommended, copied that file to /usr/local/lib/php.ini and this file has the memory_limit set to 128MB which should be enough for now….

[root@mybox php-5.2.10]# php -r "phpinfo();" | grep Configuration
Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => /usr/local/lib/php.ini


Fancy Mac (OS-x) Prompt

The Problem

Boring promt

The Fix

– Open a Terminal window.

– Edit your .profile or create a file like so vi ~/.profile

Add the following to the file:

alias vi=’vim’
4 alias ol=’ssh root@′
5 #alias cade=’ssh′
6 alias cade=’ssh′
7 alias oce=’ssh root@′
9 # colors
10 export CLICOLOR=1
11 export TERM=xterm-color
12 export LSCOLORS=gxgxcxdxbxegedabagacad  # cyan directories
13 export PS1=’\[33[01;32m\]\u@\h\[33[00m\]:\[33[01;36m\]\w\[33[00m\]\$ ‘

# Starts the extended vi when using vi
alias vi=’vim’
# Nice listing using ll
alias ll=’ls -Alhp’

export CLICOLOR=1
export TERM=xterm-color
# Information about the colors at the bottom of the article
export LSCOLORS=gxgxcxdxbxegedabagacad  # cyan directories
export PS1=’\[33[01;32m\]\u@\h\[33[00m\]:\[33[01;36m\]\w\[33[00m\]\$ ‘

This will make sure that you prompt will have ansi colors and look something like this:
freddy@svn:~/Documents$ ll drwxr-xr-x  17 freddy  staff   578B Feb 10  2008 cadechristian.com_project/ -rw-r--r--@  1 freddy  staff   112K Mar  1  2008 server.docx drwxrwxrwx   4 freddy  staff   136B Jan 28  2008 server_backup/ -rw-r--r--@  1 freddy  staff   559K Mar  3  2008 sunJVM-on-intel-multicoreservers.pdf -rw-r--r--@  1 freddy  staff   556K Mar  1  2008 tomcat_performance_tuning_20071015.ppt freddy@svn:~/Documents$ 

LSCOLOR information

These are the available ANSI colors:

a     black
b     red
c     green
d     brown
e     blue
f     magenta
g     cyan
h     light grey
A     bold black, usually shows up as dark grey
B     bold red
C     bold green
D     bold brown, usually shows up as yellow
E     bold blue
F     bold magenta
G     bold cyan
H     bold light grey; looks like bright white
x     default foreground or background 

Note that the above are standard ANSI colors. The actual display may differ depending on the color capabilities of the terminal in use. The order of the attributes in the LSCOLORS variable is as follows:

  1. directory
  2. symbolic link
  3. socket
  4. pipe
  5. executable
  6. block special
  7. character special
  8. executable with setuid bit set
  9. executable with setgid bit set
  10. directory writable to others, with sticky bit
  11. directory writable to others, without sticky bit

They are set in pairs, foreground (f) then background (b), i.e. fbfbfbfbfbfbfbfbfbfbfb for all 11 settings. The default is exfxcxdxbxegedabagacad, i.e. blue foreground and default background for regular directories, black foreground and red background for setuid executables, etc. and perl module issue

The problem

[nagios@den2lweb002 libexec]$ ./
Can’t locate LWP/ in @INC (@INC contains: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib64/perl5/site_perl/5.8.7/x86_64-linux-thread-multi /usr/lib64/perl5/site_perl/5.8.6/x86_64-linux-thread-multi /usr/lib64/perl5/site_perl/5.8.5/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/5.8.7 /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib64/perl5/vendor_perl/5.8.7/x86_64-linux-thread-multi /usr/lib64/perl5/vendor_perl/5.8.6/x86_64-linux-thread-multi /usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl/5.8.7 /usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .) at ./ line 32.
BEGIN failed–compilation aborted at ./ line 32.

[nagios@myserver libexec]$ ./ -H localhost

Can’t locate LWP/ in @INC (@INC contains: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib64/perl5/site_perl/5.8.7/x86_64-linux-thread-multi /usr/lib64/perl5/site_perl/5.8.6/x86_64-linux-thread-multi /usr/lib64/perl5/site_perl/5.8.5/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/5.8.7 /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib64/perl5/vendor_perl/5.8.7/x86_64-linux-thread-multi /usr/lib64/perl5/vendor_perl/5.8.6/x86_64-linux-thread-multi /usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl/5.8.7 /usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .) at ./ line 32.

BEGIN failed–compilation aborted at ./ line 32.

The fix

Lets find the missing LWP/ module. After searching around on Google I could not find that module alone but I found the Bundle::LWP, so I started this command after a quick su to root…

[root@myserver libexec]# perl -MCPAN -e ‘install Bundle::LWP’

And after about 2 minutes the bundle was installed

Then I dropped back to the nagios user and tested the command again…

[nagios@myserver libexec]$ ./ -H localhost

HTTPD ok: average response time 184 milliseconds

We are back in business!

Versions used

  • Linux Red Hat Enterprise Linux Server release 5.3
  • Perl v5.8.8 built for x86_64-linux-thread-multi
  • Ground Works 5.3 community edition

Eclipse MemoryAnalyzer Exit Code=-1

I was looking for a nice tool to read java heap dumps and found that regular JHat was not a great way to go with the 1.6GiB dump files I have. A friend pointed me to a Eclipse project Memory Analyzer (MAT) which is the old SAP analyzer…

Starting it up I got the Exit Code=-1 error and found that this tool is currently not working with java 1.6.x on a mac. If you want to force the tool to use 1.5 open a terminal window and follow these instructions:
freddy@svn:~/mat/$ pwd
freddy@svn:~/mat/$ vi Info.plist
Uncomment this line:
… eworks/JavaVM.framework/Versions/1.5.0/Commands/java
This will force the use of Java 1.5!

uninitialized constant CGI::Session (NameError)

After upgrading one project to Rails 2.3.2 I got an error on startup uninitialized constant CGI::Session (NameError)

Looking into the source I found that I was loading this class CGI::Session::ActiveRecordStore::Session
After a little hunting on Google I was directed to the Rails release notes and found this section:
script/server has been switched to use Rack, which means it supports any Rack compatible server. script/server will also pick up a rackup configuration file if one exists. By default, it will look for a file, but you can override this with the -c switch.
CGI::Session::ActiveRecordStore has been replaced by ActiveRecord::SessionStore.

Monitoring thins with monit…

Short story:

Download and install the latest code from (configure, make, make install.. done! )
edit /etc/monitrc
# ========================================================
# Monit global settings:
# ========================================================
set daemon 60
set logfile syslog
set mailserver localhost
set mail-format { from: }
# ========================================================
# Monit http server settings:
# ========================================================
set httpd port 2812
allow localhost
INCLUDE “/etc/monit/thins.monitrc”

check process thin-8000 with pidfile /app/shared/pids/
group rails
start program = “/usr/local/bin/thin -C /app/current/config/thin_cluster.yml start –only 8000”
stop program = “/usr/local/bin/thin -C /app/current/config/thin_cluster.yml stop –only 8000”
if failed host localhost port 8000 protocol HTTP
request “/token/monit” with timeout 60 seconds then restart
if cpu is greater than 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if totalmem > 100.0 MB for 5 cycles then restart
if loadavg(5min) greater than 10 for 8 cycles then stop
if 5 restarts within 5 cycles then timeout
depends on thin_bin

check file thin_bin with path /usr/local/bin/thin
group rails
if failed checksum then unmonitor
if failed permission 755 then unmonitor
if failed uid root then unmonitor
if failed gid root then unmonitor

Thats the setup now the ISSUE!

Monit would NOT start thin, and the error I was looking at in the thin log was:
/usr/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/rails_generator/lookup.rb:35:in `expand_path’: couldn’t find HOME environment — expanding `~’ (ArgumentError)
from /usr/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/rails_generator/lookup.rb:35:in `user_home’
from /usr/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/rails_generator/lookup.rb:114:in `use_component_sources!’
from /usr/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/rails_generator/lookup.rb:55:in `included’
from /usr/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/rails_generator.rb:38:in `include’
from /usr/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/rails_generator.rb:38:in `send’
from /usr/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/rails_generator.rb:38
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require’
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require’
… 26 levels…
from /usr/local/lib/ruby/gems/1.8/gems/thin-1.0.0/lib/thin/runner.rb:139:in `run!’
from /usr/local/lib/ruby/gems/1.8/gems/thin-1.0.0/bin/thin:6
from /usr/local/bin/thin:20:in `load’
from /usr/local/bin/thin:20

I did not want to have a “startup” script hanging around SO I added this in my /usr/local/bin/thin file:

ENV[“HOME”] = “/tmp”

Problem solved!

Mac(OSX) Jruby and Rails 2.2 — Part 2

Running webrick isn’t doing what we want… How about Tomcat? Or maybe Glassfish? Well I have heard that glassfish is VERY EASY, lets checkit out…

Step 1:
~$ sudo jruby -S gem install glassfish
Successfully installed glassfish-0.9.0-universal-java
1 gem installed
Installing ri documentation for glassfish-0.9.0-universal-java…
Installing RDoc documentation for glassfish-0.9.0-universal-java…

DONE… no I’m serious… THAT WAS IT!!!

Lets start the server:

~$ jruby -S glassfish_rails myapp
Nov 17, 2008 7:21:23 PM com.sun.enterprise.glassfish.bootstrap.ASMain main
INFO: Launching GlassFish on Apache Felix OSGi platform
Nov 17, 2008 7:21:23 PM com.sun.enterprise.glassfish.bootstrap.ASMainOSGi findDerbyClient
INFO: Cannot find javadb client jar file, jdbc driver not available

Now I can access the rails app at http://localhost:3000/


Here is some more information about the glassfish gem:

-c, –contextroot PATH: change the context root (default: ‘/’)
-p, –port PORT: change server port (default: 3000)
-e, –environment ENV: change rails environment (default: development)
-n –runtimes NUMBER: Number of JRuby runtimes to crete initially
–runtimes-min NUMBER: Minimum JRuby runtimes to crete
–runtimes-max NUMBER: Maximum number of JRuby runtimes to crete
APPLICATION_PATH (optional): Path to the application to be run (default:

This is almost too easy for a development environment…

THIS IS NOT A BENCHMARK BUT even so here is the info…

My laptop with a test app I have and seed data installed thin 1.0 and Glassfish…

With threading:
Requests per second: Thin 10 [#/sec]
Requests per second: Glassfish 14 [#/sec]

Without threading:
Requests per second: Thin 3 [#/sec]
Requests per second: Glassfish 2.6 [#/sec]

🙂 Not what I was hoping for …

Mac(OSX) Jruby and Rails 2.2

Not Sure why but I wanted to try JRuby and Rails(2.2) new threads…

These are the steps I used to get a application on my mac running with Rails 2.2 and JRuby 1.1.3(I used ports to install JRuby thats why 1.1.3).

Here are the steps:

– First Install JRuby .. # sudo port install jruby

– Fix an annoying warning .. # sudo jruby -S gem install jruby-openssl

– Install rails .. # sudo jruby -S gem install rails

– Install the database connector .. # sudo jruby -S gem install activerecord-jdbc-adapter

– Upgrade the gem environment .. # sudo jruby -S gem update

– Install latest RubyGems (Rails 2.2 Needs 1.3.1 or higher.. ) .. # sudo jruby -S gem install rubygems-update

– Now you have to force install the update .. # sudo jruby -S update_rubygems

– Install Rails 2.2.1 .. # jruby -S gem install rails -s

# jruby -S rails myapp
# cd myapp
# vi config/database.yml

adapter: jdbc
driver: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost/testapp_development
username: root

# vi config/environment.rb
Add this code:

# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), ‘boot’)
if RUBY_PLATFORM =~ /java/
require ‘rubygems’

# jruby script/server
=> Booting WEBrick…
=> Rails 2.2.1 application started on
=> Ctrl-C to shutdown server; call with –help for options
[2008-11-17 16:40:34] INFO WEBrick 1.3.1
[2008-11-17 16:40:34] INFO ruby 1.8.6 (2008-11-17) [java]
[2008-11-17 16:40:34] INFO WEBrick::HTTPServer#start: pid=13484 port=4000