sous-chefs / sc-mongodb

Development repository for the sc-mongodb cookbook
https://supermarket.chef.io/cookbooks/sc-mongodb
Apache License 2.0
75 stars 91 forks source link

mongod doesn't start as part of a replica set configuration #182

Closed wdeviers closed 6 years ago

wdeviers commented 6 years ago

On 1.0.0, Chef 12.21.31. Attempting to configure replica sets. The code beginning on line 34 of libraries/mongodb.rb:

begin connection = nil rescue_connection_failure do connection = Mongo::Connection.new('localhost', node['mongodb']['config']['port'], op_timeout: 20, slave_ok: true) connection.database_names # check connection end rescue => e Chef::Log.warn("Could not connect to database: 'localhost:#{node['mongodb']['config']['port']}', reason: #{e}") return end

When this executes (as called from definitions/mongodb.rb ~ :284), mongod is not running. I've hit my time-box limit for trying to use this cookbook, but as near as I can tell, the interpolation for the service definition in the same file doesn't work as expected.

Using action: [:enable, :start], in the definition for :mongodb_instance appears not to work. When I remove the variable and replace it with just :start, the service starts as expected, which lets that code block return clean, which attempts to continue the install.

However, it fails on libraries/mongodb.rb:54 ->

  host = "#{members[n]['fqdn']}:#{members[n]['mongodb']['config']['mongod']['net']['port']}"

because at the the time the search query runs, the first node in the replica set hasn't checked in with Chef yet so the data on the port isn't configured unless it's part of the role applied to the node before running chef-client with the wrapper cookbook attached.

mateusduboli commented 6 years ago

When using the replicaset, the way we do things is using the chef search to identify and configure the replicaset nodes.

So by definition we can't create a mongodb instance AND configure the replicaset on the same chef run, because the node needs at least a successful chef run to listed on chef server.

The current process in order to create the replicaset is documented here.

But simplifying is:

mateusduboli commented 6 years ago

Does this makes sense to you? If it does I'll close the issue :)

wdeviers commented 6 years ago

It makes sense, but I'm not sure it's addressing this issue. mongod wouldn't start regardless of the replicaset flag. Let me do some more experimentation though. Thanks!

mateusduboli commented 6 years ago

You're trying to run only the sc-mongodb::replicaset cookbook?

Can you tell more about your environment so I can understand better?

On a side note, I have a cluster of mongodb myself and use the setup I described earlier, and don't have any issues with that.

BMonsalvatge commented 6 years ago

The wording in the documentation seems a little odd to me. In a scenario with 3 nodes, are we supposed to first install the sc-mongodb::replicaset recipe to the first two nodes with node['mongodb']['auto_configure']['replicaset'] = false. Then after chef has ran on both of those, run sc-mongodb::replicaset on the 3rd node with node['mongodb']['auto_configure']['replicaset'] = true?

I've been attempting this and I have not had any luck getting it to work so far. I'll update here if I make any progress.

BMonsalvatge commented 6 years ago

Error message when following the steps above for reference:

NoMethodError
    -------------
    undefined method `[]' for nil:NilClass

    Cookbook Trace:
    ---------------
    /var/chef/cache/cookbooks/sc-mongodb/libraries/mongodb.rb:74:in `configure_replicaset'
    /var/chef/cache/cookbooks/sc-mongodb/definitions/mongodb.rb:246:in `block (3 levels) in from_file'

    Resource Declaration:
    ---------------------
    # In /var/chef/cache/cookbooks/sc-mongodb/definitions/mongodb.rb

    244:     ruby_block 'config_replicaset' do
    245:       block do
    246:         MongoDB.configure_replicaset(node, replicaset_name, rs_nodes) unless new_resource.replicaset.nil?
    247:       end
    248:       action :nothing
    249:     end
    250: 

    Compiled Resource:
    ------------------
    # Declared in /var/chef/cache/cookbooks/sc-mongodb/definitions/mongodb.rb:244:in `block in from_file'

    ruby_block("config_replicaset") do
      params {:mongodb_type=>"mongod", :action=>[:enable, :start], :logpath=>"/var/log/mongodb/mongod.log", :configservers=>[], :replicaset=>true, :notifies=>[], :not_if=>[], :name=>"mongod"}
      action [:nothing]
      retries 0
      retry_delay 2
      default_guard_interpreter :default
      block_name "config_replicaset"
      declared_type :ruby_block
      cookbook_name "sc-mongodb"
      recipe_name "replicaset"
      block #<Proc:0x0000000003be0ef8@/var/chef/cache/cookbooks/sc-mongodb/definitions/mongodb.rb:245>
    end

    System Info:
    ------------
    chef_version=12.22.5
    platform=ubuntu
    platform_version=16.04
    ruby=ruby 2.3.6p384 (2017-12-14 revision 61254) [x86_64-linux]
    program_name=chef-client worker: ppid=12395;start=19:53:50;
    executable=/opt/chef/bin/chef-client
BMonsalvatge commented 6 years ago

Nevermind, this was fixed in the release of 1.2.0.

mateusduboli commented 6 years ago

Seems not an issue anymore, closing.

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.