[sudo] password for deploy: stalls!

Posted by John
on Sunday, 02 December 2007

With the latest version of Ubuntu, Gutsy 7.10, you may have started getting cases where you fire..

cap setup_ssh_keys

and it just sits there saying...

[sudo] password for deploy:

without giving you the option to enter the password.

you can fix this by adding this line in your deploy.rb file:

set :sudo, "sudo -p Password:"

just after scm :domain like so:

set :domain, "myapp.com"
role :web, domain
role :app, domain
role :db,  domain, :primary => true
role :scm, domain

set :sudo, "sudo -p Password:"
#add this line to stop it hanging

this should fix the problem, has done on my new Gutsy test box.

all the best,

John.

How-To: Multiple Ruby Apps on the Same Box

Posted by John
on Friday, 24 August 2007

So you’ve deployed your first app to your nice lil’ Linux box via Capistrano, wahey!!

Now presuming you don’t really want to dedicate each server to one app alone, how would you get more than one app on there?

Here’s how,

Apache 2 .Conf

remote onto your server and edit the apache2 .conf file

/usr/local/apache2/conf/httpd.conf

  • look for a line saying ServerName
  • append the server’s IP address to the end of this
  • un-comment it

now when you try restarting apache remotely it’ll know where it is.

next check down the bottom of the file for:

  • Listen 80
  • Include conf/apps/
  • NameVirtualHost * :80

this tells Apache which port to listen to for incoming http requests and to load the config files in the conf/apps/ dir on startup.

Editing your Apps Deploy.rb

Now before you deploy your second app to the new server you must make sure it’ll use a different proxy port. Now by default your first app’l have used 8000 and 8001 so the obvious choice is to use 9000 and 9001.

So, navigate to your second ruby apps /config/ dir and edit it’s deploy.rb file

secondapp/config/deploy.rb

  • first off, you can copy & paste bits from your first apps deploy.rb to make your second, just remember to change the svn repository location to default (as you’ll make your own) and change your apps name.
  • look for => set :apache_proxy_port, 8000 and change it to 9000

deploy your 2nd app

in your second apps dir using the capistrano + deprec gems,

  • cap deprec_setup
  • cap setup_scm <= this’ll give you a new svn location for your app, add it to your deploy.rb file
  • cap deploy_with_migrations
  • cap restart_apache

afterwards you should have 2 ruby apps running on the same server!

If you get problems…

Now life isn’t perfect so chances are you’re gonna run into problems, so here’s some common commands and gotcha’s to help you,

Mongrel Complains .PID files already exist!

  • …ssh in and goto /var/www/apps/secondapp/current/tmp/ and run: rm *.pid

How Do I Re-Start Mongrel?

  • …navigate to app root & run: cap restart_mongrel_cluster

Second App keeps pointing to first, ARGH!!!

  • …ssh in and goto /usr/local/apache2/conf/apps/
  • …run: nano secondapp.conf
  • …make sure <VirtualHost *:80> and it’s balancemember is using 9000 and 9001

Restart Server?

  • …ssh in and run shutdown -r now

Restart Mongrel + Apache?

  • …navigate to first app and run: cap restart_mongrel_cluster
  • …goto second app my run: cap restart_mongrel_cluster
  • …run: cap restart_apache

If you still get problems drop me a line and i’ll try to help,

Best of luck,

John.

Upgrading Ruby from 1.8.4 => 1.8.6

Posted by John
on Saturday, 11 August 2007

Previously I wrote an article on how to upgrade your copy of Ruby + install Readline, so glad I’m rewriting it because that really sucked.

So here’s a real ‘i did it and it works’ guide, re-done, for upgrading your copy of Ruby on Rails from 1.8.whatever to the latest 1.8.6 on your Ubuntu Linux box on a server slice from Slicehost.com

Disable your website

First off, use Capistrano to inform people your server & site is down for maintenance, by opening a terminal window and moving into your ruby apps dir,

cap disable_web

Remote to your server + edit sources.list

Next remote into your server by using SSH at the prompt type,

ssh root@mybox.com

(change mybox.com to whatever your server’s hooked to)

type in your root account password and hit enter. Now at the prompt,

cd ..
ls

do ls to check your in the root of your machine, you should see a usr, etc, var, directories. now,

cd etc/apt
vi sources.list

now you should be in your ubuntu sources file, showing the network places / paths your box will go to to find the latest server updates etc.

