From 653aad2c76353cf9535a9dc31e833cfa2a7b798a Mon Sep 17 00:00:00 2001 From: Bob Breznak Date: Wed, 7 Aug 2013 15:00:20 -0400 Subject: [PATCH 1/3] Add setup and symlink tasks --- lib/capistrano-unicorn/capistrano_integration.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/capistrano-unicorn/capistrano_integration.rb b/lib/capistrano-unicorn/capistrano_integration.rb index 17030aa..0b6c7eb 100644 --- a/lib/capistrano-unicorn/capistrano_integration.rb +++ b/lib/capistrano-unicorn/capistrano_integration.rb @@ -11,7 +11,9 @@ class CapistranoIntegration 'unicorn:reload', 'unicorn:shutdown', 'unicorn:add_worker', - 'unicorn:remove_worker' + 'unicorn:remove_worker', + 'unicorn:setup', + 'unicorn:link_socket_dir' ] def self.load_into(capistrano_config) @@ -26,6 +28,7 @@ def self.load_into(capistrano_config) _cset(:unicorn_user) { nil } _cset(:unicorn_config_path) { "#{fetch(:current_path)}/config" } _cset(:unicorn_config_filename) { "unicorn.rb" } + _cset(:unicorn_shared_socket_dir) { "#{fetch(:shared_path)}/sockets" } end # Check if a remote process exists using its pid file @@ -215,6 +218,17 @@ def unicorn_roles fi; END end + + desc 'Setup project to use Unicorn' + task :setup, :roles => unicorn_roles, :except => {:no_release => true} do + # Create a sockets directory if one doesn't already exist + run "mkdir -p #{unicorn_shared_socket_dir}" + end + + desc 'Link unicorn_shared_socket_dir to tmp/sockets' + task :link_socket_dir, :roles => unicorn_roles, :except => {:no_release => true} do + run "ln -s #{unicorn_shared_socket_dir} #{release_path}/tmp/sockets" + end end end end From 4355c71f94e3117364ad867ac8eb93cf37e6a3fd Mon Sep 17 00:00:00 2001 From: Bob Breznak Date: Wed, 7 Aug 2013 15:06:41 -0400 Subject: [PATCH 2/3] Use latest_release over release_path --- lib/capistrano-unicorn/capistrano_integration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/capistrano-unicorn/capistrano_integration.rb b/lib/capistrano-unicorn/capistrano_integration.rb index 0b6c7eb..7ef228a 100644 --- a/lib/capistrano-unicorn/capistrano_integration.rb +++ b/lib/capistrano-unicorn/capistrano_integration.rb @@ -227,7 +227,7 @@ def unicorn_roles desc 'Link unicorn_shared_socket_dir to tmp/sockets' task :link_socket_dir, :roles => unicorn_roles, :except => {:no_release => true} do - run "ln -s #{unicorn_shared_socket_dir} #{release_path}/tmp/sockets" + run "ln -s #{unicorn_shared_socket_dir} #{latest_release}/tmp/sockets" end end end From 4ea6ebd31b73e79e05363685e3da0bdafd3d5ad4 Mon Sep 17 00:00:00 2001 From: Bob Breznak Date: Wed, 7 Aug 2013 15:13:02 -0400 Subject: [PATCH 3/3] Update README with new tasks and hooks instructions --- README.md | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 592cc78..679565a 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,12 @@ And load it into your deployment script `config/deploy.rb`: require 'capistrano-unicorn' ``` +Add unicorn setup task hook: + +```ruby +after 'deploy:setup', 'unicorn:setup' # Needed if you've configured Unicorn to use a UNIX Socket file. +``` + Add unicorn restart task hook: ```ruby @@ -35,6 +41,12 @@ after 'deploy:restart', 'unicorn:reload' # app IS NOT preloaded after 'deploy:restart', 'unicorn:restart' # app preloaded ``` +Add unicorn shared sockets hook: + +```ruby +after 'deploy:finalize_update', 'unicorn:link_socket_dir' # Needed if you've configured Unicorn to use a UNIX Socket file +``` + Create a new configuration file `config/unicorn.rb` or `config/unicorn/STAGE.rb`, where stage is your deployment environment. Example config - [examples/rails3.rb](https://github.com/sosedoff/capistrano-unicorn/blob/master/examples/rails3.rb). Please refer to unicorn documentation for more examples and configuration options. @@ -59,14 +71,15 @@ cap unicorn:reload You can modify any of the following options in your `deploy.rb` config. -- `unicorn_env` - Set unicorn environment. Default to `rails_env` variable. -- `unicorn_pid` - Set unicorn PID file path. Default to `current_path/tmp/pids/unicorn.pid` -- `unicorn_bin` - Set unicorn executable file. Default to `unicorn`. -- `unicorn_bundle` - Set bundler command for unicorn. Default to `bundle`. -- `unicorn_user` - Launch unicorn master as the specified user. Default to `user` variable. -- `unicorn_roles` - Define which roles to perform unicorn recpies on. Default to `:app`. -- `unicorn_config_path` - Set the directory where unicorn config files reside. Default to `current_path/config`. -- `unicorn_config_filename` - Set the filename of the unicorn config file. Not used in multistage installations. Default to `unicorn.rb`. +- `unicorn_env` - Set unicorn environment. Default to `rails_env` variable. +- `unicorn_pid` - Set unicorn PID file path. Default to `current_path/tmp/pids/unicorn.pid` +- `unicorn_bin` - Set unicorn executable file. Default to `unicorn`. +- `unicorn_bundle` - Set bundler command for unicorn. Default to `bundle`. +- `unicorn_user` - Launch unicorn master as the specified user. Default to `user` variable. +- `unicorn_roles` - Define which roles to perform unicorn recpies on. Default to `:app`. +- `unicorn_config_path` - Set the directory where unicorn config files reside. Default to `current_path/config`. +- `unicorn_config_filename` - Set the filename of the unicorn config file. Not used in multistage installations. Default to `unicorn.rb`. +- `unicorn_shared_socket_dir` - Set the shared socket path where the unicorn sockets should live. Default to `shared_path/sockets`. ### Multistage @@ -84,6 +97,8 @@ cap unicorn:restart # Restart Unicorn cap unicorn:shutdown # Immediately shutdown Unicorn cap unicorn:start # Start Unicorn master process cap unicorn:stop # Stop Unicorn +cap unicorn:setup # Setup the project (i.e. create the shared sockets directory) +cap unicorn:link_socket_dir # Link the shared sockets directory to tmp/sockets ``` ## License