Archive

Posts Tagged ‘ruby on rails’

Ruby on Rails compile mysql gem

July 19th, 2009 Arthur Gressick No comments

I ran into this little problem of compiling mysql gem on a centOS box and thought I would share this.

NOTE: updated January 2010
If you don’t have the mySQL development libraries installed then you might want to install them.

apt-get install libmysqlclient*-dev

Make sure you have the DEV libraries installed on the linux box and then run this command

gem install mysql --no-rdoc --no-ri -- --with-mysql-config=/usr/bin/mysql_config

It work for me on CentOS 5.3 just today.

Capistrano Script for Ruby on Rails

March 10th, 2009 Arthur Gressick No comments

Here is an excellent capistrano deploy script for Ruby on Rails applications. It changes the permissions and on the files and also pushes the mongrel cluster file. I changed my information so make sure you look at the script from beginning to end.

#Capistrano Recipe 2.0 for pushing the files. Developed by Arthur Gressick
 
set :domain, "subdomain.your_site.com"
set :user, "root"
set :application, "your_site_root"
#make sure and don't run as super user
#set :use_sudo, false
 
#SVN Repository information
#default_run_options[:pty] = false
 
set :scm, :subversion
set :repository_addy,  "svn://svn.your_repository.com/ruby_project/trunk"
set :deploy_via, :export
set :deploy_to, "/home/user/vhosts/#{application}"
 
 
set :scm_user, "username"
set :scm_password, Proc.new { Capistrano::CLI.password_prompt("SVN password for #{scm_user}, please: ") }
set :repository, Proc.new { "--username #{scm_user} --password #{scm_password} --no-auth-cache #{repository_addy}"; }
 
#set :scm_username, "username"
#set :scm_prefer_prompt, true
#set :scm_auth_cache, true
 
#DEFINE the servers that need to be updated
role :app, "ip_address"
role :web, "ip_address"
role :db,  "ip_address", :primary => true
 
#SET BACKUPS
set :keep_releases, 3 # keep only 3 versions of the site on the server
 
#DEPLOY:SETUP Script to set the permissions
desc "Setup the permissions for the project"
task :setup_permissions, :roles => :app do
	as = fetch(:runner, "root")
 
	run "chown -Rh username:username /home/username/vhosts/#{application}"
	run "chown -Rh www-data:www-data /home/username/vhosts/#{application}/shared"
end
after "deploy:setup", :setup_permissions
 
#DEPLOY:COLD Scripts for moving the mongrel cluster file to folder.
desc "Setup a link to the mongrel cluster folder"
task :setup_mongrel_cluster, :roles => :app do
	as = fetch(:runner, "root")
 
	run "chown -Rh username:username /home/username/vhosts/#{application}/releases/"
	run "ln -s /home/username/vhosts/#{application}/current/config/mongrel_cluster.yml /etc/mongrel-cluster/sites-enabled/#{application}.yml"
end
after "deploy:cold", :setup_mongrel_cluster
 
#---------------------------------------------------------------------------------------------------
#MONGREL management
namespace :deploy do
 
	desc "Start the server"
	task :start, :roles => :app do
		as = fetch(:runner, "root")
 
		invoke_command "/etc/init.d/mongrel-cluster start"
	end
 
	desc "Stop the server"
	task :stop, :roles => :app do
		as = fetch(:runner, "root")
 
		invoke_command "/etc/init.d/mongrel-cluster stop"
	end
 
	desc "Restart the server"
	task :restart, :roles => :app do
		as = fetch(:runner, "root")
 
		#copy out the log files.
		run "cp /home/username/vhosts/#{application}/shared/log/production.log /home/username/vhosts/#{application}/shared/log/production-bak.log"
		run "rm -rf /home/username/vhosts/#{application}/shared/log/production.log"
 
		run "chown -Rh username:username /home/username/vhosts/#{application}/releases/"
 
		run "chmod -R 777 /home/username/vhosts/#{application}/current/tmp"
 
		invoke_command "/etc/init.d/mongrel-cluster restart"
	end
end
 
#Run all of the clean up scripts.
after "deploy:update", "deploy:cleanup" #Clean up the directory so that there are only x working copies set the number above.
 
desc "After Symlink shared files path"
task :after_symlink, :roles => :app do
  #FileUtils.mkdir_p("#{shared_path}/files") unless File.exists?("#{shared_path}/files")
  run "ln -nfs #{shared_path}/files #{release_path}/public/files"
  #run "ln -nfs #{shared_path}/tmp #{release_path}/public/tmp"
end

Setup of a new rails app with svn

March 2nd, 2009 Arthur Gressick No comments

The easiest way to setup a new repository for your rails application is to ssh into the repository host and then using terminal type as root

svnadmin create /path/to/repos/new-repo-name

Then to lock it down without using ssh and using the provided svnserve program running as a daemon on the host run this command from the newly created repository directory

vi conf/svnserve.conf

Make sure to set in the [general] section anon-access = none and auth-access = write

Also make sure to uncomment password-db = passwd

Then after you save those changes execute the following

vi conf/passwd

Add an entry for yourself and whomever you’ll be sharing this repository with, like other developers and such. Save and quit.

While in the same repo directory go ahead and make a temp directory and inside the temp directory create three directories ( trunk, tags, branches )

mkdir trunk tags branches

You’ll want to import these directories into your repo.

svn import . [svn-host] -m "dir import"

You can now remove the temp directory you created and exit out of ssh.

Navigate to where you would like your rails application to live on your local machine and create the rails application

rails mynewapp

cd into the new rails application and then issue a svn import to import the new rails app into your repository

svn import . [svn-host]/trunk -m "initial app import"

You may now remove the app you just created on your local machine, because we will be checking it out from the repository and your repository will have all the latest changes.

svn co [svn-host]/trunk

Now let’s ignore the database.yml file, the tmp and log directories

svn propset svn:ignore database.yml config/
svn propset svn:ignore '*' tmp/
svn propset svn:ignore '*' log/

That should do it, your database.yml file, your log and tmp directory will not be checked into your repository.