errors running daemon

46 views
Skip to first unread message

derekfitz

unread,
Aug 9, 2009, 12:48:54 AM8/9/09
to Daemon Kit
I have 2 separate servers with the same Rails app installed on each.
However, when I try to run my daemon, I get different errors on each.
(I have a line in my daemon code to require the environment.rb in my
rails app so the app will load and the daemon will have access to
everything in the app) The daemon runs fine locally, but errors when
I try to run it on the servers. I assume it's something with the
installation, but I'm not sure what. Anybody know what might be
causing either of these?

Error 1--------------------------------------------------------
/opt/ruby/current/lib/ruby/site_ruby/1.8/rubygems.rb:258:in
`activate': can't activate activesupport (= 2.3.2, runtime) for
["rails-2.3.2"], already activated activesupport-2.3.3 for
["rubigen-1.5.2", "daemon-kit-0.1.7.9"] (Gem::Exception)
from /opt/ruby/current/lib/ruby/site_ruby/1.8/rubygems.rb:
274:in `activate'
from /opt/ruby/current/lib/ruby/site_ruby/1.8/rubygems.rb:
273:in `each'
from /opt/ruby/current/lib/ruby/site_ruby/1.8/rubygems.rb:
273:in `activate'
from /opt/ruby/current/lib/ruby/site_ruby/1.8/rubygems.rb:
50:in `gem'
from /opt/.../app/daemons/draft_watcher/libexec/../../../../
config/boot.rb:60:in `load_rails_gem'
from /opt/.../app/daemons/draft_watcher/libexec/../../../../
config/boot.rb:54:in `load_initializer'
from /opt/.../app/daemons/draft_watcher/libexec/../../../../
config/boot.rb:38:in `run'
from /opt/.../app/daemons/draft_watcher/libexec/../../../../
config/boot.rb:11:in `boot!'
... 8 levels...
from /opt/ruby/current/lib/ruby/site_ruby/1.8/rubygems/
custom_require.rb:31:in `require'
from /opt/scp/ruby/ruby-enterprise-1.8.6-20090610/lib/ruby/
gems/1.8/gems/daemon-kit-0.1.7.9/lib/daemon_kit/application.rb:38:in
`run'
from /opt/scp/ruby/ruby-enterprise-1.8.6-20090610/lib/ruby/
gems/1.8/gems/daemon-kit-0.1.7.9/lib/daemon_kit/application.rb:21:in
`exec'
from draft_watcher:7

Error 2------------------------------------------------------------
./../config/boot.rb:46:in `load_initializer': uninitialized constant
DaemonKit::GemBoot::Gem (NameError)
from ./../config/boot.rb:29:in `run'
from ./../config/boot.rb:10:in `boot!'
from ./../config/boot.rb:68
from ./../config/environment.rb:7:in `require'
from ./../config/environment.rb:7
from draft_watcher:5:in `require'
from draft_watcher:5

Kenneth Kalmer

unread,
Aug 9, 2009, 9:29:58 AM8/9/09
to daemo...@googlegroups.com
Hi Derek

Thanks for trying daemon-kit. Just to note, daemon-kit hasn't been written to run with Rails (yet), and there might be some havoc caused with class reloading in development mode. That said, production should be just fine, as long as you handle ActiveRecord exceptions that are thrown when the database server terminates idle connections (very common issue in daemonized processes using AR).

I'll give it my best shot to diagnose your troubles.

On Sun, Aug 9, 2009 at 6:48 AM, derekfitz <dere...@gmail.com> wrote:

I have 2 separate servers with the same Rails app installed on each.
However, when I try to run my daemon, I get different errors on each.
(I have a line in my daemon code to require the environment.rb in my
rails app so the app will load and the daemon will have access to
everything in the app)  The daemon runs fine locally, but errors when
I try to run it on the servers.  I assume it's something with the
installation, but I'm not sure what.  Anybody know what might be
causing either of these?

Error 1--------------------------------------------------------
/opt/ruby/current/lib/ruby/site_ruby/1.8/rubygems.rb:258:in
`activate': can't activate activesupport (= 2.3.2, runtime) for
["rails-2.3.2"], already activated activesupport-2.3.3 for
["rubigen-1.5.2", "daemon-kit-0.1.7.9"] (Gem::Exception)

This one is nasty. Seems rubigen, on which dk depends, has a dependency on ActiveSupport 2.2.2 or greater. This would load the latest ActiveSupport on your server, which seems to be 2.3.3. This happens long before your Rails' environment.rb is loaded, which probably has a reference to the 2.3.2 version of Rails. So when Rails boots itself, it tries to load the previous version ActiveSupport and rubygems refuses...

Solutions, upgrade locally to Rails 2.3.3 or make sure Rails 2.3.3 is removed from the server.
 
Error 2------------------------------------------------------------
./../config/boot.rb:46:in `load_initializer': uninitialized constant
DaemonKit::GemBoot::Gem (NameError)
       from ./../config/boot.rb:29:in `run'
       from ./../config/boot.rb:10:in `boot!'
       from ./../config/boot.rb:68
       from ./../config/environment.rb:7:in `require'
       from ./../config/environment.rb:7
       from draft_watcher:5:in `require'
       from draft_watcher:5

It seems that rubygems isn't installed in this server, or not available at the time of booting. I did a quick test by me to see what happens when rubygems are not loaded automatically and the code still worked as expected.

Solutions, make sure rubygems itself is installed on this box, well, I hope this is the solution.

Do let us know how this works for you with Rails in the mix !

Best
 
--
Kenneth Kalmer
kenneth...@gmail.com
http://opensourcery.co.za
@kennethkalmer

Ben

unread,
Aug 9, 2009, 11:59:46 AM8/9/09
to Daemon Kit
If you just need ActiveRecord and not all of rails, then heres how I
do that.

In pre-daemonize, I have a gems.rb file:

require 'active_record'

In post-daemonize, I have database_setup.rb file:

db_yaml = DaemonKit::Config.load('database')
DaemonKit.logger.info "Setting up ActiveRecord Connection"

ActiveRecord::Base.establish_connection(db_yaml.to_h)

This is loading in a standard database.yml file.

You'll need a lib file for each of your AR models.

class Post < ActiveRecord::Base
end

Then require it inside libexec of where ever you need to use it.

Lastly, I use the AR connection in libexec/daemon_name.rb

loop do

ActiveRecord::Base.connection_pool.with_connection do |conn|
# Do AR work here
end
sleep 60

end

One last note, Sqlite3 database does not work well if you have a Rails
app and a daemon talking to it at the same time. Also configure your
database.yml files on both the rails app and daemon so the pool stays
under whatever your max connections is for your database. If you do
use Sqlite3 for testing, etc in your daemon's database.yml put in the
full path to the database. Daemon-kit currently Dir.chdir to "/" when
it boots.

Ben
> kenneth.kal...@gmail.comhttp://opensourcery.co.za
> @kennethkalmer
Reply all
Reply to author
Forward
0 new messages