Class: SnapEbs::Plugin::MongoPlugin

Inherits:
SnapEbs::Plugin show all
Defined in:
lib/plugins/mongo_plugin.rb

Constant Summary collapse

WIRED_TIGER_KEY =
'wiredTiger'

Instance Attribute Summary collapse

Attributes inherited from SnapEbs::Plugin

#options

Instance Method Summary collapse

Methods inherited from SnapEbs::Plugin

#collect_options, inherited, registered_plugins

Instance Attribute Details

#client=(value) ⇒ Object

Sets the attribute client



4
5
6
# File 'lib/plugins/mongo_plugin.rb', line 4

def client=(value)
  @client = value
end

Instance Method Details

#afterObject



51
52
53
54
55
56
57
# File 'lib/plugins/mongo_plugin.rb', line 51

def after
  unlock_or_start_mongo

  if carefully('check that mongo is still accessible') { client.command(serverStatus: 1).first }
    logger.info "Received status from mongo, everything appears to be ok"
  end
end

#beforeObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/plugins/mongo_plugin.rb', line 37

def before
  require 'mongo'
  Mongo::Logger.logger = logger
  return unless safe_to_operate?

  if wired_tiger?
    logger.info "Wired Tiger storage engine detected"
    carefully('stop mongo') { stop_mongo } if options.shutdown
  else
    logger.info "MMAPv1 storage engine detected"
    carefully('lock mongo') { lock_mongo }
  end
end

#default_optionsObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/plugins/mongo_plugin.rb', line 22

def default_options
  {
    shutdown: false,
    command: "service mongod start",
    retry: 720,
    interval: 5,
    port: '27017',
    host: 'localhost',
    server_selection_timeout: 30,
    wait_queue_timeout: 1,
    connection_timeout: 5,
    socket_timeout: 5
  }
end

#defined_optionsObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/plugins/mongo_plugin.rb', line 5

def defined_options
  {
    shutdown: 'Shutdown mongodb server (this is required if your data and journal are on different volumes',
    command: 'Command to start mongodb if the server must be shut down (i.e. multi-volume Wired Tiger)',
    retry: 'How many times to retry starting or unlocking mongodb (default: 720)',
    interval: 'Interval (in seconds) to wait when retrying (default: 5)',
    user: 'Mongo user',
    password: 'Mongo password',
    port: 'Mongo port',
    host: 'Mongo host',
    server_selection_timeout: 'Timeout in seconds while choosing a server to connect to (default 30)',
    wait_queue_timeout: 'Timeout in seconds while waiting for a connection in the pool (default 1)',
    connection_timeout: 'Timeout in seconds to wait for a socket to connect (default 5)',
    socket_timeout: 'Timeout in seconds to wait for an operation to execute on a socket (default 5)'
  }
end

#nameObject



59
60
61
# File 'lib/plugins/mongo_plugin.rb', line 59

def name
  "Mongo"
end