[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Instantly share code, notes, and snippets.

@rummelonp
Last active June 11, 2016 14:33
Show Gist options
  • Save rummelonp/4109368 to your computer and use it in GitHub Desktop.
Save rummelonp/4109368 to your computer and use it in GitHub Desktop.

Revisions

  1. rummelonp revised this gist Jan 12, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions deploy.rb
    Original file line number Diff line number Diff line change
    @@ -50,7 +50,7 @@ def process_exists?(pid_file)
    end

    logger.important 'Starting Unicorn...', 'Unicorn'
    run "cd #{current_path} && unicorn -c #{unicorn_config} -E #{rails_env} -D"
    run "cd #{current_path} && bundle exec unicorn -c #{unicorn_config} -E #{rails_env} -D"
    end

    desc 'Stop Unicorn'
    @@ -75,7 +75,7 @@ def process_exists?(pid_file)
    run "kill -s HUP `cat #{unicorn_pid}`"
    else
    logger.important 'No PIDs found. Starting Unicorn...', 'Unicorn'
    run "cd #{current_path} && unicorn -c #{unicorn_config} -E #{rails_env} -D"
    run "cd #{current_path} && bundle exec unicorn -c #{unicorn_config} -E #{rails_env} -D"
    end
    end

  2. rummelonp revised this gist Dec 15, 2012. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -16,4 +16,16 @@ server {
    proxy_set_header Host $http_host;
    proxy_pass http://unicorn.app.com;
    }

    location = /favicon.ico {
    }

    location = /robots.txt {
    }

    location ~ ^/(assets|images|javascripts|stylesheets|system)/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
    }
    }
  3. rummelonp revised this gist Nov 19, 2012. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion deploy.rb
    Original file line number Diff line number Diff line change
    @@ -20,6 +20,9 @@

    server domain, :app, :web

    # 再起動後に古い releases を cleanup
    after 'deploy:restart', 'deploy:cleanup'

    # Unicorn 用の設定
    set :unicorn_config, "#{current_path}/config/unicorn.rb"
    set :unicorn_bin, 'unicorn'
    @@ -81,4 +84,4 @@ def process_exists?(pid_file)
    stop
    start
    end
    end
    end
  4. rummelonp revised this gist Nov 19, 2012. 1 changed file with 21 additions and 30 deletions.
    51 changes: 21 additions & 30 deletions deploy.rb
    Original file line number Diff line number Diff line change
    @@ -27,67 +27,58 @@

    # Unicorn 用のデーモン操作タスク
    def remote_file_exists?(full_path)
    'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
    capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip == 'true'
    end

    def process_exists?(pid_file)
    capture("ps -p $(cat #{pid_file}) ; true").strip.split("\n").size == 2
    capture("ps -p `cat #{pid_file}`; true").strip.split("\n").size == 2
    end

    namespace :deploy do
    desc 'Start Unicorn'
    task :start, roles: :app, except: {no_release: true} do
    if remote_file_exists?(unicorn_pid)
    if process_exists?(unicorn_pid)
    logger.important('Unicorn is already running!', 'Unicorn')
    if remote_file_exists? unicorn_pid
    if process_exists? unicorn_pid
    logger.important 'Unicorn is already running!', 'Unicorn'
    next
    else
    run "rm #{unicorn_pid}"
    end
    end

    logger.important('Starting...', 'Unicorn')
    logger.important 'Starting Unicorn...', 'Unicorn'
    run "cd #{current_path} && unicorn -c #{unicorn_config} -E #{rails_env} -D"
    end

    desc 'Stop Unicorn'
    task :stop, :roles => :app, :except => {:no_release => true} do
    if remote_file_exists?(unicorn_pid)
    if process_exists?(unicorn_pid)
    logger.important('Stopping...', 'Unicorn')
    run "kill `cat #{unicorn_pid}`"
    else
    run "rm #{unicorn_pid}"
    logger.important('Unicorn is not running.', 'Unicorn')
    end
    else
    logger.important('No PIDs found. Check if unicorn is running.', 'Unicorn')
    end
    end

    task :graceful_stop, :roles => :app, :except => {:no_release => true} do
    if remote_file_exists?(unicorn_pid)
    if process_exists?(unicorn_pid)
    logger.important('Stopping...', 'Unicorn')
    if remote_file_exists? unicorn_pid
    if process_exists? unicorn_pid
    logger.important 'Stopping Unicorn...', 'Unicorn'
    run "kill -s QUIT `cat #{unicorn_pid}`"
    else
    run "rm #{unicorn_pid}"
    logger.important('Unicorn is not running.', 'Unicorn')
    logger.important 'Unicorn is not running.', 'Unicorn'
    end
    else
    logger.important('No PIDs found. Check if unicorn is running.', 'Unicorn')
    logger.important 'No PIDs found. Check if unicorn is running.', 'Unicorn'
    end
    end

    desc 'Reload Unicorn'
    task :reload, :roles => :app, :except => {:no_release => true} do
    if remote_file_exists?(unicorn_pid)
    logger.important('Stopping...', 'Unicorn')
    run "kill -s USR2 `cat #{unicorn_pid}`"
    if remote_file_exists? unicorn_pid
    logger.important 'Reloading Unicorn...', 'Unicorn'
    run "kill -s HUP `cat #{unicorn_pid}`"
    else
    logger.important('No PIDs found. Starting Unicorn server...', 'Unicorn')
    logger.important 'No PIDs found. Starting Unicorn...', 'Unicorn'
    run "cd #{current_path} && unicorn -c #{unicorn_config} -E #{rails_env} -D"
    end
    end

    desc 'Restart Unicorn'
    task :restart, :roles => :app, :except => {:no_release => true} do
    reload
    stop
    start
    end
    end
  5. rummelonp revised this gist Nov 19, 2012. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions 0-README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    [Ubuntu+Nginx+Unicorn+Rails+Capistrano — Gist](https://gist.github.com/4106900)

    この記事から設定を例として抽出
    定義更新する
  6. rummelonp created this gist Nov 19, 2012.
    93 changes: 93 additions & 0 deletions deploy.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,93 @@
    # -*- coding: utf-8 -*-

    # deploy 時に自動で bundle install
    require 'bundler/capistrano'

    # deploy 時に自動で rake assets:precompile
    load 'deploy/assets'

    # アプリケーションの設定
    set :application, 'app'
    set :domain, 'app.com'
    set :rails_env, 'production'

    set :repository, 'file://.'
    set :branch, 'production'

    set :deploy_via, :copy
    set :deploy_to, '/var/www/app'
    set :use_sudo, false

    server domain, :app, :web

    # Unicorn 用の設定
    set :unicorn_config, "#{current_path}/config/unicorn.rb"
    set :unicorn_bin, 'unicorn'
    set :unicorn_pid, '/tmp/unicorn.app.pid'

    # Unicorn 用のデーモン操作タスク
    def remote_file_exists?(full_path)
    'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
    end

    def process_exists?(pid_file)
    capture("ps -p $(cat #{pid_file}) ; true").strip.split("\n").size == 2
    end

    namespace :deploy do
    task :start, roles: :app, except: {no_release: true} do
    if remote_file_exists?(unicorn_pid)
    if process_exists?(unicorn_pid)
    logger.important('Unicorn is already running!', 'Unicorn')
    next
    else
    run "rm #{unicorn_pid}"
    end
    end

    logger.important('Starting...', 'Unicorn')
    run "cd #{current_path} && unicorn -c #{unicorn_config} -E #{rails_env} -D"
    end

    task :stop, :roles => :app, :except => {:no_release => true} do
    if remote_file_exists?(unicorn_pid)
    if process_exists?(unicorn_pid)
    logger.important('Stopping...', 'Unicorn')
    run "kill `cat #{unicorn_pid}`"
    else
    run "rm #{unicorn_pid}"
    logger.important('Unicorn is not running.', 'Unicorn')
    end
    else
    logger.important('No PIDs found. Check if unicorn is running.', 'Unicorn')
    end
    end

    task :graceful_stop, :roles => :app, :except => {:no_release => true} do
    if remote_file_exists?(unicorn_pid)
    if process_exists?(unicorn_pid)
    logger.important('Stopping...', 'Unicorn')
    run "kill -s QUIT `cat #{unicorn_pid}`"
    else
    run "rm #{unicorn_pid}"
    logger.important('Unicorn is not running.', 'Unicorn')
    end
    else
    logger.important('No PIDs found. Check if unicorn is running.', 'Unicorn')
    end
    end

    task :reload, :roles => :app, :except => {:no_release => true} do
    if remote_file_exists?(unicorn_pid)
    logger.important('Stopping...', 'Unicorn')
    run "kill -s USR2 `cat #{unicorn_pid}`"
    else
    logger.important('No PIDs found. Starting Unicorn server...', 'Unicorn')
    run "cd #{current_path} && unicorn -c #{unicorn_config} -E #{rails_env} -D"
    end
    end

    task :restart, :roles => :app, :except => {:no_release => true} do
    reload
    end
    end
    19 changes: 19 additions & 0 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    upstream unicorn.app.com {
    server unix:/tmp/unicorn.app.sock;
    }

    server {
    listen 80;
    server_name app.com;
    root /var/www/app/current/public;

    access_log /var/log/nginx/app.access.log;
    error_log /var/log/nginx/app.error.log;

    location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_pass http://unicorn.app.com;
    }
    }
    10 changes: 10 additions & 0 deletions unicorn.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    # -*- coding: utf-8 -*-

    worker_processes 3

    listen '/tmp/unicorn.app.sock'

    pid '/tmp/unicorn.app.pid'

    stderr_path 'log/unicorn.log'
    stdout_path 'log/unicorn.log'