To create and save image from a running Instance : Amazon EC2

First, install Amazon’s AMI tools, and API tools: on your running instance:

1)mkdir /root/.ec2
2)export $EC2_TOOLS_DIR=/root/.ec2
3)mkdir ec2-ami-tools
4)cd ec2-ami-tools
5)wget http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.zip
6)unzip ec2-ami-tools.zip
7)ln -s ec2-ami-tools-* current
8)cd ..
9)mkdir ec2-api-tools
10)cd ec2-api-tools
11) wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip
12)unzip ec2-api-tools.zip
13)ln -s ec2-api-tools-* current
14)echo “export EC2_AMITOOL_HOME=`dirname $EC2_TOOLS_DIR`/ec2-ami-tools/current” >> ~/.bashrc
15)echo “export EC2_APITOOL_HOME=`dirname $EC2_TOOLS_DIR`/ec2-api-tools/current” >> ~/.bashrc
16)echo “export PATH=${PATH}:`dirname $AMI_TOOLS_DIR`/ec2-ami-tools/current/bin:`dirname $AMI_TOOLS_DIR`/ec2-api-tools/current/bin” >> ~/.bashrc
17)source ~/.bashrc

18)Next, you’ll need to get your security credentials. You can get a reminder of – or create as needed – these on the AWS “Your Account” > “Security Credentials” page.
Attached is the keys
19)You’ll also need to note your AWS access details – especially your access key and secret key – plus your Amazon account ID.

First, choose a name for your AMI snapshot. We’ll call it ami-instance-name :)
1.# make a directory for your image:
mkdir /mnt/ami-webserver-11march10
2.# create the image (this will take a while!)
ec2-bundle-vol -d /mnt/ami-instance-name -k /path/to/your/pk-(long string).pem -c /path/to/your/cert-(long string).pem -u YOUR_AMAZON_ACCOUNT_ID_WITHOUT_DASHES

Once that’s done, you should have a file called image.manifest.xml in your /mnt/ami-instance-name directory, along with all the bundle parts.

Next, upload the AMI image to S3. This command will create an S3 bucket of the given name if it doesn’t exist – I’ve found it convenient to call my buckets the same as the instance name:
1.ec2-upload-bundle -b ami-instance-name -m /mnt/ami-instance-name/image.manifest.xml -a YOUR_AWS_ACCESS_KEY -s YOUR_AWS_SECRET_KEY

You should then be able to register the instance from AWS Management Console web UI, but you can also do it from the command line using:
ec2-register ami-instance-name/image.manifest.xml

Copy your certificate and private key on mnt/ami-instance-name/amazon_cert

My .sh File

#!/bin/bash
mkdir /mnt/images/$1
ec2-bundle-vol -d /mnt/images/$1 -k $EC2_PRIVATE_KEY -c $EC2_CERT -u $AWS_ACCOUNT_ID
ec2-upload-bundle -b $1 -m /mnt/images/$1/image.manifest.xml -a $AWS_ACCESS_KEY -s $AWS_SECRET_KEY
ec2-register $1/image.manifest.xml
.and giving it a parameter of ami-instance-name.script saved as ami.sh, so I can just call, for instance:
./ami.sh webserver-name

After registarion of the image go and create instance from the same.. registered image

To Create instance from the image
Go to your amazon web console
select the image and create instance from the same.

May 10, 2010 at 1:05 pm 5 comments

Useful links for Ruby on Rails

Some of the useful links

http://www.workingwithrails.com/browse/railsplugins/usage

November 30, 2009 at 1:21 pm Leave a comment

Rotating Ruby on Rails Log Files Using Logrotate

Configuring logrotate

logrotate gets its configuration information from the file /etc/logrotate.conf. If you can’t find it, you can type locate logrotate.conf from the command line to see where it lives. Open up that file in a text editor (nano /etc/logrotate.conf will work) and append the following lines at the end:

1. Create a file called /etc/logrotate.d/passenger

And put the following contents in it.

