Thursday, September 19, 2013

Setup AWS with Nginx + Passenger + Rails 3

1. Bring up a new instance with default AMI

2. Change SSH connection from .pem file dependent to username/password authentication:
+ SSH to server using .pem file as ec2-user account
+ Create a new account and change the ssh configuration to Password Authentication:
sudo su -
useradd -m deploy
passwd deploy
visudo --> add deploy user as sudoer
vi /etc/ssh/sshd_config --> enable PasswordAuthentication
/etc/init.d/sshd reload --> restart sshd server

3. Re-log in as deploy user

4. Update ruby to 1.9
+ sudo yum install ruby19
+ cd /usr/bin
+ sudo su -
+ for f in /usr/bin/*1.9
  ln -fs $f ${f%1.9}

5. Install passenger and nginx
+ sudo su -
+ gem install passenger
+ passenger-install-nginx-module

6. Deploy application with passenger

Tuesday, November 13, 2012

View Request per Second

sudo tail -F /var/log/nginx/access.log | pv -lr >/dev/null

Sunday, November 4, 2012

Set Up RoR development environment for Mac OS X 10.8.2

1. Set up Git
Although it's named as Snow Leopard, it works with Mountain Lion.

1b. Set up Git merge tool:
+ Install p4merge
+ Create a new text file in /usr/local/bin called p4merge, make it executable, and add following lines:
/Applications/ $*

+ Create a new text file in /usr/local/bin call p4diff, make it executable and add following lines:
[ $# -eq 7 ] && /usr/local/bin/p4merge "$2" "$5"

+ Open your git configuration file (probably ~/.gitconig) and add these lines:
 keepBackup = false;
 tool = p4merge
[mergetool "p4merge"]
 cmd = p4merge "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
 keepTemporaries = false
 trustExitCode = false
 keepBackup = false
 external = p4diff

 2. Install Command Line Tools for Xcode (OS X Mountain Lion) if you don't want to install the whole Xcode

3. Install rvm and ruby 1.9.3
curl -L | bash -s stable
source /Users/phucquang/.rvm/scripts/rvm
rvm install 1.9.3
rvm use 1.9.3
rvm --default 1.9.3

4. Enabling Apache - Using 3rd party Preference Panel
OR 3rd party application (recommended)

4b. Starting built-in Apache server automatically.
sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist

5. Install MySQL
Go to, and download Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive

6. Install homebrew
ruby < (curl -fsSk

7. Install ImageMagick
brew install imagemagick --use-tiff 

Monday, September 10, 2012

Service check using Bash script, sendmail with Google Account, and cron

Bash script

if [ `ps ax | grep -v grep | grep $SERVICE | wc -l` = 1 ]
    echo "$SERVICE service running, everything is fine"
      echo "To:"
      echo "Subject: $SERVICE is down. "
    ) | sendmail -t
Install sendmail using Google Account on EC2
sudo su
apt-get update && apt-get install ssmtp
vi /etc/ssmtp/ssmtp.conf
Install cron job for checking every 5 minutes
*/5 * * * * ~/

Tuesday, September 4, 2012

Rails, jQuery, and JSONP

Client side:
$.get(url, function(data){
  }, "jsonp");

Server side:
render :json=>{:abc=>"abc"}, :callback=>params[:callback] and return

Wednesday, June 6, 2012

Thursday, May 17, 2012

Running rake background processes

nohup rake pricing:convert_spig RAILS_ENV=production &> /dev/null &