Last active
June 11, 2016 14:33
-
-
Save rummelonp/4109368 to your computer and use it in GitHub Desktop.
Revisions
-
rummelonp revised this gist
Jan 12, 2013 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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} && 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} && bundle exec unicorn -c #{unicorn_config} -E #{rails_env} -D" end end -
rummelonp revised this gist
Dec 15, 2012 . 1 changed file with 12 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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; } } -
rummelonp revised this gist
Nov 19, 2012 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 -
rummelonp revised this gist
Nov 19, 2012 . 1 changed file with 21 additions and 30 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,67 +27,58 @@ # Unicorn 用のデーモン操作タスク def remote_file_exists?(full_path) 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 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' next else run "rm #{unicorn_pid}" end end 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...', '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 desc 'Reload Unicorn' task :reload, :roles => :app, :except => {:no_release => true} do 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...', '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 stop start end end -
rummelonp revised this gist
Nov 19, 2012 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ [Ubuntu+Nginx+Unicorn+Rails+Capistrano — Gist](https://gist.github.com/4106900) この記事から設定を例として抽出 定義更新する -
rummelonp created this gist
Nov 19, 2012 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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; } } This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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'