run rails applicaton after capistrano deployment - ruby-on-rails

Deploying rails app throw Capistrano first time: I deployed my rails app on another machine (server)
File structure for rails app ## this is my server
akshay#akshay:/var/www/model_demo$ ls
current releases repo revisions.log shared
cap -T ## showing a lots of rake task
like
cap deploy:migrate # Runs rake db:migrate if migrations are set
If I run this task it is not working saying
Stage not set, please call something such as `cap production deploy`, where production is a stage you have defined.
But when I run
cap production deploy # It works
Among all the listed task only cap production deploy
1: what exactly going on under the hood?
2: How might i run rake task which is provided by cap?
Any help would be appreciated !!!

Capistrano recepies are meant to run on local system.
Run it locally.

I catch my mistake. And as I followed Railscasts Capistrano screencasts, stackoverflow Capistrano Tags and deploying-rails-apps-to-a-vps-with-capistrano-v3.
As all cap tasks run locally.
cap production deploy:migrate # Worked for me
Thanks to #maxd !!!

Related

Can I run my heroku app in Test/Development environment

I was trying to run my test cases on heroku.
Fund many blogs/answers telling how to run staging/custom environment on heroku.But whenever I run heroku run rspec spec/ it returns you are running production environment(not exact error).
So my qustion is not how to run staging/custom evironment on heroku but when I login into heroku rails console, I should be able to see
Rails.env #=> test
Or staging or whatever.
Any help is appreciable.
In heroku dashboard, you should just set RAILS_ENV and RACK_ENV to test.
You can do that here:
After setting these variables, I was able to start the console in test environment.

Capistrano Nginx Rails, After Rake Db:Migrate "Something went wrong"

I needed to migrate my database, so I made the changes to my local system, pushed them to git, then cap production deploy. Once on the service I went to the current and ran rake db:migrate. Now when I visit my site I receive an error We're sorry, but something went wrong (500). There is no other information and my /opt/nginx/logs/error.log is completely blank. How do I fix this?
I'm using Postgresql, capistrano, rails 3, nginx
If you correctly installed ruby, rails, passenger and nginx, then follow my gist. You should go through the files and change the configuration according to your need. Here, you'll find
Gemfile // required gems for capistrano deployment
Capfile
deploy.rb // change the configuration for your server
production.rb // change the configuration for your server
After fully configured according to the gist, run
cap production deploy:check # it'll tell you what is missing for deploying your application
then, cap production deploy
Always check the production.log file if you facing any problem.

How to run Rails delayed_job with Passenger in production? [duplicate]

With the delayed_jobs gem(https://github.com/collectiveidea/delayed_job) in rails, I am able to queue my notifications. But I don't quite understand how can I run the queued jobs on the production server. I knew I can just run
$ rake jobs:work
in the console for the local server. As the documentation said,
You can then do the following:
RAILS_ENV=production script/delayed_job start
RAILS_ENV=production script/delayed_job stop
# Runs two workers in separate processes.
RAILS_ENV=production script/delayed_job -n 2 start
RAILS_ENV=production script/delayed_job stop
# Set the --queue or --queues option to work from a particular queue.
RAILS_ENV=production script/delayed_job --queue=tracking start
RAILS_ENV=production script/delayed_job --queues=mailers,tasks start
# Runs all available jobs and the exits
RAILS_ENV=production script/delayed_job start --exit-on-complete
# or to run in the foreground
RAILS_ENV=production script/delayed_job run --exit-on-complete
My question is how to integrate it with my Rails app?I was thinking to create a file called delayed_jobs.rb in config/initializers as:
# in config/initializers/delayed_jobs
script/delayed_job start if Rails.env.production?
But I am not sure if it is the right way to do with it. Thanks
The workers run as separate processes, not as part of your Rails application. The simplest way would be to run the rake task in a screen session to prevent it from quitting when you log out of the terminal session. But there are better ways:
You would use a system such as monit or God or run the worker script provided by delayed_job. You'll find more information in the answers to this question.
In my experiencie I've found my solution using capistrano gem, which in words of the official doc
It supports the scripting and execution of arbitrary tasks, and includes a set of sane-default deployment workflows.
Basically it is a tool that helps you to deploy your app, including all of those task like starting/stoping queues, migrating the database, bundle new gems, and all of those thing that we usually do with ssh connection.
Here is a beutifull tutorial about capistrano and webfaction as hosting. And here is a nice module to blend capistrano and delayed_job. At the end you should only be concern about the development environment, because every time that you need to deploy to production, you'll do a commit to your repository and then
$ cap production deploy
Which will manage the whole production environment, stoping/restarting those queues, restarting the app, installing gems and everything that you can perform through the capistrano scripting way.

Heroku Deployment : Discourse Assets precompile

Hi I'm actually trying to deploy discourse on Heroku.
I'm following the step by step guide here Basic Heroku deployment
I'm facing a problem when I try to rake assets:precompile (I'm precompiling locally).
The rake command is aborted, saying to me that
No such file or directory: mydirectories/discourse/config/database.yml
When I rake assets:precompile I'm in production environment (RAILS_ENV=production).
So I checked if the database.yml was missing in the repo, and yes it was.
I currently have two database.yml but a bit different. There's database.yml.development-sample and
database.yml.production-sample.
I tried renaming database.yml.production-sample to a simple database.yml but it still doesn't work giving me this error:
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
What am I doing wrong ?
Cordially,
Rob
PS : The config/redis.yml and public/assets are commented in the .gitignore
# http://shcatula.wordpress.com/2013/07/08/deploying-discourse-to-heroku/ you have a detailed description of deployment of Discourse to Heroku. It also links to a gist with a shell script that does the entire job of pre-compiling and preparing your deploy. The shell script pretty much explains all the steps needed. Hope it helps!

Getting more info on Capistrano tasks

I'm get a Capistrano recipe to work with Bundler and a Rails (3.0.3) app but having trouble with some basic functionality.
Following the Bundler docs for "Automatic deployment with Capistrano", I'm trying to get more info on a task but for some reason it "doesn't exist"...
$ cap -e bundle:install
The task `bundle:install' does not exist.
The Capistrano (2.5.19) gem is installed and I'm trying to execute that command from the root of my project on the client (not the server).
in fact cap -T doesn't show anything related to 'bundle' or 'install'
$ cap -T
cap deploy # Deploys your project.
cap deploy:check # Test deployment dependencies.
cap deploy:cleanup # Clean up old releases.
cap deploy:cold # Deploys and starts a `cold' application.
cap deploy:migrate # Run the migrate rake task.
cap deploy:migrations # Deploy and run pending migrations.
cap deploy:pending # Displays the commits since your last deploy.
cap deploy:pending:diff # Displays the `diff' since your last deploy.
cap deploy:restart # Restarts your application.
cap deploy:rollback # Rolls back to a previous version and restarts.
cap deploy:rollback:code # Rolls back to the previously deployed version.
cap deploy:setup # Prepares one or more servers for deployment.
cap deploy:start # Start the application servers.
cap deploy:stop # Stop the application servers.
cap deploy:symlink # Updates the symlink to the most recently deployed ...
cap deploy:update # Copies your project and updates the symlink.
cap deploy:update_code # Copies your project to the remote servers.
cap deploy:upload # Copy files to the currently deployed version.
cap deploy:web:disable # Present a maintenance page to visitors.
cap deploy:web:enable # Makes the application web-accessible again.
cap invoke # Invoke a single command on the remote servers.
cap shell # Begin an interactive Capistrano session.
What am I doing wrong?
Did you include the recipe in your deploy.rb file?
require "bundler/capistrano"

Resources