无法正确启动 unicorn,出现错误 "already running"
Can't start unicorn properly with error "already running"
我想使用 capistrano
将 rails 项目部署到 Ubuntu 14.04 服务器,并让它 运行 使用 unicorn
。
我创建了一个这样的 unicorn:start
任务:
namespace :unicorn do
task :environment do
set :unicorn_pid, "#{shared_path}/tmp/pids/unicorn.pid"
set :unicorn_config, "#{current_path}/config/unicorn/#{fetch(:rails_env)}.rb"
end
def start_unicorn
within current_path do
execute :bundle, :exec, :unicorn, "-c #{fetch(:unicorn_config)} -E #{fetch(:rails_env)} -D"
end
end
desc "Start unicorn server"
task :start => :environment do
on roles(:app) do
start_unicorn
end
end
end
这是bundle exec cap production unicorn:start
的结果
DEBUG [525e1e88] Running /usr/bin/env [ -d ~/.rbenv/versions/2.2.3 ] as deployer@us.example.com
DEBUG [525e1e88] Command: [ -d ~/.rbenv/versions/2.2.3 ]
DEBUG [525e1e88] Finished in 0.465 seconds with exit status 0 (successful).
DEBUG [6dc9e26a] Running /usr/bin/env if test ! -d /var/www/us.example.com/current; then echo "Directory does not exist '/var/www/us.example.com/current'" 1>&2; false; fi as deployer@us.example.com
DEBUG [6dc9e26a] Command: if test ! -d /var/www/us.example.com/current; then echo "Directory does not exist '/var/www/us.example.com/current'" 1>&2; false; fi
DEBUG [6dc9e26a] Finished in 0.052 seconds with exit status 0 (successful).
DEBUG [81c26179] Running /usr/bin/env [ -e /var/www/us.example.com/shared/tmp/pids/unicorn.pid ] && kill -0 `cat /var/www/us.example.com/shared/tmp/pids/unicorn.pid` as deployer@us.example.com
DEBUG [81c26179] Command: [ -e /var/www/us.example.com/shared/tmp/pids/unicorn.pid ] && kill -0 `cat /var/www/us.example.com/shared/tmp/pids/unicorn.pid`
DEBUG [81c26179] Finished in 0.053 seconds with exit status 1 (failed).
INFO [a5655cfe] Running RBENV_ROOT=~/.rbenv RBENV_VERSION=2.2.3 ~/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/us.example.com/current/config/unicorn/production.rb -E deployment -D as deployer@us.example.com
DEBUG [a5655cfe] Command: cd /var/www/us.example.com/current && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.2.3 RAILS_ENV=production RBENV_ROOT=~/.rbenv RBENV_VERSION=2.2.3 ~/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/us.example.com/current/config/unicorn/production.rb -E deployment -D )
INFO [a5655cfe] Finished in 3.770 seconds with exit status 0 (successful).
DEBUG [dd3f31fa] Running /usr/bin/env if test ! -d /var/www/us.example.com/current; then echo "Directory does not exist '/var/www/us.example.com/current'" 1>&2; false; fi as deployer@us.example.com
DEBUG [dd3f31fa] Command: if test ! -d /var/www/us.example.com/current; then echo "Directory does not exist '/var/www/us.example.com/current'" 1>&2; false; fi
DEBUG [dd3f31fa] Finished in 0.055 seconds with exit status 0 (successful).
INFO [1140efb6] Running RBENV_ROOT=~/.rbenv RBENV_VERSION=2.2.3 ~/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/us.example.com/current/config/unicorn/production.rb -E production -D as deployer@us.example.com
DEBUG [1140efb6] Command: cd /var/www/us.example.com/current && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.2.3 RBENV_ROOT=~/.rbenv RBENV_VERSION=2.2.3 ~/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/us.example.com/current/config/unicorn/production.rb -E production -D )
DEBUG [1140efb6] master failed to start, check stderr log for details
并且在日志中显示 pid=': Already running on PID:10760
。
Unicorn 本身已执行,但不知何故启动过程 运行s 两次,因此第二个 运行ning 过程失败。我可以找到它,但我无法找出为什么 运行ning 过程 运行 两次。
我应该检查什么来解决这个问题?
抱歉有点跑题了。您是否尝试使用现有的 3rd 方插件而不是编写自己的 Capistrano 任务?您可以在以下位置找到它们:
我想使用 capistrano
将 rails 项目部署到 Ubuntu 14.04 服务器,并让它 运行 使用 unicorn
。
我创建了一个这样的 unicorn:start
任务:
namespace :unicorn do
task :environment do
set :unicorn_pid, "#{shared_path}/tmp/pids/unicorn.pid"
set :unicorn_config, "#{current_path}/config/unicorn/#{fetch(:rails_env)}.rb"
end
def start_unicorn
within current_path do
execute :bundle, :exec, :unicorn, "-c #{fetch(:unicorn_config)} -E #{fetch(:rails_env)} -D"
end
end
desc "Start unicorn server"
task :start => :environment do
on roles(:app) do
start_unicorn
end
end
end
这是bundle exec cap production unicorn:start
DEBUG [525e1e88] Running /usr/bin/env [ -d ~/.rbenv/versions/2.2.3 ] as deployer@us.example.com
DEBUG [525e1e88] Command: [ -d ~/.rbenv/versions/2.2.3 ]
DEBUG [525e1e88] Finished in 0.465 seconds with exit status 0 (successful).
DEBUG [6dc9e26a] Running /usr/bin/env if test ! -d /var/www/us.example.com/current; then echo "Directory does not exist '/var/www/us.example.com/current'" 1>&2; false; fi as deployer@us.example.com
DEBUG [6dc9e26a] Command: if test ! -d /var/www/us.example.com/current; then echo "Directory does not exist '/var/www/us.example.com/current'" 1>&2; false; fi
DEBUG [6dc9e26a] Finished in 0.052 seconds with exit status 0 (successful).
DEBUG [81c26179] Running /usr/bin/env [ -e /var/www/us.example.com/shared/tmp/pids/unicorn.pid ] && kill -0 `cat /var/www/us.example.com/shared/tmp/pids/unicorn.pid` as deployer@us.example.com
DEBUG [81c26179] Command: [ -e /var/www/us.example.com/shared/tmp/pids/unicorn.pid ] && kill -0 `cat /var/www/us.example.com/shared/tmp/pids/unicorn.pid`
DEBUG [81c26179] Finished in 0.053 seconds with exit status 1 (failed).
INFO [a5655cfe] Running RBENV_ROOT=~/.rbenv RBENV_VERSION=2.2.3 ~/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/us.example.com/current/config/unicorn/production.rb -E deployment -D as deployer@us.example.com
DEBUG [a5655cfe] Command: cd /var/www/us.example.com/current && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.2.3 RAILS_ENV=production RBENV_ROOT=~/.rbenv RBENV_VERSION=2.2.3 ~/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/us.example.com/current/config/unicorn/production.rb -E deployment -D )
INFO [a5655cfe] Finished in 3.770 seconds with exit status 0 (successful).
DEBUG [dd3f31fa] Running /usr/bin/env if test ! -d /var/www/us.example.com/current; then echo "Directory does not exist '/var/www/us.example.com/current'" 1>&2; false; fi as deployer@us.example.com
DEBUG [dd3f31fa] Command: if test ! -d /var/www/us.example.com/current; then echo "Directory does not exist '/var/www/us.example.com/current'" 1>&2; false; fi
DEBUG [dd3f31fa] Finished in 0.055 seconds with exit status 0 (successful).
INFO [1140efb6] Running RBENV_ROOT=~/.rbenv RBENV_VERSION=2.2.3 ~/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/us.example.com/current/config/unicorn/production.rb -E production -D as deployer@us.example.com
DEBUG [1140efb6] Command: cd /var/www/us.example.com/current && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.2.3 RBENV_ROOT=~/.rbenv RBENV_VERSION=2.2.3 ~/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/us.example.com/current/config/unicorn/production.rb -E production -D )
DEBUG [1140efb6] master failed to start, check stderr log for details
并且在日志中显示 pid=': Already running on PID:10760
。
Unicorn 本身已执行,但不知何故启动过程 运行s 两次,因此第二个 运行ning 过程失败。我可以找到它,但我无法找出为什么 运行ning 过程 运行 两次。
我应该检查什么来解决这个问题?
抱歉有点跑题了。您是否尝试使用现有的 3rd 方插件而不是编写自己的 Capistrano 任务?您可以在以下位置找到它们: