issue with deployment of my ruby on rails app - ruby-on-rails

I'm trying to solve a problem I'm having lately, deploying from a github production branch with cap: production deploy:migrations to my server.
I saw a potential solution was to follow this page: http://www.kudelabs.com/2012/03/28/rails-3-2-cap-deploy-with-assets
However I got errors at the rake assets:precompile part, running it locally. Terminal suggested I do
bundle exec rake assets:precompile, which I did, but I got the following:
root#ubuntu:~/myapp# bundle exec rake assets:precompile
DEPRECATION WARNING: require "activerecord" is deprecated and will be removed in Rails 3. Use require "active_record" instead. (called from /usr/lib/ruby/vendor_ruby/activerecord.rb:2)
/usr/bin/ruby1.8 /usr/local/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
DEPRECATION WARNING: require "activerecord" is deprecated and will be removed in Rails 3. Use require "active_record" instead. (called from /usr/lib/ruby/vendor_ruby/activerecord.rb:2)
rake aborted!
Received wrong number of arguments. [nil]
/var/lib/gems/1.8/gems/omniauth-1.1.0/lib/omniauth/strategy.rb:136:in `initialize'
/var/lib/gems/1.8/gems/actionpack-3.2.3/lib/action_dispatch/middleware/stack.rb:43:in `new'
/var/lib/gems/1.8/gems/actionpack-3.2.3/lib/action_dispatch/middleware/stack.rb:43:in `build'
/var/lib/gems/1.8/gems/actionpack-3.2.3/lib/action_dispatch/middleware/stack.rb:113:in `build'
/var/lib/gems/1.8/gems/railties-3.2.3/lib/rails/application.rb:282:in `inject'
/var/lib/gems/1.8/gems/actionpack-3.2.3/lib/action_dispatch/middleware/stack.rb:113:in `each'
/var/lib/gems/1.8/gems/actionpack-3.2.3/lib/action_dispatch/middleware/stack.rb:113:in `inject'
/var/lib/gems/1.8/gems/actionpack-3.2.3/lib/action_dispatch/middleware/stack.rb:113:in `build'
/var/lib/gems/1.8/gems/railties-3.2.3/lib/rails/engine.rb:470:in `build_middleware_stack'
/var/lib/gems/1.8/gems/railties-3.2.3/lib/rails/application/finisher.rb:31
/var/lib/gems/1.8/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `instance_exec'
/var/lib/gems/1.8/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `run'
/var/lib/gems/1.8/gems/railties-3.2.3/lib/rails/initializable.rb:55:in `run_initializers'
/var/lib/gems/1.8/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `each'
/var/lib/gems/1.8/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `run_initializers'
/var/lib/gems/1.8/gems/railties-3.2.3/lib/rails/application.rb:136:in `initialize!'
/var/lib/gems/1.8/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `send'
/var/lib/gems/1.8/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/christophecompaq/myapp/config/environment.rb:5
/var/lib/gems/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
/var/lib/gems/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
/var/lib/gems/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency'
/var/lib/gems/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
/var/lib/gems/1.8/gems/railties-3.2.3/lib/rails/application.rb:103:in `require_environment!'
/var/lib/gems/1.8/gems/railties-3.2.3/lib/rails/application.rb:292:in `initialize_tasks'
/var/lib/gems/1.8/gems/actionpack-3.2.3/lib/sprockets/assets.rake:93
/var/lib/gems/1.8/gems/actionpack-3.2.3/lib/sprockets/assets.rake:60
Tasks: TOP => environment
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/usr/bin/ruby1.8 /usr/local/bin/rake asset...]
/var/lib/gems/1.8/gems/actionpack-3.2.3/lib/sprockets/assets.rake:12:in `ruby_rake_task'
/var/lib/gems/1.8/gems/actionpack-3.2.3/lib/sprockets/assets.rake:21:in `invoke_or_reboot_rake_task'
/var/lib/gems/1.8/gems/actionpack-3.2.3/lib/sprockets/assets.rake:29
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
root#ubuntu:~/myapp#
Can anyone tell me where the problem might be?

