Rails 4.1 on Ubuntu 14.04 with rbenv and ruby 2.2.1.
Using capistrano with the capistrano-passenger gem, but the restart at the end fails:
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.
When I try to run this command at the command line via SSH, I get this:
deployer#host:~/app/shared/config$ passenger-config restart-app
*** ERROR: You are not authorized to query the status for this
What am I doing wrong here?
I'm using Apache, here's the relevant parts of my /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>
Here's what got me running, I added this to my conifg/deploy.rb:
set :passenger_restart_with_sudo, true
Ref: https://github.com/capistrano/passenger/
To add password-less sudo access for the deployer user, on the server do:
(you might want to be more specific as to the allowed commands)
sudo tee /etc/sudoers.d/deployer > /dev/null <<'EOF'
deployer ALL=(ALL) NOPASSWD:ALL
EOF
...and in your delpoy.rb, have:
set :user, 'deployer' # Deployment user on remote servers
Note: it should be noted that the Passenger authors are working on a method so that sudo will not be required any longer in the future.
If you don't want to use sudo for restarting application server, simply add to 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
For restarting with sudo (Note that it doesn't have any effect on Passenger < 5):
set :passenger_restart_with_sudo, false
If you want to change restarting options, you might override these:
set :passenger_restart_command, 'passenger-config restart-app'
set :passenger_restart_options, -> { "#{deploy_to} --ignore-app-not-running" }
Related
I bought some hosting space where I have SSH access. Now I want to deploy a Ruby on Rails apps which works locally to one of the subdomains I made, let's call it subdomain.mywebsite.com.
I have setup SSH access via a public key, installed Ruby on Rails and Passenger on the server, and installed Capistrano locally by following the steps provided on the website and via tutorials. When I run cap production deploy the whole site is uploaded to the production server and via SSH I can see the current, releases, repo and shared folder. Unfortunately, when I go to subdomain.mywebsite.com I get a 404 - not found error.
I am new to setting up my own server and do not know what to do now. All tutorials I have found do not explain how to continue from here, and I hope someone who reads this can help me to actually being able to access the site.
Deploy.rb:
require 'capistrano'
set :stages, ["staging", "production"]
set :default_stage, "staging"
set :application, 'chiachia_store' # application name
set :repo_url, 'git#github.com:erooijak/chiachia_store.git' # your repo url
set :deploy_to, '/home/erooijak/chiachia.erooijak.simple-webhosting.eu'
set :user, "root"
set :scm, :git
set :branch, 'master'
set :keep_releases, 5
ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
set :format, :pretty
set :log_level, :debug
set :pty, true
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set :stage, :production
role :app, %w{root#213.159.6.126}
role :web, %w{root#213.159.6.126}
role :db, %w{root#213.159.6.126}
set :puma_rackup, -> { File.join(current_path, 'config.ru') }
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
namespace :deploy do
desc 'Restart application...'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
execute :touch, release_path.join('tmp/restart.txt')
end
end
desc 'Copy database.yml to correct location.'
task :copy_databaseyml do
on roles(:app) do
execute :cp ,'-r', shared_path.join('config/database.yml'),
release_path.join('config/database.yml')
end
end
after :publishing, :restart
after :restart, :copy_databaseyml
end
Apache.conf:
LoadModule passenger_module /usr/lib/apache2/modules/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p547/gems/passenger-4.0.49
PassengerRuby /usr/bin/ruby
ServerName www.chiachia.erooijak.simple-webhosting.eu
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /home/erooijak/chiachia.erooijak.simple-webhosting.eu/current/public
<Directory /home/erooijak/chiachia.erooijak.simple-webhosting.eu/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>
The effect of running this is the following:
So it kind of works. Unfortunately I get a 404 error on all domains, the PHP application keeps running properly.
The passenger.3000.log has the following information:
passenger.3000.log
html error message metnioned in log
Why don't we start from scratch.
After reading your last comments, what you want is to be able to deploy multiple rails applications on the same server.
There are many options to do that, and depending on what you choose, configuration is going to be very different. There is a good SO answer that covers the basics you might want to read:
Ruby on Rails Server options
The stack I'm used to is Nginx/capistrano/unicorn but that depends on personal preferences and the nature of what's deployed.
Apache/Phusion passenger
The first thing to do is to configure apache for your domain. The phusion passenger documentation is a very good starting point.
You can even find a complete guide on how to deploy Rails >= 3.X apps with phusion passenger in the same documentation
If you follow carefully the instructions, you should have your app up and running without puma. They even also provide you capistrano recipes to use.
Puma
At this stage, unless you app needs high concurrency, puma is not needed. Phusion Passenger is an app server by itself, no need to add puma behind it. If you really need it for some reason, then you'll be better off switching to Nginx/Puma.
I hope the references I gave you clear things up a bit.
my environment is as follows:
Ubuntu 10.04
Ruby 2.0.0
Rails 4.0
The deployed Rails application resides in /var/www/application. The deployment is handled by Capistrano, therefore, the directory structure is as follows:
root#lvps91-250-114-42:/var/www/application# ls -la
total 16
drwxrwxr-x 4 www-data www-data 4096 2013-11-14 12:53 .
drwxr-xr-x 6 www-data www-data 4096 2013-11-12 22:54 ..
lrwxrwxrwx 1 www-data www-data 39 2013-11-14 12:53 current -> /var/www/application/releases/20131114115156
drwxrwxr-x 11 www-data www-data 4096 2013-11-14 12:51 releases
drwxrwxr-x 8 www-data www-data 4096 2013-11-13 01:49 shared
The config/deploy.rb is configured to use a :local ruby (which has been installed into ../shared). The capistrano config:
require 'bundler/capistrano'
require 'rvm/capistrano'
#....
set :bundle_flags, "--deployment"
set :default_shell, '/bin/bash -l'
set :rvm_ruby_string, :local
#....
before 'deploy:setup', 'rvm:install_rvm'
before 'deploy:setup', 'rvm:install_ruby'
Maybe this plays a role because there is another rvm/ruby installation which is recognized when installing the Passenger. Passenger told me to configure the Apache 2 as follows:
LoadModule passenger_module /root/.rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.24/buildout/apache2/mod_passenger.so
PassengerRoot /root/.rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.24
PassengerDefaultRuby /root/.rvm/wrappers/ruby-2.0.0-p247/ruby
But it complained about my .rvm installation (which resides in root :-() and that I will need to change the permissions (but I didn't change them):
It is recommended that you relax permissions as follows:
sudo chmod o+x "/root"
Press Ctrl-C to return to the shell. (Recommended)
After relaxing permissions, re-run this installer.
-OR-
Press Enter to continue anyway.
The corresponding sites-enabled/application configuration:
<VirtualHost *:80>
ServerName subdomain.domain.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/application/current/public
<Directory /var/www/application/current/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
When I started the application, I got the following error in my browser:
Cannot execute "/root/.rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.24/buildout/agents/SpawnPreparer": Permission denied (errno=13)
After:
sudo chmod o+x "/root"
Everything is working.
What is your advice to fix it? Should I re-install .rvm and passenger? Can I reconfigure the Apache configuration so that Apache will access all those executables which reside in /var/www/application?
Thank you in advance!!
jepetko
If you have used the rvm installation method for a single user, have you considered setting the ownership of the files for the ruby application to be the same as the owner of rvm?
For myself, I have ran into this problem before and here is what I have done:
Create new user for managing rvm
Add the new user to be able to sudo to root
Login as the new user and install rvm as a single user
Install passenger gem
Run passenger installation for module with rvmsudo
Set the ownership of the ruby application to be the same as the new user account for rvm management
Sometimes I have had to add the following to my apache conf:
SetEnv LD_LIBRARY_PATH /home/rvmuser/.rvm/default/lib
SetEnv GEM_PATH /home/rvmuser/.rvm/gems/ruby-1.9.3-p484:/home/rvmuser/.rvm/gems/ruby-1.9.3-p484#global
Hope this helps!
i have same problem with you before and this is how i solve it:
try use set config PassengerUser https://www.phusionpassenger.com/library/config/apache/reference/#passengeruser . Set it with user that you use when install rvm. Because you put the rails app on /var/www/ which is that is owned with apache/www-data you need specify user that owned the rvm.
So, based on you example, just add: PassengerUser deploy after or before DocumentRoot config on your apache config.
Don't forget to restart the apache. Good luck.
Hi I'm running Passenger/mongo/Rails 3.2 (no activerecord or mysql) with a Capistrano deploy script.
I'm trying to get my app to run in production mode on my linux server.
In my apache config file i have the following...
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /srv/www/example.com/current/public
ErrorLog /srv/www/example.com/current/log/error.log
CustomLog /srv/www/example.com/current/log/access.log combined
PassengerDefaultUser www-data
<Directory /srv/www/test.example.com/current/public>
AllowOverride all
Options -MultiViews
</Directory>
RailsEnv production
</VirtualHost>
EDIT: In my environment.rb file I no longer have the following...
RAILS_ENV="production"
RAILS_ENV.freeze
In my Capistrano deploy.rb I have the following...
set :rails_env, "production"
EDIT: But when I deploy via capistrano or do a sudo service apache2 restart. It says apache restarts but the server never comes up when i access the url.
Seems like an unusual problem. I have deployed many applications with similar or identical stacks without incident.
Try this:
Please remove any custom code (related to this issue) from your environment.rb file.
Remove the rails_env variable from your deploy file
Make sure to leave "RailsEnv production" inside your Apache virtual host config
SSH into the server and restart Apache manually
I will check in the morning, but I believe that restart task for mod_rails is no good, I think I have hooked in a manual Apache restart after the deploy. Not sure why, think it has something to do with the fact that "current_path" is only a symlink or perhaps "PassengerMinInstances" is preventing a new passenger thread from spawning with the modified code. All speculation.
For Rails 3.x apps that come with a config.ru file you should be using the RackEnv parameter in your VirtualHost configuration:
RackEnv production
You really should not be force-setting RAILS_ENV inside of environment.rb. That's bound to cause all kinds of problems.
On my production environment (application name conflux), I have RailsEnv production inside the tag.
<Directory /var/www/conflux/current/public>
RailsEnv production
PassengerAppRoot /var/www/conflux/current
Allow from all
#Turn off MultiViews, which is incompatable with Passenger.
Options -MultiViews
</Directory>
I agree not to set RAILS_ENV inside environment.rb. For one thing, RAILS_ENV is a constant, and I think if it is used (and before Rails 3) it is set before entering the environments. So, it may already be set, and as a constant, will not change.
I also am not sure that RAILS_ENV is used in Rails 3 any more.
Have you tried pre-compiling the assets, Once precompiled, the assets are placed in public folder and then only you will be able to run it successfully in production mode. try this rake assets:precompile if it is jruby then jruby -S rake assets:precompile.
If the server is in production mode, asset pipeline and asset server needs to be set to "TRUE" in production.rb
I assume that this is the permissions settings for your directory
<Directory /srv/www/**test.example.com/**current/public>
AllowOverride all
Options -MultiViews
</Directory>
In which case, wouldn't this have to be the same as your document root setting
DocumentRoot /srv/www/**example.com**/current/public
Not that familiar with Capistrano or apache, but i've always thought these would need to be the same.
I am using apache passenger to deploy rails application.
I have followed each and every step clearly and everything works fine.
No error message in deployment.
But the site doesn't show up on browser.
Here are the files
$ sudo cat /etc/apache2/sites-available/capi_app
<VirtualHost *:80>
ServerName www.passionate4.net
DocumentRoot /var/www/apps/capi_app/public
RailsEnv production
<Directory /var/www/apps/capi_app/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
I also tried to change
$ sudo cat /etc/apache2/sites-available/capi_app
<VirtualHost *:80>
ServerName www.passionate4.net
DocumentRoot /var/www/apps/capi_app/current/public
RailsEnv production
<Directory /var/www/apps/capi_app/current/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
--> With this, when i restart apache, I don't get error (/ / / public) doesn't exist, but site still doesn't show up.
#Martin
$ sudo cat /etc/apache2/sites-enabled/capi_app
<VirtualHost *:80>
ServerName www.passionate4.net
DocumentRoot /var/www/apps/capi_app/current/public
RailsEnv production
<Directory /var/www/apps/capi_app/current/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
----------- deploy.rb file -------------
require 'bundler/capistrano'
#using RVM!
$:.unshift("#{ENV["HOME"]}/.rvm/lib")
require "rvm/capistrano"
set :rvm_type, :user
set :application, "capi_app"
set :deploy_to, "/var/www/#{application}"
role :web, "50.18.155.154" # Your HTTP server, Apache/etc
role :app, "50.18.155.154" # This may be the same as your `Web` server
role :db, "50.18.155.154", :primary => true # This is where Rails migrations will run
default_run_options[:pty] = true
set :repository, "git#github.com:jaipratik/capi_app.git"
set :scm, :git
set :branch, "master"
set :user, "ubuntu" #if error use whats shown in podcast
set :use_sudo, false
set :admin_runner, "ubuntu"
set :rails_env, 'production' #<<<<<<<<<< NEW
#set :use_sudo, false #if error delete this
# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
ubuntu#ip-10-166-185-18:~$ ls -l /var/www/apps/capi_app
total 8
lrwxrwxrwx 1 ubuntu ubuntu 46 2011-11-17 19:04 current -> /var/www/
apps/capi_app/releases/20111117190420
drwx-w---- 5 ubuntu ubuntu 4096 2011-11-17 19:04 releases
drwx-w---- 6 ubuntu ubuntu 4096 2011-11-17 09:48 shared
ubuntu#ip-10-166-185-18:~$
I placed the application at this particular location var/www/myapplication.
This resolved the error "Symbolic link not allowed or link target not accessible". I will put all the steps I took to resolve this issue.
In addition to this i'll also blog on how to resolve errors involved with first time deployment of rails 3.1 to ec2. here ->
http://recipe4developer.wordpress.com/2011/11/19/correcting-errors-in-first-time-rails-3-1-deployment-to-ec2/
Make sure that your vhost lives somewhere in /etc/apache2/sites-available, and then make sure to add it to apache, either by using the a2ensite command, or by manually symlinking /etc/apache2/sites-enabled/your_vhost_name_here to whatever you called the site.
Possible commands to enable the site (use either one):
sudo a2ensite your_vhost_name
sudo ln -s /etc/apache2/sites-available/your_vhost_name /etc/apache2/sites-enabled
After you've done this, make sure to reload apache, by running the following command:
sudo service apache2 restart
Is there a reason you're not using Heroku? You get EC2 with very easy deployment.
I have a machine where all my rails apps are running in a "staging" environment, even the production ones. It is trying to connect to the staging database. I have tried setting it set to production in the following places:
#/etc/apache2/mods-enabled/passenger.so:
# the line above was wrong, it is in /etc/apache2/sites-enabled/ier
RailsBaseURI /ier
RailsEnv production
<Directory /rails/production/ier/current/public>
Options -MultiViews
</Directory>
#app/controllers/application_controller.rb
Rails.env = 'production'
I even tried putting it in:
#config/environment.rb adding Rails.env = 'production'
I am getting a passenger error of:
staging database is not configured (ActiveRecord::AdapterNotSpecified)
I even ran ( grep -R "staging" . in ) and got:
Binary file ./.git/index matches
./config/deploy.rb:set :stages, %w(staging production)
./config/deploy.rb:# %w{staging.rb}.each do |config|
./config/deploy.rb:# %w{production.rb staging.rb}.each do |deploy_env|
./config/database.yml:staging:
grep: ./config/deploy/staging.rb: No such file or directory
grep: ./config/deploy/production.rb: No such file or directory
I am running Apache2, Passenger 3.0.7, ruby 1.9.2, and rails 3.0.9
Where else can I look to find out where I set the environment to staging?
thanks for any help
Try putting this inside your <VirtualHost> configuration (probably in /etc/apache2/site-enabled/000-default).
RailsEnv production
RackEnv production
I hear some versions of Passenger required RackEnv instead of RailsEnv so you might want to try that especially.
You can also try putting it in an .htaccess file in your public directory if you have AllowOverride set to Options or All.