我很难(重新)启动Unicorn,因为我正在使用Capistrano以及手动部署。
这是deploy.rb
:
# config valid only for current version of Capistrano
lock "3.8.1"
set :application, "project"
set :repo_url, "git@bitbucket.org:username/project.git"
set :branch, "master"
set :tmp_dir, '/home/deployer/tmp'
set :deploy_to, "/home/deployer/apps/project"
set :keep_releases, 5
set(:executable_config_files, %w(
unicorn_init.sh
))
# files which need to be symlinked to other parts of the
# filesystem. For example nginx virtualhosts, log rotation
# init scripts etc.
set(:symlinks, [
{
source: "nginx.conf",
link: "/etc/nginx/sites-enabled/default"
},
{
source: "unicorn_init.sh",
link: "/etc/init.d/unicorn_#{fetch(:application)}"
},
{
source: "log_rotation",
link: "/etc/logrotate.d/#{fetch(:application)}"
},
{
source: "monit",
link: "/etc/monit/conf.d/#{fetch(:application)}.conf"
}
])
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
invoke 'unicorn:restart'
end
end
after :publishing, :restart
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
desc "Make sure local git is in sync with remote."
task :check_revision do
on roles(:web) do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
end
before "deploy", "deploy:check_revision"
end
在这个部署过程中,这是Capistrano给我的错误:
SSHKit::Runner::ExecuteError: Exception while executing as deployer@IP: Exception while executing as deployer@IP: bundle exit status: 1
bundle stdout: Nothing written
bundle stderr: master failed to start, check stderr log for details
这是独角兽日志:
I, [2017-07-26T09:27:41.274475 #21301] INFO -- : Refreshing Gem list
E, [2017-07-26T09:27:44.101407 #21301] ERROR -- : adding listener failed addr=/tmp/unicorn.project.sock (in use)
E, [2017-07-26T09:27:44.101620 #21301] ERROR -- : retrying in 0.5 seconds (4 tries left)
E, [2017-07-26T09:27:44.602753 #21301] ERROR -- : adding listener failed addr=/tmp/unicorn.project.sock (in use)
E, [2017-07-26T09:27:44.603927 #21301] ERROR -- : retrying in 0.5 seconds (3 tries left)
E, [2017-07-26T09:27:45.106551 #21301] ERROR -- : adding listener failed addr=/tmp/unicorn.project.sock (in use)
E, [2017-07-26T09:27:45.107051 #21301] ERROR -- : retrying in 0.5 seconds (2 tries left)
E, [2017-07-26T09:27:45.608434 #21301] ERROR -- : adding listener failed addr=/tmp/unicorn.project.sock (in use)
E, [2017-07-26T09:27:45.608617 #21301] ERROR -- : retrying in 0.5 seconds (1 tries left)
E, [2017-07-26T09:27:46.109480 #21301] ERROR -- : adding listener failed addr=/tmp/unicorn.project.sock (in use)
E, [2017-07-26T09:27:46.109664 #21301] ERROR -- : retrying in 0.5 seconds (0 tries left)
E, [2017-07-26T09:27:46.611021 #21301] ERROR -- : adding listener failed addr=/tmp/unicorn.project.sock (in use)
bundler: failed to load command: unicorn (/home/deployer/apps/project/shared/bundle/ruby/2.4.0/bin/unicorn)
Errno::EADDRINUSE: Address already in use - connect(2) for /tmp/unicorn.project.sock
/home/deployer/apps/project/shared/bundle/ruby/2.4.0/gems/unicorn-5.2.0/lib/unicorn/socket_helper.rb:122:in `initialize'
It says ** Errno::EADDRINUSE: Address already in use - connect(2) for /tmp/unicorn.project.sock** -- however, what does it mean exactly? How to fix it?
I tried to run Unicorn also manually from the server - `bundle exec unicorn -D -c config/unicorn/production.rb -E production`, but only got
> master failed to start, check stderr log for details
that's pointing out on the error message from the log above.
编辑:独角兽的实例
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
rails 2134 0.0 0.5 13620 5640 ? Ss Jul24 0:00 /bin/bash /home/rails/rails_project/.unicorn.sh
rails 2347 0.0 1.6 91052 17136 ? Sl Jul24 0:04 unicorn master -c /etc/unicorn.conf -E production --debug
rails 2349 0.0 7.3 270292 74716 ? Sl Jul24 0:10 unicorn worker[0] -c /etc/unicorn.conf -E production --debug
rails 2352 0.0 7.5 270420 77188 ? Sl Jul24 0:09 unicorn worker[1] -c /etc/unicorn.conf -E production --debug
rails 2354 0.0 7.4 270628 75236 ? Sl Jul24 0:09 unicorn worker[2] -c /etc/unicorn.conf -E production --debug
rails 2358 0.0 7.6 270288 77312 ? Sl Jul24 0:10 unicorn worker[3] -c /etc/unicorn.conf -E production --debug
deployer 9330 0.0 7.9 269032 80364 ? Sl 08:36 0:02 unicorn master -c /home/deployer/apps/project/current/config/unicorn/production.rb -E deployment -D
deployer 9334 0.0 7.2 269560 73800 ? Sl 08:36 0:00 unicorn worker[0] -c /home/deployer/apps/project/current/config/unicorn/production.rb -E deployment -D
deployer 9337 0.0 7.2 269560 73800 ? Sl 08:36 0:00 unicorn worker[1] -c /home/deployer/apps/project/current/config/unicorn/production.rb -E deployment -D
deployer 9340 0.0 7.2 269560 73748 ? Sl 08:36 0:00 unicorn worker[2] -c /home/deployer/apps/project/current/config/unicorn/production.rb -E deployment -D
deployer 24279 0.0 0.1 12948 1080 pts/0 S+ 11:13 0:00 grep --color=auto %CPU\|unicorn