If this is an initial deploy, try to remove
load 'deploy/assets'
Then try to
cap deploy:setup
cap deploy:cold
In this case you app will be deployed but without any assets :)
Then you need to add this:
#to the top of your deploy.rb namespace :deploy block
namespace :assets do
task :precompile, :roles => :web do
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ lib/assets/ app/assets/ | wc -l").to_i > 0
run_locally("rake assets:clean && rake assets:precompile")
run_locally "cd public && tar -jcf assets.tar.bz2 assets"
top.upload "public/assets.tar.bz2", "#{shared_path}", :via => :scp
run "cd #{shared_path} && tar -jxf assets.tar.bz2 && rm assets.tar.bz2"
run_locally "rm public/assets.tar.bz2"
run_locally("rake assets:clean")
else
logger.info "Skipping asset precompilation because there were no asset changes"
end
end
task :symlink, roles: :web do
run ("rm -rf #{latest_release}/public/assets &&
mkdir -p #{latest_release}/public &&
mkdir -p #{shared_path}/assets &&
ln -s #{shared_path}/assets #{latest_release}/public/assets")
end
end
Then recheck if you have this in your production.rb
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
After all this work, change some thing in you assets, for example add new line in application.css, this will tell "task :precompile" to realy precomlile and upload new assets, because new assets was added..

Related

Why are DB tasks missing from rake?

When I run bundle exec rake db:setup I get an error saying that rake doesn't know how to build that task. I then run bundle exec rake -T and see that db tasks are missing (all output below). How can I access the db tasks?
--application.rb--
require File.expand_path('../boot', __FILE__)
require 'rails'
require 'active_model/railtie'
require 'active_job/railtie'
require 'action_controller/railtie'
require 'action_view/railtie'
require 'sprockets/railtie'
Bundler.require(*Rails.groups)
module LofocatsUi
class Application < Rails::Application
end
end
--rake command--
bos-mp478:lofocats_ui rabdelaz$ bundle exec rake db:setup --trace
rake aborted!
Don't know how to build task 'db:setup' (See the list of available tasks with `rake --tasks`)
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/gems/rake-12.3.2/lib/rake/task_manager.rb:59:in `[]'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/gems/rake-12.3.2/lib/rake/application.rb:159:in `invoke_task'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/gems/rake-12.3.2/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/gems/rake-12.3.2/lib/rake/application.rb:116:in `each'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/gems/rake-12.3.2/lib/rake/application.rb:116:in `block in top_level'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/gems/rake-12.3.2/lib/rake/application.rb:125:in `run_with_threads'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/gems/rake-12.3.2/lib/rake/application.rb:110:in `top_level'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/gems/rake-12.3.2/lib/rake/application.rb:83:in `block in run'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/gems/rake-12.3.2/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/gems/rake-12.3.2/lib/rake/application.rb:80:in `run'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/bin/rake:23:in `load'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/bin/rake:23:in `<top (required)>'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/lib/ruby/site_ruby/2.4.0/bundler/cli/exec.rb:74:in `load'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/lib/ruby/site_ruby/2.4.0/bundler/cli/exec.rb:74:in `kernel_load'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/lib/ruby/site_ruby/2.4.0/bundler/cli/exec.rb:28:in `run'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/lib/ruby/site_ruby/2.4.0/bundler/cli.rb:424:in `exec'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/lib/ruby/site_ruby/2.4.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/lib/ruby/site_ruby/2.4.0/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/lib/ruby/site_ruby/2.4.0/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/lib/ruby/site_ruby/2.4.0/bundler/cli.rb:27:in `dispatch'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/lib/ruby/site_ruby/2.4.0/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/lib/ruby/site_ruby/2.4.0/bundler/cli.rb:18:in `start'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/bin/bundle:30:in `block in <main>'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/lib/ruby/site_ruby/2.4.0/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/bin/bundle:22:in `<main>'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#global/bin/ruby_executable_hooks:24:in `eval'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#global/bin/ruby_executable_hooks:24:in `<main>'
--tasks list--
bos-mp478:lofocats_ui rabdelaz$ bundle exec rake -T
rake about # List versions of all Rails frameworks and the environment
rake assets:clean[keep] # Remove old compiled assets
rake assets:clobber # Remove compiled assets
rake assets:environment # Load asset compile environment
rake assets:precompile # Compile all the assets named in config.assets.precompile
rake cache_digests:dependencies # Lookup first-level dependencies for TEMPLATE (like messages/show or comments/_comment.html)
rake cache_digests:nested_dependencies # Lookup nested dependencies for TEMPLATE (like messages/show or comments/_comment.html)
rake doc:app # Generate docs for the app -- also available doc:rails, doc:guides (options: TEMPLATE=/rdoc-template.rb, TITLE="Custom Title")
rake log:clear # Truncates all *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)
rake middleware # Prints out your Rack middleware stack
rake notes # Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)
rake notes:custom # Enumerate a custom annotation, specify with ANNOTATION=CUSTOM
rake rails:template # Applies the template supplied by LOCATION=(/path/to/template) or URL
rake rails:update # Update configs and some other initially generated files (or use just update:configs or update:bin)
rake routes # Print out all defined routes in match order, with names
rake secret # Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions)
rake stats # Report code statistics (KLOCs, etc) from the application or engine
rake time:zones:all # Displays all time zones, also available: time:zones:us, time:zones:local -- filter with OFFSET parameter, e.g., OFFSET=-6
rake tmp:clear # Clear session, cache, and socket files from tmp/ (narrow w/ tmp:sessions:clear, tmp:cache:clear, tmp:sockets:clear)
rake tmp:create # Creates tmp directories for sessions, cache, sockets, and pids

Error deploying Sidekiq to Ubuntu using Capistrano

I'm following the directions here to integrate Sidekiq with Capistrano on Ubuntu: https://github.com/mperham/sidekiq/wiki/Deploying-to-Ubuntu
I'm having an issue with the Capistrano part.
I put this code at the end of deploy.rb:
# For capistrano 3
namespace :sidekiq do
task :quiet do
# Horrible hack to get PID without having to use terrible PID files
puts capture("kill -USR1 $(sudo initctl status workers | grep /running | awk '{print $NF}') || :")
end
task :restart do
execute :sudo, :initctl, :restart, :workers
end
end
after 'deploy:starting', 'sidekiq:quiet'
after 'deploy:reverted', 'sidekiq:restart'
after 'deploy:published', 'sidekiq:restart'
And I get this error when I run cap production deploy:
cap aborted!
NoMethodError: undefined method `capture' for main:Object
config/deploy.rb:67:in `block (2 levels) in <top (required)>'
/Users/user/.rvm/gems/ruby-2.1.2#project/gems/capistrano-3.2.1/lib/capistrano/dsl/task_enhancements.rb:12:in `block in after'
/Users/user/.rvm/gems/ruby-2.1.2#project/gems/capistrano-3.2.1/lib/capistrano/dsl.rb:15:in `invoke'
/Users/user/.rvm/gems/ruby-2.1.2#project/gems/capistrano-3.2.1/lib/capistrano/tasks/framework.rake:65:in `block (2 levels) in <top (required)>'
/Users/user/.rvm/gems/ruby-2.1.2#project/gems/capistrano-3.2.1/lib/capistrano/tasks/framework.rake:64:in `each'
/Users/user/.rvm/gems/ruby-2.1.2#project/gems/capistrano-3.2.1/lib/capistrano/tasks/framework.rake:64:in `block in <top (required)>'
/Users/user/.rvm/gems/ruby-2.1.2#project/gems/capistrano-3.2.1/lib/capistrano/application.rb:15:in `run'
/Users/user/.rvm/gems/ruby-2.1.2#project/gems/capistrano-3.2.1/bin/cap:3:in `<top (required)>'
/Users/user/.rvm/gems/ruby-2.1.2#project/bin/cap:23:in `load'
/Users/user/.rvm/gems/ruby-2.1.2#project/bin/cap:23:in `<main>'
/Users/user/.rvm/gems/ruby-2.1.2#project/bin/ruby_executable_hooks:15:in `eval'
/Users/user/.rvm/gems/ruby-2.1.2#project/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => sidekiq:quiet
(See full trace by running task with --trace)
The deploy has failed with an error: #<NoMethodError: undefined method `capture' for main:Object>
Obviously, it's the capture function that's undefined, but what is the problem? Did I put the code in the right file deploy.rb? Do I need to require something?
You have to specify which server to run the code on. For instance:
namespace :sidekiq do
task :quiet do
# Horrible hack to get PID without having to use terrible PID files
on roles(:app) do
puts capture("kill -USR1 $(sudo initctl status workers | grep /running | awk '{print $NF}') || :")
end
end
task :restart do
on roles(:app) do
execute :sudo, :initctl, :restart, :workers
end
end
end
Try to require the sidekiq gem, or take a look at capistrano with sidekiq integration

undefined method `run' for main:Object

i'm getting the following output when deploying:
cap aborted!
NoMethodError: undefined method `run' for main:Object
config/deploy.rb:37:in `block (2 levels) in <top (required)>'
/var/lib/gems/1.9.1/gems/capistrano-3.2.1/lib/capistrano/dsl/task_enhancements.rb:12:in `block in after'
/var/lib/gems/1.9.1/gems/capistrano-3.2.1/lib/capistrano/application.rb:15:in `run'
/var/lib/gems/1.9.1/gems/capistrano-3.2.1/bin/cap:3:in `<top (required)>'
Tasks: TOP => deploy:permissions
(See full trace by running task with --trace)
The deploy has failed with an error: #<NoMethodError: undefined method `run' for main:Object>
i'm using Capistrano Version: 3.2.1 (Rake Version: 10.3.2).
the deploy works fine but i created a after deploy task to modify the owner of the deployed release which looks so:
namespace :deploy do
task :permissions do
run "chown -R :#{fetch(:group)} #{deploy_to} && chmod -R g+s #{deploy_to}"
end
end
after :deploy, "deploy:permissions"
vars are defined correctly (i fixed that error before) but i get this missing method error for the run method and i dont know why.
Your code uses 2.x syntax, while your version is 3.x. In 3.x, the syntax looks like this:
namespace :deploy do
on roles :all do
execute :chown, "-R :#{fetch(:group)} #{deploy_to} && chmod -R g+s #{deploy_to}"
end
end

rails script using whenever gem error: __rvm_add_to_path: command not found

I'm using capistrano and the whenever gem.
Capistrano deploys and updates the crontab on our ubuntu server with the cronjob detailed out in our schedule.rb file.
But the cronjob doesn't happen. It fails and emails me every 5 minutes this error:
/etc/profile.d/rvm.sh: line 67: __rvm_add_to_path: command not found
/home/pkatepalli/.rbenv/versions/1.9.3-p448/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- bundler/setup (LoadError)
from /home/pkatepalli/.rbenv/versions/1.9.3-p448/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /[REMOVED]/releases/20140204194143/config/boot.rb:6:in `<top (required)>'
from /home/pkatepalli/.rbenv/versions/1.9.3-p448/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/pkatepalli/.rbenv/versions/1.9.3-p448/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from script/rails:4:in `<main>'
The weird part is we're deploying with a different username than pkatepalli. pkatepalli is my username on the server. That explains why it's emailing me the error - I think.
Also, we're using ruby 1.9.3 not 1.9.1. I'm not sure why it's not using the right ruby version.
On server:
Bundler version 1.3.5
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-linux]
$ rbenv version
1.9.3-p448 (set by /[REMOVED]/current/.ruby-version)
But interestingly enough in the current directory there's ruby 1.9.1, which I'm confused by:
/current/vendor/bundle/ruby/1.9.1
gemfile:
gem 'whenever', require: false
schedule.rb:
I've tried uncommenting: env 'PATH', ENV['PATH'], but the PATH that gets put into the schedule.rb file doesn't help.
Locally we're using RVM instead of rbenv (which is being used on the server). I'm not sure if that screws up the path if we set: env 'PATH', ENV['PATH']
#env 'PATH', ENV['PATH']
#set :output, "/log/cron.log"
#set :stage, :environment_variable
every 5.minutes, :roles => [:app] do
runner "Model.method"
end
deploy.rb:
require 'capistrano/log_with_awesome'
require "bundler/capistrano"
set :application, "[REMOVED]"
set :scm, :git
set :repository, "[REMOVED]"
set :branch, "master"
set :deploy_via, :remote_cache
set :user, "[REMOVED]"
set :password, "[REMOVED]"
set :deploy_to, "[REMOVED]"
set :keep_releases, 5
task :qa do
set :domain, "[REMOVED]"
role :web, "[REMOVED]", {:port => [REMOVED]} # Your HTTP server, Nginx
role :app, "[REMOVED]", {:port => [REMOVED]} # This may be the same as your `Web` server
set :env, "test"
end
task :production do
set :domain, "[REMOVED]"
role :web, "[REMOVED]", {:port => [REMOVED]} # Your HTTP server, Nginx
role :app, "[REMOVED]", {:port => [REMOVED]} # This may be the same as your `Web` server
set :env, "production"
end
set :use_sudo, false
default_run_options[:pty] = true
role :db, "[REMOVED]", {:port => [REMOVED], primary: true, :no_release => true}
after "deploy:setup", "deploy:chown"
namespace :bundle do
task :install, {:roles => :app} do
run "cd #{release_path} && bundle install --deployment --without development test"
end
end
before "deploy:assets:precompile" do
transfer :up, "config/application.yml", "#{shared_path}/application.yml", :via => :scp
run "ln -nfs #{shared_path}/application.yml #{release_path}/config/application.yml"
end
namespace :whenever do
task :start, :roles => :app do
run "cd #{release_path} && bundle exec whenever --update-crontab"
end
end
namespace :deploy do
task :execute_migrations, :roles => :app do
puts "RUNNING DB MIGRATIONS"
run "cd #{current_path}; bundle exec rake RAILS_ENV=#{env} db:migrate"
end
task :chown do
run "#{try_sudo} chown -R #{user} #{deploy_to}"
end
task :restart_nginx, {:roles => :web} do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
before "deploy:restart_nginx", "deploy:execute_migrations"
after :deploy, "deploy:restart_nginx"
after "deploy:restart_nginx", "deploy:cleanup"
after "deploy:update", "whenever:start"
end
When I ssh into the server and run crontab -l in the app's current directory:
# Begin Whenever generated tasks for: /[REMOVED]/releases/20140204194143/config/schedule.rb
#0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash -l -c 'cd /[REMOVED]/releases/20140204194143 && script/rails runner -e production '\''Model.method'\'''
# End Whenever generated tasks for: [REMOVED]/releases/20140204194143/config/schedule.rb
When I run the cron job on the server like this I get this result:
:/[REMOVED]/current$ rails runner -e production '\''Model.method'\'''
Rails Error: Unable to access log file. Please ensure that /[REMOVED]/releases/20140204194143/log/production.log exists and is chmod 0666. The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/runner.rb:53:in `eval': (eval):1: syntax error, unexpected $undefined (SyntaxError)
\Model.method'
^
(eval):1: unterminated string meets end of file
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/runner.rb:53:in `<top (required)>'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:64:in `require'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:64:in `<top (required)>'
from script/rails:5:in `require'
from script/rails:5:in `<main>'
When I do it like this. I get this:
[REMOVED]/current$ rails runner Model.method
Rails Error: Unable to access log file. Please ensure that [REMOVED]/releases/20140204194143/log/development.log exists and is chmod 0666. The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
[REMOVED]/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `initialize': could not connect to server: Connection refused (PG::ConnectionBad)
Is the server running on host "localhost" ([REMOVED]) and accepting
TCP/IP connections on port 5432?
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `new'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `connect'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:326:in `initialize'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
from /usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
from /usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/model_schema.rb:308:in `clear_cache!'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/railtie.rb:97:in `block (2 levels) in <class:Railtie>'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:418:in `_run__249672195884464632__prepare__2220886522034318467__callbacks'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:405:in `__run_callback'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `instance_exec'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `run'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:55:in `block in run_initializers'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `each'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `run_initializers'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/application.rb:136:in `initialize!'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /[REMOVED]/releases/20140204194143/config/environment.rb:5:in `<top (required)>'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `require'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `block in require'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:236:in `load_dependency'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `require'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/application.rb:103:in `require_environment!'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/runner.rb:44:in `<top (required)>'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:64:in `require'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:64:in `<top (required)>'
from script/rails:5:in `require'
from script/rails:5:in `<main>'
In response to Leonid Shevtsov's answer:
I ran:
rails runner -e production 'Model.method'
and I got this:
[REMOVED]/current$ rails runner -e production 'Model.methodName'
/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/runner.rb:53:in `eval': undefined method `methodName' for #<Class:0x0000000570d668> (NoMethodError)
from (eval):1:in `<top (required)>'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/runner.rb:53:in `eval'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/runner.rb:53:in `<top (required)>'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:64:in `require'
from /[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:64:in `<top (required)>'
from script/rails:5:in `require'
from script/rails:5:in `<main>'
when I run crontab -l, I get the whenever generated crons
a) 1.9.1 is the "base" version of Ruby 1.9.3 (1.9.3 is considered to be a version of Ruby 1.9.1); it's normal that you see it in the paths.
b) the command line in cron is escaping quotes; the proper way to check it manually is rails runner -e production 'Model.method'
c) are you sure the error isn't arriving from a locally installed cron job? (check with crontab -l)
Ok this is kind of complicated and some debugging info is missing so I will try to take a guess.
First of all it seems that you have both rvm and rbenv installed on your system which is not a very good idea. Try uninstalling one of the two, or better yet uninstall both and reinstall the one you prefer.
In your deploy script it seems you have rolled your own whenever capistrano tasks. This is not bad, but whenever already provides this out of the box with better support (e.g. rollbacks). You can also get better feedback on your future problems.
Those are potential pitfalls but their are not probably the cause of your problems. You seem to have messed things up regarding the linux users and their permissions. As far as I understand there are two users on your production system: pkatepalli and another one which you commented out, lets call him deployer.
From what I see you are trying to set everything up to work from the perspective of deployer which is a good practice.
I assume the capistrano user variable is set to deployer. If not this is the root of your problem. This is the user which capistrano uses to log in and issue your commands.
Also it seems that when you run crontab -l you see the cron jobs correctly but if you are logged in with pkatepalli when you run the command then this is your problem. You have written your tasks to the wrong user's crontab. If this has happened it more likely means either that you run the whenever command from the wrong user during cap deploy (in which case you need to check which is the logged in user during cap) or you have actually run the whenever command from both users and you are only getting errors for pkatepalli (clear your crontab before experimenting again). If it still looks it is ok then you can try passing the -u username option to whenever command (you probably need sudo for this).
To set up the deployer user properly you can follow the instructions by capistrano

