【问题标题】:Unicorn unable to write pid file独角兽无法写入pid文件
【发布时间】:2012-02-01 03:04:17
【问题描述】:

我正在使用 Capistrano 将 Ruby on Rails 应用程序部署到 Linode VPS。我使用 Unicorn 作为应用服务器,使用 Nginx 作为代理。我的问题是,由于明显的权限问题,我无法启动 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

我回来了,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

最后,这是我的独角兽配置文件​​(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"

我在“部署”用户和组下使用 Capistrano 进行部署,这也是 Unicorn 应该在其下运行的。

有没有人知道为什么 Unicorn 不能写出 pid 文件?任何帮助将不胜感激!!!

  • 迈克

【问题讨论】:

    标签: ruby deployment capistrano file-permissions unicorn


    【解决方案1】:

    其实错误信息已经告诉你原因了:

    pid=/home/deploy/apps/shared/pids/unicorn.pid 的目录不可写

    那么,/home/deploy/apps/shared/pids 目录是否存在?如果没有,您应该调用mkdir 来创建它。

    【讨论】:

    • 你是对的。我使用了不正确的绝对路径。引用了正确的目录,生活中的一切都好起来了。感谢您的帮助。
    【解决方案2】:

    独角兽进程在后台运行(-d), 输入

    ps aux | grep unicorn
    

    并杀死正在运行的独角兽进程,然后重新启动。

    【讨论】:

      【解决方案3】:

      在 capistrano 3 中;如果我们将角色更改为:all,那么在部署 capistrano 的同时; WARN [SKIPPING] No Matching Host for ..... 部署后所有符号链接都不再起作用。如果 symlink 数组中有 tmp/pids 文件夹,则 unicorn 找不到 tmp/pids 文件夹并说 unicorn.pid 不可写。

      所以我们必须使用; roles: %w{web app db} 而不是 roles :all

      production.rb 中的示例服务器线;

      server 'YOUR_SERVER_IP', user: 'YOUR_DEPLOY_USER', roles: %w{web app db}, ssh_options: { forward_agent: true }

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-06-01
        • 1970-01-01
        • 2023-03-23
        • 2013-01-26
        • 2023-03-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多