【问题标题】:Ruby on Rails: Unicorn failed to start serverRuby on Rails:独角兽无法启动服务器
【发布时间】:2013-09-19 08:06:30
【问题描述】:

我正在关注#335 Deploying to a VPS,当我运行cap deploy:cold 时,一切都很好,除了最后它报告

executing 'deploy:start'
executing "/etc/init.d/unicorn_just4magic start"
servers: ["106.XXX.XXX.XXX"]
[106.XXX.XXX.XXX] executing command
out :: 106.XXX.XXX.XXX sh: /etc/init.d/unicorn_just4magic: Permission denied
command finished in 502ms
failed: "env PATH=$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH sh -c '/etc/init.d/unicorn_just4magic start'" on 
106.XXX.XXX.XXX     

我可以在VPS上手动运行rails server,完全没有问题。 但是在使用 cap 进行部署时,我得到了上述错误。当我访问我的网站时,我会收到Sorry Something went wrong 提示

更新: deploy.rb 是here,这里是start/restart 部分

  %w[start stop restart].each do |command|
    desc "#{command} unicorn server"
    task command, roles: :app, except: {no_release: true} do
      run "/etc/init.d/unicorn_#{application} #{command}"
    end
  end

更新2: 现在permission denied 提示没有出现,我遇到了另一个问题: sudo: /etc/init.d/unicorn_just4magic: command not found

我找到Capistrano deploy:start with unicornDuring cap deploy:cold - command not found for /etc/init.d/unicorn 我更改了shell脚本的行分隔符,并从git和set :bundle_flags, ''中删除了gemfile.lock。还是报错

【问题讨论】:

  • deploy.rb 可以放吗?它需要 sudo 用户权限
  • @RajarshiDas,看看我的更新
  • 设为run "#{sudo :as => 'cqcn'} /etc/init.d/unicorn_#{application} #{command}"run "#{sudo} /etc/init.d/unicorn_#{application} #{command}"
  • @RajarshiDas 它现在正在工作。但我得到command not found 错误。请看我的更新2
  • 您好抱歉迟到了......找不到命令?

标签: ruby-on-rails capistrano unicorn


【解决方案1】:

我通过在其上运行 chmod +x config/unicorn_init.sh 来授予本地文件 /config/unicorn_init.sh 可执行权限来解决它。将其推送到您的 git 存储库,将其部署到服务器,这对我来说就像一个魅力。

在服务器上摆弄权限好像不太好。

此外,如果您似乎无法找到您描述的文件(“找不到命令”),请尝试使用新权限再次运行 cap deploy:setup,然后从那里开始。可能是因为权限问题导致符号链接没有正确创建?

希望有帮助!

【讨论】:

    【解决方案2】:

    默认情况下,Unix 用户对其 /home/user/ 目录具有权限
    文件unicorn_just4magic 不在主目录或任何允许写入的目录下,因此您会收到“权限被取消”错误。
    要解决此问题,您可以
    - 将 unicorn_just4magic 移动到您的主目录下的某个位置(您可以在您的独角兽配置文件​​中进行设置

    - 为您的用户添加对 /etc/ 目录的权限
    $ chown your_username /etc/init.d/unicorn_just4magic

    【讨论】:

    • 它有效。但现在我得到command not found error。如何处理?
    • 当你运行chown your_username /etc/init.d/unicorn_just4magic ?
    • 当我运行 cap deploy:start 时,它无法运行 /etc/init.d/unicorn_just4magic start。在问题中查看我的更新