/home/myapp/log/*.log {
daily
missingok
rotate 30
compress
delaycompress
sharedscripts
postrotate
touch /home/myapp/tmp/restart.txt
endscript
}

Now your logs will get rotated daily with the previous day being compressed into it’s own file. The compressed files will sit around for 30 days then be deleted. After the rotation is done, postrotate, it will touch /home/myapp/tmp/restart.txt to restart passenger.

2. Test it

Run: logrotate -f /etc/logrotate.d/passenger

After running, you should see an archived log file and a fresh new active one taking the original files place. Also, Passenger will restart so it can log to the new file.

November 13, 2009 at 6:49 pm 1 comment

Server Installation For Ruby From Scratch on UBUNTU

To make your vps live for your first rails applicatio is really a cakewalks for me. I am writing here some of my experience which i faced and i learned while doing so.

First There are some do’s and dont do’s. You will get all the to do on a various blogs. The common of them are

1) Choose your flavor of os and VPS.

2) Connect to your vps and install mysql-client ,passenger , ruby, ruby gems and rails

One thing that i learned from my exp. is that to compile your rubygems rather than instaling it from apt-get. It gives some eroors later.

run the command as root:

sudo apt-get update
apt-get -y install build-essential zlib1g zlib1g-dev libxml2 libxml2-dev libxslt-dev sqlite3 libsqlite3-dev
for Rmagick:
apt-get -y install libmagick9-dev
Ruby Install
apt-get -y install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8 libopenssl-ruby
Some standare ruby gems( you include all your gems needed for the app)
gem install rake nokogiri hpricot builder cheat daemons json uuid rmagick sqlite3-ruby fastthread rack
mysql :
sudo apt-get install mysql-server mysql-client libmysqlclient15-dev
3) Install your apache
echo “deb http://apt.brightbox.net hardy main” > /etc/apt/sources.list.d/brightbox.list
wget -q -O – http://apt.brightbox.net/release.asc | apt-key add -
apt-get update
apt-get -y install libapache2-mod-passenger
4) configure your apache with passenger in the apache conf and restart your apache server

http://www.modrails.com/documentation/Users%20guide.html

If everything is configured correctly you will see your app running.

For further study : http://ariejan.net/2007/06/20/rails-production-server-setup-and-deployment-on-ubuntudebian/

http://www.rubyinside.com/how-to-install-a-ruby-18-stack-on-ubuntu-810-from-scratch-1566.html

September 7, 2009 at 6:01 am Leave a comment

Time estimates: failure or success

Ask any  developer, and they will tell you that they work longer hours than the time they estimated for that work. As such, we have a pretty universal set of procedures to estimate a task, usually 1/2 – 1 hour, and we estimate our job accordingly. We see that one is working far more than their time estimates and hence the project cost increase . Obviously that’s not optimal at all, and I’m thinking why there is a lag on one person’s time.

Why is there such a disconnect? Are we all terrible in estimating? Are we spending too much time checking up our google pals. That may be the case for some few colleagues most of the time, or some of us on our younger days, but it’s definitely not the case at mastiff on a typical day. Yet somehow I can sit at the computer from 10:30 am to 10:30 pm doing nothing but work, and walk away with just two task done of estimated 2 hrs.

There’s a lot of reasons why, but it becomes most clear when we examine what is entailed in a single simple project consisting of one task. Take the example of a pretty quick change where a redirect needs to be added to a site so that ‘/proxy’ points to a new url. It should be quick, after all it’s just opening a remote file, adding a line, and saving it. Should almost be completed in 10 mins, right?

Yet when all the time tracking is done, I find that I spend somewhere between 1/4 – 1 hour on such a request because of all the administrative overhead that MUST come with any project. You see the task being done is only one part of what it takes to move a project through an organization, even a small one like mine. So while we have read the simple version of what it takes to make the change, let’s examine how it actually plays out in the real world where I try to convert my time into money:

  • A change comes into my email inbox and I stop the work I’m on to immediately address the request. I know from experience that failing to immediately respond all my clients correspondence creates a bad atmosphere. This will delay the task that I’m already on somewhat, but I’ll usually discount that from the current estimates of my current task.
  • I estimate how much I think it will take time to finish and get back to what I was doing.
  • Another email comes in asking for an official estimate because the company has specific procedures.
  • I go and create an estimate. I let it sit for five minutes while I do other work, and come back to double check it, since experience has taught me not to send any numbers out  just after typing them.
  • I get another email that the estimate is approved and the work begins.
  • I Make the change, which involves looking up ssh and ftp settings for the site, using them to login, discovering the .htaccess file’s true location, editing it. I may need to look up the correct commands for VI editor, or make sure that this doesn’t mess up any hosting stuff.
  • I test the change, which means opening the browser to http://www.gigoptix.com/proxy and then clicking around the site to make sure nothing there is messed up.
  • I email that the change is complete and wait for confirmation that it’s correct.
  • I get either confirmation that the job’s done, or more often I get some “oh yeah”s.
  • Usually some small change or additional work is thrown in at this stage. I call it the “oh yeah” stuff, as in: “Oh yeah, can you also do that for these other long urls…” I typically do these without any estimates and don’t usually add much to the project scope.
  • I draft the time sheet and send it out.In the end, a 15 minute change actually invokes about an hour’s worth of residual work and time. So after reading all that, here’s some specific advice for you.

So how do we stay in business like this? I’m sure there’s lots of strategies to explore, and I welcome comment on them, but some that I have found wide-spread and useful are as follows:

  • Increment task: Divide the task into maximum subtask. This makes sure that you don’t spend the whole day running around chasing small work and increment yor task list as per the new task thrown.
  • COMMUNICATE. Let your managers know where they stand at all times. You can NOT be afraid of talking about your tasks nor can you expect your manager to be keeping track of what you are up to. It’s routine for managers to schedule meetings and not realize that this is consulting, or for a series of out of scope changes to rack up a big task in the heat of the project’s final week. If you feel that the task is increased, talk to your managers and log them. Failure to do so could land you in hot water with disputed, and inevitably low productivity on your end.

August 4, 2009 at 1:36 pm

Ruby On rails Installation for developers

To install ruby and start rolling on rails is as simple as the following steps:

Installing Ruby:

CODE:

  1. yum install ruby ruby-devel
  2. wget http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgz
  3. tar -xzf rubygems-0.9.0.tgz
  4. cd rubygems-0.9.0
  5. ruby setup.rb
And you are set for development:
To install mongrel:
  1. gem install mongrel
Now you are all set to start the new rails application;
  1. rails mytest

this will create the directory structure and the basic rails framework where you can write your own controllers, model and views.

Starting the server:

Once Mongrel has been installed you can start it up to host your project by executing the following, from the root of your application:

skx@host:~/Rails/mytest$ mongrel_rails start -d -e production -a 127.0.0.1 -p 3000

Here we’ve used several arguments (for an overview of more options run “mogrel_rails start -t“) here is a quick explanation of what they mean:

  • -d
    • To detach and run in the background
  • -e production
    • To run the application in “production” mode.
  • -a 127.0.0.1
    • To bind to the localhost only.
  • -p 3000
    • To listen upon port 3000.

Note: you don’t need to start the server as root, since you’re binding to a “non privileged” port.

All being well you should receive no errors and browsing at http://localhost:3000 should show you your applications front page.

To stop the server you may run:

skx@host:~/Rails/mytests$ mongrel_rails stop
Sending TERM to Mongrel at PID 9698...Done.

October 23, 2008 at 9:11 am Leave a comment

Apache Configuration For Rails Apps

Configuring single rails app on apache server

To host your rails app through apache one need to add the virtual host entry in the httpd.conf

<VirtualHost *>
    # Server name
    ServerName test.example.com

    # Proxy ACL
    <Proxy *>
        Order allow,deny
        Allow from all
    </Proxy>

    # Proxy directives
    ProxyPass / http://localhost:3000/
    ProxyPassReverse / http://localhost:3000/
    ProxyPreserveHost on

    # Logfiles
    ErrorLog  /var/log/apache2/test.example.com.error.log
    CustomLog /var/log/apache2/test.example.com.access.log combined

</VirtualHost>

Configuring multiple rails app on single apache server

<VirtualHost *>
    # Server name
    ServerName test.example.com

    # Proxy ACL
    <Proxy *>
        Order allow,deny
        Allow from all
    </Proxy>
<Directory "/var/www/html/railsApp/public">
Options Indexes FollowSymLinks
AllowOverride none
Order allow,deny
Allow from all
</Directory>

    # Proxy directives
    ProxyPass /railsApp http://localhost:3000/
    ProxyPassReverse /railsApp http://localhost:3000/
    ProxyPreserveHost on

    # Logfiles
    ErrorLog  /var/log/apache2/test.example.com.error.log
    CustomLog /var/log/apache2/test.example.com.access.log combined

</VirtualHost>

you can access theis application as :
http://test.example.com/railsApp

For this we have to make a small adjustmwnt in our code and and add the folloeing code in pur apps enviornmrnt.rb
ActionController::AbstractRequest.relative_url_root = "/railsApp"

October 23, 2008 at 9:00 am Leave a comment

Older Posts


Categories

  • Blogroll

  • Feeds


    Follow

    Get every new post delivered to your Inbox.