Skip to content

Instantly share code, notes, and snippets.

View tsyber1an's full-sized avatar
🎯
Focusing

Tsyren O. tsyber1an

🎯
Focusing
View GitHub Profile

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

# Kill and restart nginx
function restart_nginx(){
pids=$(pidof nginx)
if [[ -n $pids ]];
then
sudo kill -9 $pids
sudo service nginx restart
fi
}
# 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
alert('test')
# NOTICE: to get Nginx+Unicorn best-practices configuration see the gist https://gist.github.com/3052776
$ cd /usr/src
$ wget http://nginx.org/download/nginx-1.2.1.tar.gz
$ tar xzvf ./nginx-1.2.1.tar.gz && rm -f ./nginx-1.2.1.tar.gz
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
$ tar xzvf pcre-8.30.tar.gz && rm -f ./pcre-8.30.tar.gz
$ wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
@tsyber1an
tsyber1an / app_manageer.rb
Created August 8, 2014 09:20
Using shoes UI lib i build the app manager tool to control my custom development apps
require "shoes"
Shoes.app 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"},
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# 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")
@tsyber1an
tsyber1an / .ctags
Created October 1, 2014 15:01
Ctags config for #dotfile
--langdef=Go
--langmap=Go:.go
--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/
package main
import (
"archive/zip"
"io"
"os"
)
func main() {
file, _ := os.Open("test.go")