Class: Dolphin::Mongodb

Inherits:
Base
  • Object
show all
Defined in:
lib/dolphin/ubuntu/mongodb.rb

Overview

Mongodb related tasks

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Dolphin::Base

Instance Method Details

#backupObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/dolphin/ubuntu/mongodb.rb', line 79

def backup
  # upload files
  upload("#{@config_root}/mongo/*", "/tmp")

  menu = [
    %{
      mkdir -p ~/backups/mongodb
      mv /tmp/mg* ~/backups/mongodb
      # # add cron job to /var/spool/cron/crontabs/user
      crontab /tmp/cron.txt
    },

  ]

  execute menu
end

#configObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/dolphin/ubuntu/mongodb.rb', line 43

def config
  # upload files
  upload("#{@config_root}/mongo/*", "/tmp")

  # allow access from peers
  ufw = [
    '# ufw',
    'sudo ufw allow from 192.168.0.0/16 to any port 27017',
    'sudo ufw allow from 192.168.0.0/16 to any port 28017',
  ]
  @group_hash[:mg].each do |item|
    ufw << "sudo ufw allow from #{@server_hash[item]}/32 to any port 27017"
    ufw << "sudo ufw allow from #{@server_hash[item]}/32 to any port 28017"
  end
  ufw << "sudo ufw status numbered"

  menu = [
    ufw.join("\n"),

    # config files
    %{
      sudo mv /tmp/mongodb.conf /etc/
      sudo chown root:root /etc/mongodb.conf
      sudo mv /tmp/keyfile.txt /etc/
      sudo chown mongodb:mongodb /etc/keyfile.txt
      sudo chmod go-r /etc/keyfile.txt
      sudo restart mongodb
    },

  ]

  execute menu

end

#disableObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/dolphin/ubuntu/mongodb.rb', line 19

def disable
  menu = [
    %{
      sudo stop mongodb
      sudo sh -c 'echo manual > /etc/init/mongodb.override'
    },
  ]

  execute menu
end

#enableObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/dolphin/ubuntu/mongodb.rb', line 31

def enable
  menu = [
    %{
      sudo rm -f /etc/init/mongodb.override
      sudo start mongodb
    },
  ]

  execute menu
end

#installObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/dolphin/ubuntu/mongodb.rb', line 5

def install
  menu = [
    %{
      sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
      sudo echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/10gen.list
      sudo apt-get update
      sudo apt-get -y install mongodb-10gen
    },
  ]

  execute menu
end