ruby 独角兽无法写入pid文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8706088/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unicorn unable to write pid file
提问by Mike Filbin
I am using deploying a Ruby on Rails app to a Linode VPS using Capistrano. I am using Unicorn as the application server and Nginx as the proxy. My problem is that I am not able to start Unicorn because of an apparent permissions issue, but I'm having a hard time tracking it down.
我正在使用 Capistrano 将 Ruby on Rails 应用程序部署到 Linode VPS。我使用 Unicorn 作为应用服务器,使用 Nginx 作为代理。我的问题是,由于明显的权限问题,我无法启动 Unicorn,但我很难对其进行跟踪。
Unicorn is started using this Capistrano task:
Unicorn 开始使用这个 Capistrano 任务:
task :start, :roles => :app, :except => { :no_release => true } do
run <<-CMD
cd #{current_path} && #{unicorn_bin} -c #{unicorn_config} -E #{rails_env} -D
CMD
end
I get back and ArgumentError indicating that the path to the pid file is not writeable.
我回来了,ArgumentError 表明 pid 文件的路径不可写。
cap unicorn:start master [d4447d3] modified
* executing `unicorn:start'
* executing "cd /home/deploy/apps/gogy/current && /home/deploy/apps/gogy/current/bin/unicorn -c /home/deploy/apps/gogy/shared/config/unicorn.rb -E production -D"
servers: ["66.228.52.4"]
[66.228.52.4] executing command
** [out :: 66.228.52.4] /home/deploy/apps/gogy/shared/bundle/ruby/1.8/gems/unicorn-4.1.1/lib/unicorn/configurator.rb:88:in `reload':
** [out :: 66.228.52.4] directory for pid=/home/deploy/apps/shared/pids/unicorn.pid not writable (ArgumentError)
** [out :: 66.228.52.4] from /home/deploy/apps/gogy/shared/bundle/ruby/1.8/gems/unicorn-4.1.1/lib/unicorn/configurator.rb:84:in `each'
** [out :: 66.228.52.4] from /home/deploy/apps/gogy/shared/bundle/ruby/1.8/gems/unicorn-4.1.1/lib/unicorn/configurator.rb:84:in `reload'
** [out :: 66.228.52.4] from /home/deploy/apps/gogy/shared/bundle/ruby/1.8/gems/unicorn-4.1.1/lib/unicorn/configurator.rb:65:in `initialize'
** [out :: 66.228.52.4] from /home/deploy/apps/gogy/shared/bundle/ruby/1.8/gems/unicorn-4.1.1/lib/unicorn/http_server.rb:102:in `new'
** [out :: 66.228.52.4] from /home/deploy/apps/gogy/shared/bundle/ruby/1.8/gems/unicorn-4.1.1/lib/unicorn/http_server.rb:102:in `initialize'
** [out :: 66.228.52.4] from /home/deploy/apps/gogy/shared/bundle/ruby/1.8/gems/unicorn-4.1.1/bin/unicorn:121:in `new'
** [out :: 66.228.52.4] from /home/deploy/apps/gogy/shared/bundle/ruby/1.8/gems/unicorn-4.1.1/bin/unicorn:121
** [out :: 66.228.52.4] from /home/deploy/apps/gogy/current/bin/unicorn:16:in `load'
** [out :: 66.228.52.4] from /home/deploy/apps/gogy/current/bin/unicorn:16
** [out :: 66.228.52.4] master failed to start, check stderr log for details
command finished in 1032ms
failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell 'default' -c 'cd /home/deploy/apps/gogy/current && /home/deploy/apps/gogy/current/bin/unicorn -c /home/deploy/apps/gogy/shared/config/unicorn.rb -E production -D'" on 66.228.52.4
Finally, here is the relevant sections of my Unicorn configuration file (unicorn.rb)
最后,这里是我的 Unicorn 配置文件(unicorn.rb)的相关部分
# Ensure that we're running in the production environment
rails_env = ENV['RAILS_ENV'] || 'production'
# User to run under
user 'deploy', 'deploy'
# We will spawn off two worker processes and one master process
worker_processes 2
# set the default working directory
working_directory "/home/deploy/apps/gogy/current"
# This loads the application in the master process before forking
# worker processes
# Read more about it here:
# http://unicorn.bogomips.org/Unicorn/Configurator.html
preload_app true
timeout 30
# This is where we specify the socket.
# We will point the upstream Nginx module to this socket later on
listen "/home/deploy/apps/shared/sockets/unicorn.sock", :backlog => 64
pid "/home/deploy/apps/shared/pids/unicorn.pid"
# Set the path of the log files
stderr_path "/home/deploy/apps/gogy/current/log/unicorn.stderr.log"
stdout_path "/home/deploy/apps/gogy/current/log/unicorn.stdout.log"
I'm deploying with Capistrano under the 'deploy' user and group and that's what Unicorn should be run under also.
我正在“部署”用户和组下使用 Capistrano 进行部署,这也是 Unicorn 也应该在其下运行的。
Does anyone have any ideas why Unicorn can't write out the pid file? Any help would be greatly appreciated!!!
有谁知道为什么 Unicorn 不能写出 pid 文件?任何帮助将不胜感激!!!
- Mike
- 麦克风
回答by Limbo Peng
Actually, the error message has already told you why:
实际上,错误消息已经告诉您原因:
directory for pid=/home/deploy/apps/shared/pids/unicorn.pid not writable
pid=/home/deploy/apps/shared/pids/unicorn.pid 的目录不可写
So, does the directory /home/deploy/apps/shared/pidsexist? If not, you should call mkdirto create it.
那么,该目录是否/home/deploy/apps/shared/pids存在?如果没有,你应该打电话mkdir来创建它。
回答by Pravin Mishra
Unicorn process is running in background(-d), type
独角兽进程在后台运行(-d),输入
ps aux | grep unicorn
and kill running unicorn process then start once again.
并杀死正在运行的独角兽进程,然后再次启动。
回答by Farukca
in capistrano 3; if we change roles to :all, then while deployment capistrano saying;
and after deployment all symlinks not working anymore. And if tmp/pids folder in symlink array, then unicorn can't find the tmp/pids folder and saying unicorn.pid is not writable.WARN [SKIPPING] No Matching Host for .....
在卡皮斯特拉诺 3; 如果我们将角色更改为:all,那么在部署 capistrano 时说;
部署后所有符号链接不再起作用。如果符号链接数组中的 tmp/pids 文件夹,则 unicorn 找不到 tmp/pids 文件夹并说 unicorn.pid 不可写。WARN [SKIPPING] No Matching Host for .....
So we must use; roles: %w{web app db}instead of roles :all.
所以我们必须使用; roles: %w{web app db}而不是roles :all.
Sample server line at production.rb;
production.rb 中的示例服务器线;
server 'YOUR_SERVER_IP', user: 'YOUR_DEPLOY_USER', roles: %w{web app db}, ssh_options: { forward_agent: true }
server 'YOUR_SERVER_IP', user: 'YOUR_DEPLOY_USER', roles: %w{web app db}, ssh_options: { forward_agent: true }

