问题描述
我使用capistrano和任何gem。
Capistrano部署和更新crontab在我们的Ubuntu服务器上cronjob详细介绍我们的schedule.rb文件。
但cronjob不会发生。它失败,并每5分钟发出一封电子邮件这个错误:
/etc/profile.d/rvm.sh:第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':无法加载这样的文件 - - bundler / setup(LoadError)
从/home/pkatepalli/.rbenv/versions/1.9.3-p448/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in`require'
来自/[REMOVED]/releases/20140204194143/config/boot.rb:6:in`< top(必需)>'
从/home/pkatepalli/.rbenv/versions/1.9.3- p448 / lib / ruby / 1.9.1 / rubygems / custom_require.rb:36:在`require'
从/home/pkatepalli/.rbenv/versions/1.9.3-p448/lib/ruby/1.9.1 /rubygems/custom_require.rb:36:in`require'
从script / rails:4:在`< main>'
奇怪的部分是使用不同于pkatepalli的用户名来部署。 pkatepalli是我在服务器上的用户名。这就解释了为什么它发送电子邮件给我的错误 - 我想。
此外,我们使用ruby 1.9.3不是1.9.1。我不知道为什么它不使用正确的ruby版本。
在服务器上:
Bundler版本1.3.5
ruby 1.9.3p448(2013-06-27修订版41675)[x86_64-linux]
$ rbenv版本
1.9.3-p448(由/[REMOVED]/current/.ruby-version设置)
但有趣的是,在当前目录下有ruby 1.9.1,我很困惑:
/current/vendor/bundle/ruby/1.9.1
$ b b
gemfile:
gem'every',require:false
schedule.rb:
我已尝试取消注释:env' PATH',ENV ['PATH'],但被放入schedule.rb文件的PATH没有帮助。
在本地,我们使用RVM而不是rbenv(在服务器上使用)。如果我们设置:env'PATH',ENV ['PATH']<$ p c $ c> #env'PATH',ENV ['PATH']
#set:output,/log/cron.log
#set:stage,:environment_variable
every 5.minutes,:roles => [:app] do
runnerModel.method
end
strong> deploy.rb :
需要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
任务:qa do
:domain,[REMOVED]
role:web,[REMOVED],{:port => [REMOVED]}#您的HTTP服务器,Nginx
角色:app,[REMOVED],{:port => [REMOVED]}#这可能和你的`Web`服务器相同
set:env,test
end
task:production do
set:domain,[REMOVED]
role:web,[REMOVED],{:port => [REMOVED]}#您的HTTP服务器,Nginx
角色:app,[REMOVED],{:port => [REMOVED]}#这可能和你的`Web`服务器相同
set:env,production
end
set:use_sudo,false b $ b default_run_options [:pty] = true
role:db,[REMOVED],{:port => [REMOVED],primary:true,:no_release => true
deploy:setup,deploy:chown
命名空间:bundle do
任务:install,{:roles = > :app} do
运行cd#{release_path}& bundle install --deployment - without development test
end
end
beforedeploy:assets:precompiledo
transfer:up,config / application.yml,#{shared_path} /application.yml,:via => :scp
runln -nfs#{shared_path} /application.yml#{release_path} /config/application.yml
end
$ b b namespace:every do
task:start,:roles => :app do
runcd#{release_path}&& bundle exec - --update-crontab
end
end
命名空间:deploy do
task:execute_migrations,:roles => :app do
putsRUNNING DB MIGRATIONS
runcd#{current_path}; bundle exec rake RAILS_ENV =#{env} db:migrate
end
$ b b 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:cleanup
之后部署deploy:restart:restart_nginx,deploy:execute_migrations
b
afterdeploy:update,every:start
end
当我ssh进入服务器并在应用程序的当前目录中运行crontab -l时:
#Begin每当生成任务时:/[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'\''
#结束每当生成的任务:[REMOVED] /releases/20140204194143/config/schedule.rb
当我在服务器上运行cron作业时,我得到这个结果:
:/ [REMOVED] / current $ rails runner -e production'\''Model.method'\''
Rails错误:无法访问日志文件。请确保/[REMOVED]/releases/20140204194143/log/production.log存在,并且为chmod 0666.日志级别已升至WARN,并且输出定向到STDERR,直到问题解决。
/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/runner.rb:53:in'eval':(eval ):1:语法错误,意外$ undefined(SyntaxError)
\Model.method'
^
(eval):1:未终止的字符串遇到文件结尾
从/ [REMOVED] /releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/runner.rb:53:in`⊤ top(必填)>'
来自/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:64:in`require'
从/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:64:in`< top(必填)>'
从脚本/ rails:5:在`require'
从脚本/ rails:5:在`< main>'
当我这样做。我得到这个:
[REMOVED] / current $ rails runner Model.method
Rails错误:无法访问日志文件。请确保[REMOVED] /releases/20140204194143/log/development.log存在,并且为chmod 0666.日志级别已升至WARN,并且输出定向到STDERR,直到问题解决。
[REMOVED] /20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in'initialize':无法连接到服务器:连接被拒绝(PG :: ConnectionBad)
服务器是否在主机localhost([REMOVED])上运行,并且在端口5432上接受
TCP / IP连接?
来自/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:innew
来自/[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'
从/[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'
从/ [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'
从/ [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'
从/ [REMOVED] /发行版/ 20140204194143 / vendor / bundle / ruby / 1.9.1 / gems / activerecord-3.2.12 / lib / active_record / connection_adapters / abstract / connection_pool.rb:315:在`new_connection'
从/ [REMOVED]发布/ 20140204194143 / vendor / bundle / ruby / 1.9.1 / gems / activerecord-3.2.12 / lib / active_record / connection_adapters / abstract / connection_pool.rb:325:在`checkout_new_connection'
从/ [REMOVED] release / 20140204194143 / vendor / bundle / ruby / 1.9.1 / gems / activerecord-3.2.12 / lib / active_record / connection_adapters / abstract / connection_pool.rb:247:在`block(2 levels)in checkout'
来自/[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'
从/[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在结帐块
从/usr/lib/ruby/1.9.1/monitor.rb:211:in`mon_synchronize'
从/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/ activerecord-3.2.12 / lib / active_record / connection_adapters / abstract / connection_pool.rb:239:在`checkout'
从/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/ activerecord-3.2.12 / lib / active_record / connection_adapters / abstract / connection_pool.rb:102:在`block in connection'
从/usr/lib/ruby/1.9.1/monitor.rb:211:in` mon_synchronize'
来自/[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`连接'$ b $ b从/[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'
从/[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'
从/[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'连接'$ b $ b来自/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/model_schema.rb:308:in`clear_cache!'
来自/[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>'
来自/[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'
来自/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:405:in`__run_callback'
从/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:385:in`_run_prepare_callbacks'
从/ [REMOVED] /releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:81:in`run_callbacks'
从/ [REMOVED] / release / 20140204194143 / vendor / bundle / ruby / 1.9.1 / gems / actionpack-3.2.12 / lib / action_dispatch / middleware / reloader.rb:74:在`prepare!'
从/ [REMOVED] /20140204194143/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/reloader.rb:48:in`prepare!'
从/ [REMOVED] / releases /
从/ [/ b]中的中的块 REMOVED] /releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb30:in`instance_exec'
来自/ [REMOVED] / releases /20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:30:in`run'
从/ [REMOVED] / releases / 20140204194143 / vendor /bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:55:in`block in run_initializers'
从/ [REMOVED] / releases / 20140204194143 / vendor / bundle /ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:54:in`each'
来自/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9 .1 / gems / railties-3.2.12 / lib / rails / initializable.rb:54:在`run_initializers'
从/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems /railties-3.2.12/lib/rails/application.rb:136:in'initialize!'
来自/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties- 3.2.12 / lib / rails / railtie / configurable.rb:30:in`method_missing'
从/[REMOVED]/releases/20140204194143/config/environment.rb:5:in`< top >'
来自/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in`require'
来自/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/actenciesupport-3.2.12/lib/active_support/dependencies.rb:251:in'block in require'
从/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:236:in`load_dependency'
从/ [ REMOVED] /releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in`require'
来自/ [REMOVED] / releases /20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/application.rb:103:in`require_environment!'
从/ [REMOVED] / releases / 20140204194143 / vendor / bundle / ruby / 1.9.1 / gems / railties-3.2.12 / lib / rails / commands / runner.rb:44:在`< top(必需)>'
从/ [REMOVED] /releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:64:in`require'
从/ [REMOVED] / releases / 20140204194143 /vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:64:in`< top(必需)>'
from script / rails:5 :`require'
从脚本/ rails:5:在`< main>'
为了响应Leonid Shevtsov的回答:
我跑了:
rails runner -e production'Model.method'
这:
[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)>'
从/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems /railties-3.2.12/lib/rails/commands/runner.rb:53:in' eval'
来自/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/railties -3.2.12 / lib / rails / commands / runner.rb:53:in`< top(必需)>'
从/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9。 1 / gems / railties-3.2.12 / lib / rails / commands.rb:64:在`require'
从/[REMOVED]/releases/20140204194143/vendor/bundle/ruby/1.9.1/gems/ raillets-3.2.12 / lib / rails / commands.rb:64:在`< top(必需)>'
从脚本/ rails:5:在`require'
从脚本/ rails :5:当我运行crontab -l时,在`< main>'
生成crons
确定这是一个复杂的一些调试信息丢失,所以我会尝试猜测。 p>
-
首先看起来你有 rvm 和 rbenv 安装在您的系统上,这是更好的支持(例如回滚)。您还可以获得有关您未来问题的更好反馈。
这些是潜在的陷阱,但它们可能不是您的问题的原因。你似乎搞乱了关于linux用户和他们的权限。据我所知,你的生产系统上有两个用户: pkatepalli 和另一个你注释掉,让他 deployer 。
根据我看到的,你正在尝试从 deployer 这是一个好习惯。
- 我假设capistrano 用户变量设置为 deployer 。如果不是这是你的问题的根源。这是capistrano用来登录和发出命令的用户。
- 此外,当您运行 crontab -l 时,您会看到cron工作正确 当你运行命令时,用 pkatepalli 登录,这是你的问题。您已将您的任务写入错误的用户的crontab。如果这发生了它更可能意味着你运行每当命令从错误的用户在cap部署(在这种情况下,你需要检查哪个是登录的用户或者你实际上运行每当命令从两个用户和你只得到 pkatepalli 的错误(清除你的crontab再试验之前)。如果它仍然看起来确定,那么您可以尝试通过选项> /capistranorb.com/documentation/getting-started/authentication-and-authorisation/rel =nofollow> capistrano
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
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
这篇关于rails脚本使用每当gem错误:__rvm_add_to_path:命令未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!