Answer the question
In order to leave comments, you need to log in
How to deploy unicorn via capistrano 3?
Good evening.
Trying to deploy a site, my script is capistrano.
gems
gem "capistrano", "~> 3.0.1"
gem "capistrano-rvm", "~> 0.0.3"
gem "capistrano-bundler", "~> 1.0.0"
gem "capistrano-rails", "~> 1.1.0"
gem "unicorn", "~> 4.7.0"
project_name = 'my_project'
root = "/var/www/#{ project_name }/current"
working_directory root
pid "#{root}/tmp/pids/unicorn.pid"
stderr_path "#{root}/log/unicorn.stderr.log"
stdout_path "#{root}/log/unicorn.stdout.log"
listen "#{root}/tmp/sockets/unicorn.sock"
worker_processes 2
timeout 30
set :application, 'my_project'
set :repo_url, '[email protected]*****************.git'
set :deploy_to, '/var/www/my_project'
set :scm, :git
set :branch, "trunk"
set :linked_files, %w{config/database.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set :rvm_type, :system
set :rvm_ruby_version, '[email protected]_gemset'
set :keep_releases, 10
set :rails_env, "production"
namespace :deploy do
desc 'Restart application'
task :restart do
invoke 'deploy:unicorn:restart'
end
after :finishing, 'deploy:cleanup'
namespace :unicorn do
pid_path = "#{release_path}/tmp/pids"
unicorn_pid = "#{pid_path}/unicorn.pid"
def run_unicorn
execute "cd #{current_path} ; bundle exec unicorn_rails -E #{fetch(:rails_env)}"
end
desc 'Start unicorn'
task :start do
on roles(:app) do
run_unicorn
end
end
desc 'Stop unicorn'
task :stop do
on roles(:app) do
if test "[ -f #{unicorn_pid} ]"
execute :kill, "-QUIT `cat #{unicorn_pid}`"
end
end
end
desc 'Force stop unicorn (kill -9)'
task :force_stop do
on roles(:app) do
if test "[ -f #{unicorn_pid} ]"
execute :kill, "-9 `cat #{unicorn_pid}`"
execute :rm, unicorn_pid
end
end
end
desc 'Restart unicorn'
task :restart do
on roles(:app) do
if test "[ -f #{unicorn_pid} ]"
execute :kill, "-USR2 `cat #{unicorn_pid}`"
else
run_unicorn
end
end
end
end
end
Running cd /var/www/my_project/current ; bundle exec unicorn_rails -E production on 192.168.**.**
DEBUG [829b451b] Command: cd /var/www/my_project/current ; bundle exec unicorn_rails -E production
cap aborted!
cd /var/www/my_project/current ; bundle exec unicorn_rails -E production stdout: Nothing written
cd /var/www/my_project/current ; bundle exec unicorn_rails -E production stderr: Nothing written
Answer the question
In order to leave comments, you need to log in
I also suffered with this
1. Instead of unicorn_rails, you just need to use unicorn
2. Specifying the path to rvm also helped me
RAILS_ENV=#{fetch(:stage)} /usr/local/rvm/bin/rvm default do
before bundledef run_unicorn
execute cd #{release_path} && ("RAILS_ENV=#{fetch(:stage)} /usr/local/rvm/bin/rvm default do bundle exec unicorn -E #{fetch(:rails_env)})"
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question