Skip to content

Instantly share code, notes, and snippets.

@danmaispace
Forked from wlangstroth/deploy.rb
Created September 4, 2013 07:53
Show Gist options
  • Save danmaispace/6433942 to your computer and use it in GitHub Desktop.
Save danmaispace/6433942 to your computer and use it in GitHub Desktop.

Revisions

  1. @wlangstroth wlangstroth revised this gist Mar 19, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nginx.conf
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ server {

    server {
    server_name www.example.net;
    root /srv/net/public;
    root /srv/net/current/public;

    location / {
    try_files $uri @net;
  2. @wlangstroth wlangstroth revised this gist Mar 19, 2013. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions deploy.rb
    Original file line number Diff line number Diff line change
    @@ -24,19 +24,19 @@
    set :rack_env, :production

    set :deploy_to, "/srv/#{application}"
    set :unicorn_conf, "#{release_path}/config/unicorn.rb"
    set :unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid"
    set :unicorn_conf, "#{current_path}/config/unicorn.rb"
    set :unicorn_pid, "#{shared_path}/pids/unicorn.pid"

    set :public_children, ["css","img","js"]

    namespace :deploy do

    task :restart do
    run "if [ -f #{unicorn_pid} ]; then kill -USR2 `cat #{unicorn_pid}`; else cd #{deploy_to}/current && bundle exec unicorn -c #{unicorn_conf} -E #{rack_env} -D; fi"
    run "if [ -f #{unicorn_pid} ]; then kill -USR2 `cat #{unicorn_pid}`; else cd #{current_path} && bundle exec unicorn -c #{unicorn_conf} -E #{rack_env} -D; fi"
    end

    task :start do
    run "cd #{deploy_to}/current && bundle exec unicorn -c #{unicorn_conf} -E #{rack_env} -D"
    run "cd #{current_path} && bundle exec unicorn -c #{unicorn_conf} -E #{rack_env} -D"
    end

    task :stop do
  3. @wlangstroth wlangstroth revised this gist Feb 8, 2013. 1 changed file with 3 additions and 8 deletions.
    11 changes: 3 additions & 8 deletions unicorn.rb
    Original file line number Diff line number Diff line change
    @@ -8,26 +8,21 @@
    old_pid = pid_file + '.oldbin'

    timeout 30
    worker_processes 4
    worker_processes 2
    listen socket_file, :backlog => 1024

    pid pid_file
    stderr_path err_log
    stdout_path log_file

    # make sure that Bundler finds the Gemfile
    before_exec do |server|
    ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', File.dirname(__FILE__))
    end

    before_fork do |server, worker|
    # zero downtime deploy magic:
    # if unicorn is already running, ask it to start a new process and quit.
    if File.exists?(old_pid) && server.pid != old_pid
    begin
    Process.kill("QUIT", File.read(old_pid).to_i)
    rescue Errno::ENOENT, Errno::ESRCH
    # someone else did our job for us
    # already done
    end
    end
    end
    end
  4. @wlangstroth wlangstroth revised this gist Feb 8, 2013. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions deploy.rb
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    require 'bundler/capistrano'

    set :application, "lila"
    set :repository, "git@ministryofcomputation.com:lila.git"
    set :application, "net"
    set :repository, "git@githost.com:net.git"

    set :scm, :git

    @@ -17,7 +17,7 @@
    set :group, user
    set :runner, user

    set :host, "#{user}@ministryofcomputation.com"
    set :host, "#{user}@host.com"
    role :web, host
    role :app, host

  5. @wlangstroth wlangstroth revised this gist Feb 8, 2013. 1 changed file with 10 additions and 13 deletions.
    23 changes: 10 additions & 13 deletions deploy.rb
    Original file line number Diff line number Diff line change
    @@ -1,36 +1,33 @@
    $:.unshift(File.expand_path('./lib', ENV['rvm_path']))

    require 'rvm/capistrano'
    require 'bundler/capistrano'

    set :rvm_ruby_string, '1.9.3'
    set :rvm_type, :user

    set :application, "net"
    set :repository, "[email protected]:net.git"
    set :application, "lila"
    set :repository, "[email protected]:lila.git"

    set :scm, :git

    set :default_environment, {
    'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH"
    }

    set :use_sudo, false
    set(:run_method) { use_sudo ? :sudo : :run }

    default_run_options[:pty] = true

    set :user, "deployer"
    set :group, user
    set :runner, user

    set :host, "#{user}@example.net"
    set :host, "#{user}@ministryofcomputation.com"
    role :web, host
    role :app, host

    set :rack_env, :production

    set :deploy_to, "/srv/#{application}"
    set :unicorn_conf, "#{deploy_to}/current/config/unicorn.rb"
    set :unicorn_conf, "#{release_path}/config/unicorn.rb"
    set :unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid"

    set :public_children, ["img","js","css"] # comment out to keep the default ["images" ...]
    set :public_children, ["css","img","js"]

    namespace :deploy do

    @@ -46,4 +43,4 @@
    run "if [ -f #{unicorn_pid} ]; then kill -QUIT `cat #{unicorn_pid}`; fi"
    end

    end
    end
  6. @wlangstroth wlangstroth revised this gist Sep 18, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nginx.conf
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    pstream net_unicorn {
    upstream net_unicorn {
    server unix:/srv/net/shared/unicorn.sock fail_timeout=0;
    }

  7. @wlangstroth wlangstroth revised this gist Sep 18, 2012. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions unicorn.rb
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    # define paths and filenames
    deploy_to = "/srv/net"
    rails_root = "#{deploy_to}/current"
    rack_root = "#{deploy_to}/current"
    pid_file = "#{deploy_to}/shared/pids/unicorn.pid"
    socket_file= "#{deploy_to}/shared/unicorn.sock"
    log_file = "#{rails_root}/log/unicorn.log"
    err_log = "#{rails_root}/log/unicorn_error.log"
    log_file = "#{rack_root}/log/unicorn.log"
    err_log = "#{rack_root}/log/unicorn_error.log"
    old_pid = pid_file + '.oldbin'

    timeout 30
  8. @wlangstroth wlangstroth revised this gist Sep 18, 2012. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions unicorn.rb
    Original file line number Diff line number Diff line change
    @@ -15,9 +15,6 @@
    stderr_path err_log
    stdout_path log_file

    # make forks faster
    preload_app true

    # make sure that Bundler finds the Gemfile
    before_exec do |server|
    ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', File.dirname(__FILE__))
  9. @wlangstroth wlangstroth renamed this gist Sep 18, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  10. @wlangstroth wlangstroth renamed this gist Sep 18, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  11. @invalid-email-address Anonymous created this gist Sep 18, 2012.
    49 changes: 49 additions & 0 deletions deploy.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    $:.unshift(File.expand_path('./lib', ENV['rvm_path']))

    require 'rvm/capistrano'
    require 'bundler/capistrano'

    set :rvm_ruby_string, '1.9.3'
    set :rvm_type, :user

    set :application, "net"
    set :repository, "[email protected]:net.git"

    set :scm, :git

    set :use_sudo, false
    set(:run_method) { use_sudo ? :sudo : :run }

    default_run_options[:pty] = true

    set :user, "deployer"
    set :group, user
    set :runner, user

    set :host, "#{user}@example.net"
    role :web, host
    role :app, host

    set :rack_env, :production

    set :deploy_to, "/srv/#{application}"
    set :unicorn_conf, "#{deploy_to}/current/config/unicorn.rb"
    set :unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid"

    set :public_children, ["img","js","css"] # comment out to keep the default ["images" ...]

    namespace :deploy do

    task :restart do
    run "if [ -f #{unicorn_pid} ]; then kill -USR2 `cat #{unicorn_pid}`; else cd #{deploy_to}/current && bundle exec unicorn -c #{unicorn_conf} -E #{rack_env} -D; fi"
    end

    task :start do
    run "cd #{deploy_to}/current && bundle exec unicorn -c #{unicorn_conf} -E #{rack_env} -D"
    end

    task :stop do
    run "if [ -f #{unicorn_pid} ]; then kill -QUIT `cat #{unicorn_pid}`; fi"
    end

    end
    24 changes: 24 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    pstream net_unicorn {
    server unix:/srv/net/shared/unicorn.sock fail_timeout=0;
    }

    server {
    server_name example.net;
    rewrite ^(.*) http://www.example.net$1 permanent;
    }

    server {
    server_name www.example.net;
    root /srv/net/public;

    location / {
    try_files $uri @net;
    }

    location @net {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://net_unicorn;
    }
    }
    36 changes: 36 additions & 0 deletions unicorn.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    # define paths and filenames
    deploy_to = "/srv/net"
    rails_root = "#{deploy_to}/current"
    pid_file = "#{deploy_to}/shared/pids/unicorn.pid"
    socket_file= "#{deploy_to}/shared/unicorn.sock"
    log_file = "#{rails_root}/log/unicorn.log"
    err_log = "#{rails_root}/log/unicorn_error.log"
    old_pid = pid_file + '.oldbin'

    timeout 30
    worker_processes 4
    listen socket_file, :backlog => 1024

    pid pid_file
    stderr_path err_log
    stdout_path log_file

    # make forks faster
    preload_app true

    # make sure that Bundler finds the Gemfile
    before_exec do |server|
    ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', File.dirname(__FILE__))
    end

    before_fork do |server, worker|
    # zero downtime deploy magic:
    # if unicorn is already running, ask it to start a new process and quit.
    if File.exists?(old_pid) && server.pid != old_pid
    begin
    Process.kill("QUIT", File.read(old_pid).to_i)
    rescue Errno::ENOENT, Errno::ESRCH
    # someone else did our job for us
    end
    end
    end