Enhance assets:precompile on Heroku to add non fingerptinted filenames

In a Rails 4 app, I want precompiled assets to have copies of some assets to be available with a non fingerprinted filename. The app is deployed on Heroku.
I have the following rake task in place:
namespace :app do
task :nonfingerprint_assets => :environment do
manifests = Rails.application.config.assets[:precompile]
manifests = manifests.slice(1, manifests.length)
assets = Dir.glob(File.join(Rails.root, 'public/assets/**/*'))
regex = /(-{1}[a-z0-9]{32}*\.{1}){1}/
assets.each do |file|
next if File.directory?(file) || file !~ regex
source = file.split('/')
source.push(source.pop.gsub(regex, '.'))
non_digested = File.join(source)
if manifests.any? {|m|
if m.is_a? Regexp
m.match non_digested
else
m.ends_with?(non_digested)
end
}
puts "** copy source: #{file}"
puts "** copy destination: #{non_digested}"
FileUtils.cp(file, non_digested)
end
end
end
end
Rake::Task['assets:precompile'].enhance do
puts "Invoke nonfingerprint_assets"
Rake::Task['app:nonfingerprint_assets'].invoke
end
This rake task is working fine on my local machine even in production environment. It creates a file in public/assets/application.js which is the copy of the same file with a digest in its name.
When I deploy this code to heroku I get the following error message which I don't understand:
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_
locales = false to avoid this message.
Invoke nonfingerprint_assets
** copy source: /tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/public/assets/application-51d1660b66655782ab137ee98c789fdd.js
** copy destination: /tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/public/assets/application.js
rake aborted!
No such file or directory - /tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/public/assets/application.js
/tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/lib/tasks/production.rake:26:in `block (3 levels) in <top (required)>'
/tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/lib/tasks/production.rake:9:in `each'
/tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/lib/tasks/production.rake:9:in `block (2 levels) in <top (required)>'
/tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/lib/tasks/production.rake:45:in `block in <top (required)>'
Tasks: TOP => app:nonfingerprint_assets
(See full trace by running task with --trace)
Please help me to understand what's going on.

Resources