Archive for May, 2009
Postgresql: Renaming existing database name
ALTER DATABASE <old> RENAME TO <new>
Capistrano: Uploading file with different owner
Normally when working with capistrano, you choose to execute your commands on remote machine with a root user or non-root user. For root level activity, you don’t actually use “root” account but instead provide a “deploy” user “sudo” privileges and then leverage capistrano’s “use_sudo => true” option.
This still leaves you out in cold when you want to transfer a file and put it in a directory where your sudo user doesn’t have permission. In theory, what this needs is transferring/uploading/scp/sftp-ing that file to a /tmp and then using “sudo mv old_location new_location” to accomplish the task.
I ended up writing a utility method to do this but kept wondering that the need is so common that an inbuilt (and better) utility should exist. And then I found std.su_put.
Getting a Ruby on Rails app running on a fresh Ubuntu server
Shamelessley copy/pasted this from Centostrano README… thought this would be a good reference next time I setup a slicehost slice.
export HOSTS=<target.host.name> # Install Rails stack cap deprec:rails:install_rails_stack # Install mysql (if it's running on the same box) cap deprec:mysql:install cap deprec:mysql:config_gen cap deprec:mysql:config # Install your Rails app cap deploy:setup cap deploy cap deprec:db:create cap deprec:db:migrate cap deprec:nginx:restart cap deprec:mongrel:restart
Hudson build, init script and RUBYOPT
If you have a init script for hudson build that fires off the hudson server using java command, you may run into gem not found error.
In my case, my hudson init script had following:
$ java -jar hudson.war
This worked fine until a ruby build failed with gem not found (in my case the gem was rcov/rcovtask). Upon some digging here and here, I figured that it was due to missing RUBYOPT=rubygem environment variable. I tried both solutions but they didn’t help me pick up the missing rubygem.
I ended up creating a startup script as follows:
#!/bin/bash
export RUBYOPT=rubygems
# any other environment setup before firing up hudson build server
/usr/java/jdk1.6.0_12/bin/java -jar /home/hudson/hudson.war
Then all I had to do is delegate to this script from my /etc/init.d/hudson startup script.
Break Law to Save Life
By law, I mean law of nature. Today I had an interesting experience. While driving for workout, I saw family of one duck and 4 ducklings crossing road in front of my car. Suddenly, there came coyote rushing to grab one of the duckling. Just as coyote was grabbing one of the ducklings and running away, it hit another car. Coyote dropped duckling and ran away.
The duckling was injured and I could not leave it alone. It would either be taken away again by coyote or get overridden by a non suspecting car. Not knowing what to do, I called 911 for advice. Interestingly, I got response that it is just the “law of nature” and there is nothing they can do about it. Understandably, police must be getting a few tens of those calls each day and they have more important work to do than attend to this concern. Fortunately, they left me with a phone number for nearby Wildlife preservation center.
I called Willowbrook Wildlife Center. They were accepting injured animal. I ended up dropping the duckling there.
Half an hour drive from where I was to the wildlife center left me thinking. Obviously, I saved one but there must be quite a few such incidents happening each day. Did I interfere with nature by doing this? Did coyote’s life depend on find such prey? If I could save each and every duckling, should I do it? Would it not negatively impact nature?
Hmm, look at the image… even a duckling lives off of insect!
Installing mysql gem on centos
On CentOS,
gem install msql
may result in following error:
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/opt/ruby/bin/ruby extconf.rb install mysql
checking for mysql_query() in -lmysqlclient… yes
checking for mysql_ssl_set()… yes
checking for mysql.h… no
checking for mysql/mysql.h… no
*** extconf.rb failed ***
Read the rest of this entry »
ActionMailer, GMail and TLS
Prior to rails 2.3.2, if you needed to use GMail as your SMTP carrier (sending out emails from your app), you had to use one of the following plugins to modify the ActionMailer::Base class to support TLS for ActiveRecord.
- tlsmail
- ambethia-smtp-tls
- openrain-action_mailer_tls
- simplificator-tls-support
In rails 2.3.2, this is supported natively, provided you had proper configuration specified:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'localhost.localdomain',
:authentication => :plain,
:user_name => "username",
:password => "password"
}
This should work without any plugins/gems in rails 2.3.2. The only caveat is that ruby version has to be >= 1.8.7. It won’t work with ruby 1.8.6 or older, as documented here.
Enjoy!
Installing passenger/mod_rails on CentOS
Installing passenger/mod_rails on CentOS sometimes is not as simple as:
$ gem install passenger
and
$ passenger-install-apache2-module
In my case, I also had to install “apr-util-devel” yup package. Also, for some reason the “sudo yum install
$ sudo su -
$ yum install apr-util-devel
After this, “gem install passenger” and passenger-apache module install worked fine.
Installing mysql gem on CentOS
Installing mysql gem on cent-os may sometimes be not as easy as:
$ gem install mysql
It may result in compilation error and fail to install. While this may happen for various reasons, in my case, I had to install “mysql-devel” package.
$ sudo yum install mysql-devel
Once I did this, the mysql gem installed happily.
Reverting last git commit
Although this is not a good idea if the commit is already pushed to a remote repository, but it may apply to local commit.
The command is:
git revert HEAD
Enjoy!