Skip to content

Instantly share code, notes, and snippets.


Ubuntu 12.04, Ruby, Rails, Nginx, Unicorn and git-deploy

In the seemlingly endless search for the actual correct and easy way to deploy a Rails app, we have tried several ways. We tried out using Apache2 and running a cluster of Thin servers. With the built in threading of Puma we decided to use it with Nginx.

Server Setup

  • Create new server
  • Login to new server
    • ssh root@IPaddress (you can also use the domain name if you have the DNS setup already)
    • accept the RSA key

I just had to set up Jenkins to use GitHub. My notes (to myself, mostly):

Detailed Instructions

For setting up Jenkins to build GitHub projects. This assumes some ability to manage Jenkins, use the command line, set up a utility LDAP account, etc. Please share or improve this Gist as needed.

Install Jenkins Plugins

View gist:9816249
# Kill and restart nginx
function restart_nginx(){
pids=$(pidof nginx)
if [[ -n $pids ]];
sudo kill -9 $pids
sudo service nginx restart
View rails2_3-ruby1_9-encoding-fix.rb
# Keywords: Rails 2.3, Ruby 1.9
# Error: invalid byte sequence in US-ASCII
# Error: incompatible character encodings: UTF-8 and ASCII-8BIT
# This patch overwrites every ActionView::Helpers::TagHelper
# method and the "value" and "value_before_type_cast" methods
# of ActionView::Helpers::InstanceTag, to force the UTF8
# encoding on their return value, if applicable.
# This is done because the source encoding of Rails' files is
# NOTICE: to get Nginx+Unicorn best-practices configuration see the gist
$ cd /usr/src
$ wget
$ tar xzvf ./nginx-1.2.1.tar.gz && rm -f ./nginx-1.2.1.tar.gz
$ wget
$ tar xzvf pcre-8.30.tar.gz && rm -f ./pcre-8.30.tar.gz
$ wget
Funfun / app_manageer.rb
Created Aug 8, 2014
Using shoes UI lib i build the app manager tool to control my custom development apps
View app_manageer.rb
require "shoes" do
@result = {}
{name: "[r]abbitmq-server", start: '/usr/local/sbin/rabbitmq-server', stop: '/usr/local/sbin/rabbitmqctl stop'},
{name: "[r]edis-server", start: '/usr/local/bin/redis-server', stop: "kill $(ps aux | grep '[r]edis-server' | awk '{print $2}')"},
{name: 'mongodb', start: '/usr/local/bin/mongod --config /usr/local/etc/mongod.conf --fork', stop: "kill $(ps aux | grep '[m]ongod' | awk '{print $2}')"},
{name: 'mysql', start: '/usr/local/bin/mysql.server start', stop: "/usr/local/bin/mysql.server stop"},
View rspec-syntax-cheat-sheet.rb
# RSpec 2.0 syntax Cheet Sheet by
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
Funfun / .ctags
Created Oct 1, 2014
Ctags config for #dotfile
View .ctags
--regex-Go=/func([ \t]+\([^)]+\))?[ \t]+([a-zA-Z0-9_]+)/\2/d,func/
--regex-Go=/var[ \t]+([a-zA-Z_][a-zA-Z0-9_]+)/\1/d,var/
--regex-Go=/type[ \t]+([a-zA-Z_][a-zA-Z0-9_]+)/\1/d,type/
View gist:10971100a066e1ffadf5
package main
import (
func main() {
file, _ := os.Open("test.go")