如何让passenger-config restart-app工作?

时间:2015-03-26 17:00:49

标签: ruby-on-rails capistrano passenger capistrano3

使用rbenv和ruby 2.2.1在Ubuntu 14.04上安装Rails 4.1。

将capistrano与capistrano-passenger gem一起使用,但最后重启失败:

INFO [8213c63a] Running /usr/bin/env passenger-config restart-app /home/deployer/my_app --ignore-app-not-running as deployer@mysite.com
DEBUG [8213c63a] Command: passenger-config restart-app
DEBUG [8213c63a]    Please pass either an app path prefix or an app group name. See --help for more information.

当我尝试通过SSH在命令行运行此命令时,我得到了这个:

    deployer@host:~/app/shared/config$ passenger-config restart-app
*** ERROR: You are not authorized to query the status for this

我在这里做错了什么?

我正在使用Apache,这是我/etc/apache2/apache2.conf的相关部分:

LoadModule passenger_module /home/deployer/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/passenger-5.0.5/buildout/apache2/mod_passenger.so
   <IfModule mod_passenger.c>
     PassengerRoot /home/deployer/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/passenger-5.0.5
     PassengerDefaultRuby /home/deployer/.rbenv/versions/2.2.1/bin/ruby
   </IfModule>

<VirtualHost *:80>
      ServerName mysite.name.com
      # !!! Be sure to point DocumentRoot to 'public'!
      DocumentRoot /home/deployer/myssite/current/public
      <Directory /home/deployer/mysite/current/public>
         # This relaxes Apache security settings.
         AllowOverride all
         # MultiViews must be turned off.
         Options -MultiViews
         # Uncomment this if you're on Apache >= 2.4:
         Require all granted
      </Directory>
   </VirtualHost>

2 个答案:

答案 0 :(得分:7)

这就是让我跑步的原因,我将其添加到我的conifg/deploy.rb

set :passenger_restart_with_sudo, true

参考:https://github.com/capistrano/passenger/

要为sudo用户添加无密码deployer访问权限,请在服务器上执行以下操作:

(您可能希望更具体地说明允许的命令)

sudo tee /etc/sudoers.d/deployer > /dev/null <<'EOF'
deployer ALL=(ALL) NOPASSWD:ALL
EOF

...在您的delpoy.rb中,有:

set :user, 'deployer' # Deployment user on remote servers

注意:应该注意的是,Passenger作者将来会working on a method so that sudo will not be required any longer

答案 1 :(得分:3)

如果您不想使用sudo重新启动应用服务器,只需添加到config/deploy.rb

namespace :deploy do
  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      execute :touch, release_path.join('tmp/restart.txt')
    end
  end
end

使用sudo重新启动(请注意,它对Passenger&lt; 5没有任何影响):

set :passenger_restart_with_sudo, false

如果您想更改重启选项,可以覆盖以下内容:

set :passenger_restart_command, 'passenger-config restart-app'
set :passenger_restart_options, -> { "#{deploy_to} --ignore-app-not-running" }