Archive for

July 2011

Deploying with Inploy - An alternative to Capistrano

Inploy is similar to Capistrano but easier - it has better defaults and it is more forgiving when you don’t know what you’re doing (me).

Inploy on your development machine:

  • add to Gemfile: gem ‘inploy’
  • bundle install --without production

Create deploy.rb under your app’s config directory. The basic config/deploy.rb file:

application = "test"
repository = 'git@git.assembla.com:my-apps-repo.git'
hosts = ['zer1']
path = '/home/deploy'

Notes on deploy.rb:

  • default user is ‘deploy’
  • deploys to #{path}/#{application}
  • Inploy’s hosts will look to your development machine’s .ssh/config (so add your production server)

Inploy commands:

Pull the app from repo, bundle install, create database, migrate:

  • bundle exec rake inploy:remote:setup

Once you’re setup, you can update your app and repo:

  • bundle exec rake inploy:remote:update

That’s it! You can learn more about Inploy on Github.

Posted

Rails on Ubuntu 10.04: Passenger, Nginx, MySQL, Varnish

I setup a new VPS this weekend and decided to share my notes.

My notes are from being logged in as root. If you're logged in as another user, you'll be typing sudo a lot. :)

Configure your locale
 
  • locale -a
  • locale-gen en_US.UTF-8
  • update-locale LANG=en_US.UTF-8
  • update-locale LANGUAGE=en_US.UTF-8
  • exit
  • ssh zer1 #zer1 is my VPS added to ~/.ssh/config 
  • locale -a #should have en_US.UTF-8 listed 
  • update-locale #errors? 

Set your time zone

  • dpkg-reconfigure tzdata
  • ntpdate ntp.ubuntu.com

Update Ubuntu

  • apt-get update && apt-get upgrade

Install dependencies

  • apt-get install build-essential libmagickcore-dev imagemagick libxml2-dev libxslt1-dev git-core libapr1-dev libssl-dev libmysqlclient15-dev libcurl4-openssl-dev curl libncurses5-dev libreadline5-dev libopenssl-ruby1.9

Install MySQL

  • apt-get install mysql-server libmysqlclient-dev libmysqlclient15-dev libmysql-ruby
  • mysql_secure_installation

Install latest Ruby from source

Set default environment for Rails

  • nano /etc/environment
  • add the following line to it:
  • export RAILS_ENV=production

Install Nginx and Passenger

Configure Nginx

  • mkdir /opt/nginx/conf/sites-enabled
  • nano /opt/nginx/conf/nginx.conf
  • add this within the http { } block:
  • change default listen port to 8080
  • include /opt/nginx/conf/sites-enabled/*;
  • nano /opt/nginx/conf/sites-enabled/test

*note port 8080 for Varnish

server {
   listen 8080;
   server_name mywebsite.com;
   root /home/deploy/test/public;
   passenger_enabled on;
}


  • service nginx restart

Add deploy user

  • adduser deploy
  • su deploy #switches to deploy
  • ssh-keygen -t rsa -C “deploy@myserver”
  • cat ~/.ssh/id_rsa.pub
  • copy the output into your favorite Git hosting as an allowed key (Assembla, Github, etc)
  • on your development machine:
  • cat ~/.ssh/id_rsa.pub
  • on the server as deploy user:
  • nano ~/.ssh/authorized_keys
  • paste in your development machine’s public key
  • git clone git@git.assembla.com:myapp.git      #lets you add host as known_host
  • rm -rf myapp         

Create a MySQL user and database

  • mysql -u root -p
  • create database myapp_prod;
  • create user 'mydbuser'@'localhost' identified by 'secret';
  • grant all privileges on myapp_prod.* to 'mydbuser'@'localhost';

Install Varnish HTTP cache

  • apt-get install subversion autotools-dev automake1.9 libtool autoconf libncurses-dev xsltproc quilt debhelper
  • svn co http://varnish-cache.org/svn/tags/varnish-2.0.5
  • cd varnish-2.0.5/varnish-cache
  • dpkg-buildpackage
  • cd ..
  • dpkg -i libvarnish1_2.0.6-2_i386.deb
  • dpkg -i varnish_2.0.6-2_i386.deb
  • service varnish start

Configure Varnish

  • nano /etc/varnish/default.vcl
  • Leave this at defaults, but now you know where it is :)
  • nano /etc/default/varnish
  • Comment out DAEMON_OPTS use the following instead:
  • DAEMON_OPTS="-a :80 -f /etc/varnish/default.vcl -s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,1G"
  • service varnish restart

 

Posted

Migrating to Google Apps Standard from Cpanel

So I just had a nightmare of a time bouncing from cPanel providers. I figured there had to be something better that I could offer small businesses I work with.

I decided to run a trial of Google Apps Standard for two weeks and consider if it would be viable to move businesses using cPanel to Google Apps Standard accounts.

The trial went well. I used Google Apps for two weeks and had no service disruptions and migration was painless. After the trial, I moved my family's small business http://midhurstroofing.ca to Google Apps. 

Here's some problems I encountered during the migration and how I fixed them:

1.  Microsoft Outlook + POP3 + Google Apps Migration Tool = TimeStamp fail

I finished my first user and hooked up IMAP. All the dates for messages were wrong. The dates shown after the migration were all < 1 day and they should have gone all the way back to 2009. WTF!

Apparently the problem is related to Outlook displaying the DateTime from a part of the message header that is updated during the migration. I found two solutions to this:

The first, was to use an email client other than Outlook. Literally any other client has no issues with the Google Apps Migration Tool - Mozilla Thunderbird, Apple Mail, mobile clients, etc.

The second, for those that have users that are too used to Outlook to switch cold turkey, is to change Outlooks view to sort and display the Sent DateTime of the message header instead of Received(default). To accomplish this:

- click the Sort by Date at the top of your message list.
- click custom
- change Sort to Sent

This view change is on a per-folder level, meaning you'll have to do it on a couple folders. Depending on your user, usually Inbox and Sent is a must.

All future emails (not migrated) will have the proper information in the headers for Outlook to handle this under default settings. Hopefully Microsoft improves IMAP to handle this like other email clients do.

2.  Users were used to an Inbox under Personal, now the IMAP mailbox is a separate item in the Navigation Pane

For this one, I made sure unused PST/Archives listed in the navigation pane were removed (AutoArchive) since users get boat loads of storage with Google Apps, there's no need to retain copies locally. 

The next thing was to either hide or delete email messages on the user's machine. I recommend hiding them in a subfolder until you're confident the move to Google Apps is complete.

Next is to make sure when Outlook is started, it shows their IMAP inbox instead of their old Inbox. To do this:

- Tools > Options > Misc tab
- Advanced Options
- Change which folder is opened when Outlook runs
- Select the inbox under IMAP

After that's done, I collapsed the whole Personal archive in the navigation pane.

This results in a Navigation pane that looks very similar to the user's old one.

3.  Sent items need to go into GMail

Make sure their sent items are properly being placed in their GMail Sent Items and not a local folder or the copy Google Apps Migration Tool makes.

4. I need to clean up IMAP folders but it says Permission Denied

GMail only allows the deletion of IMAP folders through the web interface. For this, I suggest you login to the web interface and use Manage Labels to clean things up.

Manage Labels interface:
Pastedgraphic-1

As you can see, there's a lot of garbage folders that one might not necessarily use that get copied in a migration.

That's all! Overall I'm pleased with the outcome and I hope users are too. :)

Posted