make sure the two lines below are un-commented (remove the # at the start)

deb http://us.archive.ubuntu.com/ubuntu dapper universe

deb-src http://us.archive.ubuntu.com/ubuntu dapper universe

hit shift+i to goto edit mode in the VI editor, edit the file and hit esc then type :wq and hit enter to save the file. now navigate to the root again,

cd /

Upgrade your Linux Server

update your server’s software repository, dictionary.

apt-get update

and install any required server software updates

apt-get upgrade

Install Ruby 1.8.6

now pull off the latest ruby sourcefiles (1.8.6), extract them to their own directory and move into them.

wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.6.tar.gz

tar zxvf ruby-1.8.6.tar.gz

cd ruby-1.8.6

now your in your new ruby source directory, configure the source and make the native binary files

./configure

make

now install ruby and the ruby docs

make install

once this all finishes you should be able to kill the SSH connection by typing

exit

Check Ruby Version

then re-connect via SSH, and run,

ruby -v

and see ruby 1-8-6 displayed, bingo, you have a new ruby build on your server.

however, as you’ve built this not using apt-get you’re going to have to make sure ubuntu uses your new version and not it’s old one,

to do this edit your profile file

nano /etc/profile

and add..

export PATH=/usr/local/sbin:/usr/local/bin:$PATH

now when you reboot it’ll take your new ruby rather than the old 1.8.4

End your SSH connection by typing,

exit

Reboot your Server

Now goto slicehost.com, login to your admin console and request to soft-reboot your slice, should take 2-3 minutes. ping it using

ping www.mybox.com

you’ll see your machine pinging the server, stall for a while (it rebooting) and pinging again, your good to go now.

Re-deploy your ruby app

Go back to your terminal window and within your ruby app, run

cap deploy_with_migrations

This will deploy the latest svn version of your app to the server and more importantly reboot your mongrel server.

Turn your website back on

This should checkout ok, now run this below to remove the maintenance holding-page

cap enable-web

Hopefully things will go right and you’ll have a brand new build running on your linux box.

All the best,

John.

Recommended Gems + Deployment

Posted by John
on Tuesday, 29 May 2007

Ruby Gems

After a while of development with Ruby on Rails, you build up a few notes on what you should always have, or recommended setups. So to complement all my other notes, here's a little collection of Ruby Gems that I'd recommend you add to your collection, and some command lines to help you.

Startup + Deployment

Basics

ruby -v
// returns ruby version

rails [app]
// creates new app in current directory

script/generate
// generates templates, models, views, etc.

rake db:migrate
// runs pending database migration plans

script/server
// starts mongrel or webrick web server

script/server -p 3030 -e production
// starts mongrel in production mode at port 3030

script/server -d
// starts mongrel in development mode silently
// terminte it with these two:

ps aux | grep mongrel
// shows active processes named 'mongrel'

kill 31290
// terminate process 31290

Adding + Removing Gems

sudo gem install [gem]
// installs gem [gem]

sudo gem uninstall [gem]
// uninstalls gem [gem]

Required Gems

sudo gem install rails --include-dependencies
// the web framework ruby sits on

sudo gem install mongrel --include-dependencies
// mongrel is RoR's webserver

sudo gem install mongrel_cluster
// cluster-based mongrels

gem install capistrano -v 1.4.1
// makes it easy to deploy your RoR app

sudo gem install deprec -v 1.2.3 -y
// adds deprec deployment recipies

Capifying your App

To make your app ready for deployment to your remote server, do:

cap --apply-to .
// creates the capify .caprc file

deprec --apply-to . --name myapp --domain myapp.com
// generate your apps deploy.rb file

cap show_tasks
// show available capistrano tasks

Getting Cutting-Edge Builds

Freezing your Rails to the Edge

When building your app, you may want to make sure it will only ever use the Ruby version you've got now; rather than the one you might have in the future (if you upgrade ruby later). You know, if certain commands get depreciated later on, or if the command you use now doesn't work in the next version of ruby, but you need to upgrade your server's Ruby build for the other apps.

...to freeze rails, navigate to your apps dir, then run;

rake rails:freeze:edge
rake rails:update

...un-freeze it with;

rake rails:unfreeze

...to check what versions your running, try;

script/about

Gem Maintenance

Updating Ruby on Rails

gem update
// updates all installed gems

gem update --system
// updates 'gem' -> latest version

gem cleanup
// deletes any previous unneeded gem files

rake rails::update
// updates your app to latest rails release

Extra Gems

sudo gem install termios --include-dependencies
// wrapper for the UNIX termios command
// prevents passwords you enter in
// Capistrano from being displayed in 
// your Terminal for all to see

sudo gem install tzinfo --remote
// timezone library, provides
// daylight-saving awareness and 
// different time zones

sudo gem install redcloth
// adds support for Textile formatting

sudo gem install feed-normalizer
// ruby RSS/ATOM feed reader + dependencies

sudo gem install mysql
// builds in better mysql performance