3

Trying to get deploying on Capistrano 3. I'm using NGINX, RVM, Passenger, Rails 4. My deploys are working, but I need to restart NGINX manually - here is the error at the end of the deploy:

    DEBUG [c4e821bc] Command: ~/.rvm/bin/rvm default do passenger -v
DEBUG [c4e821bc]    Phusion Passenger version 5.0.6
DEBUG [c4e821bc]    
DEBUG [c4e821bc]    "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
DEBUG [c4e821bc] Finished in 0.981 seconds with exit status 0 (successful).
 INFO [5082ae94] Running ~/.rvm/bin/rvm default do passenger-config restart-app /home/deploy/skilltry --ignore-app-not-running on 104.237.158.232
DEBUG [5082ae94] Command: ~/.rvm/bin/rvm default do passenger-config restart-app /home/deploy/skilltry --ignore-app-not-running
DEBUG [5082ae94]    *** ERROR: You are not authorized to query the status for this Phusion Passenger instance. Please try again with 'rvmsudo'.
cap aborted!

I've tried a fix over here: https://github.com/capistrano/passenger/issues/2

Use visudo to edit the file (so if you mess up you have the chance to re-edit the file), at the end of the file (*) add the following:

deployuser    ALL=(root) NOPASSWD: /usr/bin/passenger-config

This made no difference

And over here: How can I get passenger-config restart-app to work?

But I get a prompt which I cannot enter:

[sudo] password for deploy: 
Community
  • 1
  • 1
fatfrog
  • 2,118
  • 1
  • 23
  • 46

3 Answers3

2

Looking at the gems/capistrano-passenger-0.0.5/lib/capistrano/tasks/passenger.cap file, it contains the following defaults:

  task :defaults do
    set :passenger_roles, :app
    set :passenger_restart_runner, :sequence
    set :passenger_restart_wait, 5
    set :passenger_restart_limit, 2
    set :passenger_restart_with_sudo, false
    set :passenger_environment_variables, {}
    set :passenger_restart_command, 'passenger-config restart-app'
    set :passenger_restart_options, -> { "#{deploy_to} --ignore-app-not-running" }
    set :passenger_rvm_ruby_version, ->{ fetch(:rvm_ruby_version) }
    if Rake.application.tasks.collect(&:to_s).include?("rvm:hook")
      before :'rvm:hook', :'passenger:rvm:hook'
    end
    if Rake.application.tasks.collect(&:to_s).include?("rbenv:map_bins")
      before :'rbenv:map_bins', :'passenger:rbenv:hook'
    end
  end

I was able to add the following to deploy.rb to override how the passenger instances are restarted:

set :passenger_restart_command, 'sudo passenger-config restart-app'

You should verify first that your /etc/sudoers config allows password-less execution of that command as root.

Javeed
  • 99
  • 3
  • I'm going to give your suggestion a try this weekend, I was able to get things going with set :passenger_restart_with_sudo, true and deploy ALL=(ALL) NOPASSWD:ALL – fatfrog Apr 16 '15 at 02:17
  • 1
    Actually, it looks like passenger_restart_with_sudo might be the better alternative here :-) – Javeed Apr 16 '15 at 03:40
2

I was getting the *** ERROR: You are not authorized to query the status for this Phusion Passenger instance. Please try again with 'sudo'. error as well when I tried to deploy. I found using the capistrano-passenger gem, there's an option to fix this:

# add this to config/deploy.rb
set :passenger_restart_with_sudo, true # default false

You can read up on the docs to see some other options.

jeremywoertink
  • 2,281
  • 1
  • 23
  • 29
  • Got an error: `sudo: no tty present and no askpass program specified`. Dropping this line into the configuration isn't sufficient to solve the issue. – a.barbieri May 18 '19 at 20:31
  • 1
    I found what was causing the issue and there is no need, in my case, to use `sudo`. I added my answer above. – a.barbieri May 18 '19 at 22:13
0

Possible issues:

  1. Nginx configuration is pointing to a directory where Capistrano user doesn't have access/permission.
  2. Nginx configuration isn't listening to the domain you set in your Capistrano config.

Passenger is a “process manager” and uses Nginx to manage http traffic to/from those processes.

Make sure your virtual server is pointing to a directory owned by Capistrano user and the virtual server is listening to the same domain present in your Capistrano configuration.

An example:

Assuming you are deploying to /home/my_user/my_app_path you should set my_user as Capistrano user to deploy the application.

Also assuming your domain is my_app.com, make sure is consistent in both Capistrano and Nginx config.

# Capistrano configuration
server "my_app.com", user: "my_user", roles: %w{app web db}
# Nginx configuration
server {
  listen 80;
  server_name my_app.com;
  root /home/my_user/my_app_path/current/public;
  passenger_ruby /home/my_user/.rbenv/shims/ruby;
  passenger_enabled on;
  passenger_min_instances 2;
  passenger_max_requests 5000;

  rails_env production;

  #... some more config settings

}
passenger_pre_start http://my_app.com;
Community
  • 1
  • 1
a.barbieri
  • 2,398
  • 3
  • 30
  • 58