27 February 2007

Clearing Out Rails file-bases Sessions with cron

Adapted from Agile Web Development on Rails:
The session handler in Rails doesn’t do automated housekeeping. This means that once the data for a session is created, it isn’t automatically cleared out after the session expires. This can quickly spell trouble. The default file-based session handler will run into trouble long before the database-based session handler will, but both handlers will create an endless amount of data. Since Rails doesn’t clean up after itself, you’ll need to do it yourself. The easiest way is to run a script periodically, you could put the following command into a script
that will delete files that haven’t been touched in the last 1 hour every morning at 4am.

In the bash, run the command:
crontab -e

You'll enter a command line editor vi like, type "I" and copy-paste the following command:
0 4 * * * cd ~/YOUR_RAILS_APPS_HOME_FOLDER_HERE/; find tmp/sessions -name 'ruby_sess.*' -amin +60 -exec rm -rf {} \;

To save, type ESC, then wq in order to save the file and quit.

As far as I am concerned, I can't stand these command line software which don't give a clue about how to use them. I am sooooo looking forward a rebirth of some Pao Alto 70 spirit in the domain of User Interface: I want to see 3D, vocal commands, predictive User Interfaces !!! Damn the Monopoles!!!!

21 February 2007

MySQL Database access problem in Ruby on Rails

I was having the following problem repetitively when using rake to run the tests on my ubuntu Edgy Eft machine:
rake aborted!
Lost connection to MySQL server during query
/config/../vendor/rails/activerecord/lib/active_record/vendor/mysql.rb:1127:in `write'

As I am using Radrails since the beginning of my ruby career , I have never found out before!!! Indeed, Radrails must use another driver than my plain ruby to access the mysql database.

It turned out that installing the libmysql-ruby solved the problem:
sudo apt-get install libmysql-ruby

14 February 2007

Deploying a rails application on site5

It took me a while - 2 days and a half ! - but I finnaly managed to deploy my application on site5 using capistrano!

The toughest part was understanding this error message:

error: directory is writable by others: (/home/xxxxxx/rails/webapps/xxxx/releases/20070213163348/public)
[warn] FastCGI: (dynamic) server "/home/xxxxx/public_html/xxxxx/dispatch.fcgi"
has failed to remain running for 30 seconds given 3 attempts, its restart interval has been backed off
to 600 seconds

It turned out - as I found in the site5 forum - that site5 has CGI/FCGI configured to shut down scripts that are group- or world-writable. As of 1.3, Capistrano issues a "chmod g+w" command over the entire check-out branch.

The solution was to change the permissions in a :after_update_code task.

The thing is, site5 is cheap but it so sloooooooooow! not sure how long I am going to pay for such a service.





# Capistrano deployment script on site 5
# Jean-Michel Garnier
# Tested with capistrano 1.40 14/02/2007
#
# Inspired by http://fluctisonous.com/2006/11/19/moving-home-with-capistrano-on-site5
# And Kyle Daigle http://forums.asmallorange.com/index.php?showtopic=8892

# Usage:
# the first time: cap setup
#
# Then to initialize the db the first time- if you have a bootstrap task like in mephisto -
# env BOOTSTRAP=true cap deploy
#
# otherwise: cap deploy


# =============================================================================
# Customize these variables
# =============================================================================

set :application, "bicinostrum"

set :user, "your userlogin at site5" # defaults to the currently logged in user
set :password, "your site5 password"
set :domain, "21croissants.com" # your applications domain name
#set :deploy_server, "you.server.name" # the url of your server


set :public_html, "/home/#{user}/public_html/#{application}"
set :svn_repositoty_home, "rails/svn_repository"
set :rails_apps_home, "rails/webapps"

# =============================================================================
# Do not change these variables
# =============================================================================
set :use_sudo, false
set :rails_env, "production"
set :deploy_to, "/home/#{user}/#{rails_apps_home}/#{application}"
set :repository, "svn+ssh://#{user}@#{domain}/home/#{user}/#{svn_repositoty_home}/#{application}/trunk"

# =============================================================================
# ROLES
# =============================================================================
# You can define any number of roles, each of which contains any number of
# machines. Roles might include such things as :web, or :app, or :db, defining
# what the purpose of each machine is. You can also specify options that can
# be used to single out a specific subset of boxes in a particular role, like
# :primary => true.

role :web, domain
role :app, domain
role :db, domain

# =============================================================================
# SSH OPTIONS ?
# =============================================================================

set :svn_passphrase, ""
# ssh_options[:port] = 25

# =============================================================================
# TASKS
# =============================================================================
# Define tasks that run on all (or only some) of the machines. You can specify
# a role (or set of roles) that each task should be executed on. You can also
# narrow the set of servers to a subset of a role by specifying options, which
# must match the options given for the servers to select (like :primary => true)

desc "Restart the web server. Overrides the default task for Site5 use"
task :restart, :roles => :app do
run "skill -9 -u#{user} -cdispatch.fcgi"
end

task :after_setup, :roles => :app do
run <<-CMD
ln -s /home/#{user}/#{rails_apps_home}/#{application}/current/public/ #{public_html}
CMD

end

task :after_update_code, :roles => :app do
run "find #{release_path}/public -type d -exec chmod 0755 {} \\;"
run "find #{release_path}/public -type f -exec chmod 0644 {} \\;"
run "chmod 0755 #{release_path}/public/dispatch.*"

if ENV['BOOTSTRAP']
run <<-EOF
cd #{release_path} && rake db:bootstrap RAILS_ENV=production
EOF
else
run <<-EOF
cd #{release_path} && rake db:migrate RAILS_ENV=production
EOF
end
end

13 February 2007

Unlocking an HTC S620 WIFI phone in 5 minutes / Resisting to telco thanks to voip

http://www.pianetacellulare.it/Modelli/immagini/s620_htc.jpg


In most of european countries, there are 3-5 operators who have agreed to maintain very expensive prices for mobile phone communications and text messaging. This is obviously an unofficially agreement and there will be some kind of justice one day, probably from the European Commission...

But today is a great day, I have unlocked in 5 minutes the HTC S620 I bought on eBay in the US for 220€ using IMEI-Check services (20 pounds). This is still cheaper than the 489€ retail price in Europe! I did not want to buy any Microsoft based device but I was not convinced by what I read about symbian os smart-phones (correct me if I am wrong).

The image “http://en.fon.com/lib/tools/fgf/home_images/en/en_logoFon.png” cannot be displayed, because it contains errors.

Hopefully, there are a lot of open Wifi networks (still) + the fact the FON network is growing rapidly, I am confident I will be able to use Skype and call for free my relatives abroad, make voip phone calls at the rate of 12 centimes instead of 18 centimes (I am not sure about that, the price system of mobile phone communication was not not made to be readable) (plus the fact they always fucking charge the first minute even if the conversation lasted 1 second), and especially send text messages for 7 centimes instead of 20 centimes with my current pay-as-go contract!!!

06 February 2007

Freezing the gems of a specific version of Rails

rake rails:freeze:gems VERSION=1.1.6

01 February 2007

Installing Java plugin for firefox 2.0 on Ubuntu Feisty

Automatix won't work - the symlink to java plugin won't be copied - and you'll have to do it manually ... The next step would be to update the Automatix script ...

sudo apt-get install sun-java6-plugin
cd /opt/firefox/plugins
sudo ln -s /usr/lib/jvm/java-6-sun/jre/plugin/i386/ns7/libjavaplugin_oji.so ./libjavaplugin_oji.so