Skip to content

Instantly share code, notes, and snippets.

View ahadshafiq's full-sized avatar

Ahad Shafiq ahadshafiq

View GitHub Profile

Zero downtime deploys with unicorn + nginx + runit + rvm + chef

Below are the actual files we use in one of our latest production applications at Agora Games to achieve zero downtime deploys with unicorn. You've probably already read the GitHub blog post on Unicorn and would like to try zero downtime deploys for your application. I hope these files and notes help. I am happy to update these files or these notes if there are comments/questions. YMMV (of course).

Other application notes:

  • Our application uses MongoDB, so we don't have database migrations to worry about as with MySQL or postgresql. That does not mean that we won't have to worry about issues with the database with indexes being built in MongoDB or what have you.
  • We use capistrano for deployment.

Salient points for each file:

#create & deploy lamp droplet
#login via ssh as root
#initial setup (ref: http://library.linode.com/getting-started#sph_logging-in-for-the-first-time)
# update /etc/hosts (to "thalassophobia.surrealroad.com")
nano /etc/hosts
#
Instead of
rails server
do:
rails s -d
then to kill it, find which process is using the port:
lsof -i :3000
finally, kill the process:
kill -9 $(lsof -i :3000 -t)
@ahadshafiq
ahadshafiq / Useful sh functions
Created April 3, 2013 15:22
Useful bashrc/.bash_profile/bash.bashrc functions
ListAllCommands | grep searchstr
function ListAllCommands
{
COMMANDS=`echo -n $PATH | xargs -d : -I {} find {} -maxdepth 1 \
-executable -type f -printf '%P\n'`
ALIASES=`alias | cut -d '=' -f 1`
echo "$COMMANDS"$'\n'"$ALIASES" | sort -u
}
@ahadshafiq
ahadshafiq / Git Workflow
Created April 8, 2013 13:15
Git workflow to follow
http://nvie.com/posts/a-successful-git-branching-model/
Master
Develop
Feature1
Feature2
Feature3
Get original source updates to master. By git pull origin originalmaster.
Check where git remote is for originamaster. git remote -v
@ahadshafiq
ahadshafiq / rake db:what
Created April 8, 2013 15:28
Active Record database commands
db:create creates the database for the current env
db:create:all creates the databases for all envs
db:drop drops the database for the current env
db:drop:all drops the databases for all envs
db:migrate runs migrations for the current env that have not run yet
db:migrate:up runs one specific migration
db:migrate:down rolls back one specific migration
db:migrate:status shows current migration status
db:migrate:rollback rolls back the last migration
db:forward advances the current schema version to the next one
@ahadshafiq
ahadshafiq / Show Controller#Action in browser
Created April 10, 2013 09:08
Rails debugging: params
put <%= params.inspect %> in application.html.erb
@ahadshafiq
ahadshafiq / Masterclass: Git
Created April 11, 2013 08:41
Masterclass: Git
http://mislav.uniqpath.com/2010/07/git-tips/
@ahadshafiq
ahadshafiq / Ruby SSL Error
Created April 11, 2013 23:07
Fixing an SSL error that came up during Janus curl. openssl::ssl::sslerror: ssl_connect returned=1 errno=0 state=sslv3 read server certificate b: certificate verify failed
rvm -v
rvm get head
rvm -v
rvm osx-ssl-certs status all
The above will show if certificates are outdated:
Certificates for /opt/sm/pkg/versions/openssl/1.0.1c/ssl/cert.pem: Old.
rvm osx-ssl-certs update all
The above will update the certificates:
@ahadshafiq
ahadshafiq / Performance
Created April 13, 2013 16:41
Some notes on Performance
--------------------------------------------------
Server Stack
--------------------------------------------------
As with other *nix applications, you can control nginx through the use
of signals. To use signals, you’ll need the process ID.
nginx is architected as a single master
process with any number of worker processes.
You can stop the master process with the