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
do
  ln -fs $f ${f%1.9}
done

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
http://code.google.com/p/git-osx-installer/downloads/detail?name=git-1.8.0-intel-universal-snow-leopard.dmg&can=3&q=&sort=-uploaded
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:
#!/bin/sh
/Applications/p4merge.app/Contents/MacOS/p4merge $*

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

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

 2. Install Command Line Tools for Xcode (OS X Mountain Lion) if you don't want to install the whole Xcode
https://developer.apple.com/downloads/index.action

3. Install rvm and ruby 1.9.3
curl -L https://get.rvm.io | 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
http://amz.clickontyler.com/WebSharing.dmg
OR 3rd party application (recommended)
http://clickontyler.com/virtualhostx/

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

5. Install MySQL
Go to http://dev.mysql.com/downloads/mysql/#downloads, and download Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive

6. Install homebrew
ruby < (curl -fsSk https://raw.github.com/mxcl/homebrew/go)

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
#!/bin/sh
SERVICE='jobs:work'

if [ `ps ax | grep -v grep | grep $SERVICE | wc -l` = 1 ]
then
    echo "$SERVICE service running, everything is fine"
else
    (
      echo "To: alert@abc.com"
      echo "Subject: $SERVICE is down. "
    ) | sendmail -t
fi
Install sendmail using Google Account on EC2
sudo su
apt-get update && apt-get install ssmtp
vi /etc/ssmtp/ssmtp.conf

AuthUser=abc@abc.com
AuthPass=abcabc
FromLineOverride=YES
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES
Install cron job for checking every 5 minutes
*/5 * * * * ~/jobs_check.sh

Tuesday, September 4, 2012

Rails, jQuery, and JSONP

Client side:
$.get(url, function(data){
    console.log(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 &