-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsystems.py
More file actions
300 lines (245 loc) · 13.3 KB
/
Copy pathsystems.py
File metadata and controls
300 lines (245 loc) · 13.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
from fabric.api import run, sudo
from fabric.contrib.files import exists, contains, append
from fabric.utils import abort
#utility functions
def abort_with_message(message):
abort(message)
def basic_install_check(message, config_loc, mongod_bin_loc, data_dir_loc):
#check existence of config file
if not exists(config_loc):
abort_with_message(message + 'config file not found')
#TODO should we the contents of the config file?
#check existence of binaries
if not exists(mongod_bin_loc):
abort_with_message(message + 'mongod binary not found')
#TODO should we check other binaries?
#check existence of data dir
if not exists(data_dir_loc):
abort_with_message(message + 'mongod data directory not found')
def basic_running_check(message, log_loc, lock_file_loc):
#confirm log exists
if not exists(log_loc):
abort_with_message(message + 'mongod log not found')
#confirm lockfile exists
if not contains(lock_file_loc, '[0123456789]', escape=False):
abort_with_message(message + 'mongod lock not found')
def basic_stopped_check(message, lock_file_loc):
#confirm that lockfile doesnt exist
if contains(lock_file_loc, '[0123456789]', escape=False):
abort_with_message(message + 'mongod lock not empty')
#systems
class system_operator(object):
def __init__(self):
pass
def install(self, enterprise=False):
pass
def install_old(self, version, enterprise=False):
pass
def start(self):
pass
def stop(self):
pass
def restart(self):
pass
def check_installed(self, version=None):
pass
def check_started(self):
pass
def check_stopped(self):
pass
class debian_operator(system_operator):
def __init__(self):
self.name = 'debian'
self.locations = {}
self.locations['config_loc'] = '/etc/mongod.conf'
self.locations['mongod_bin_loc'] = '/usr/bin/mongod'
self.locations['data_dir_loc'] = '/var/lib/mongodb'
self.locations['log_loc'] = '/var/lib/mongodb/mongodb.log'
self.locations['lock_file_loc'] = '/var/lib/mongodb/mongod.lock'
self.locations['pid_file_loc'] = '/var/run/mongod.pid'
def install(self, enterprise=False):
if enterprise:
sudo('apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10')
append('/etc/apt/sources.list.d/mongodb-enterprise.list', 'deb http://repo.mongodb.com/apt/debian wheezy/mongodb-enterprise/stable main', use_sudo=True)
sudo('apt-get update')
sudo('apt-get -y install mongodb-enterprise')
else:
sudo('apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10')
append('/etc/apt/sources.list.d/mongodb.list', 'deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen', use_sudo=True)
sudo('apt-get update')
sudo('apt-get -y install mongodb-org')
def install_old(self, version, enterprise=False):
if enterprise:
sudo('apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10')
#Note that versioning works differently here version should be something like '2.6' not '2.6.1'
append('/etc/apt/sources.list.d/mongodb-enterprise.list', 'deb http://repo.mongodb.com/apt/debian wheezy/mongodb-enterprise/' + version + ' main', use_sudo=True)
sudo('apt-get update')
sudo('apt-get -y install mongodb-enterprise')
else:
sudo('apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10')
append('/etc/apt/sources.list.d/mongodb.list', 'deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen', use_sudo=True)
sudo('apt-get update')
sudo('apt-get -y install mongodb-org=' + version + ' mongodb-org-server=' + version + ' mongodb-org-shell=' + version + ' mongodb-org-mongos=' + version + ' mongodb-org-tools=' + version)
def start(self):
sudo('service mongod start')
def stop(self):
sudo('service mongod stop')
def restart(self):
sudo('service mongod restart')
def check_installed(self, version=None):
basemsg = 'check_installed failed: '
basic_install_check(basemsg,
self.locations['config_loc'],
self.locations['mongod_bin_loc'],
self.locations['data_dir_loc'])
if version is not None:
#confirm the binaries are of the correct version
foundversion = run(self.locations['mongod_bin_loc'] + ' --version')
if version != foundversion:
abort_with_message(basemsg + 'version is not correct')
def check_started(self):
basemsg = 'check_started failed: '
basic_running_check(basemsg,
self.locations['log_loc'],
self.locations['lock_file_loc'])
#confirm pidfile exists
if not exists(self.locations['pid_file_loc']):
abort_with_message(basemsg + 'mongod pidfile not found')
def check_stopped(self):
basemsg = 'check_mongod_stopped failed: '
basic_stopped_check(basemsg,
self.locations['lock_file_loc'])
class ubuntu_operator(system_operator):
def __init__(self, ubuntuname):
self.name = 'ubuntu'
self.locations = {}
self.locations['config_loc'] = '/etc/mongod.conf'
self.locations['mongod_bin_loc'] = '/usr/bin/mongod'
self.locations['data_dir_loc'] = '/var/lib/mongodb'
self.locations['log_loc'] = '/var/log/mongodb/mongod.log'
self.locations['lock_file_loc'] = '/var/lib/mongodb/mongod.lock'
self.ubuntuname = ubuntuname
def install(self, enterprise=False):
if enterprise:
sudo('apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10')
append('/etc/apt/sources.list.d/mongodb-enterprise.list', 'deb http://repo.mongodb.com/apt/ubuntu ' + self.ubuntuname + '/mongodb-enterprise/stable multiverse', use_sudo=True)
sudo('apt-get update')
sudo('apt-get -y install mongodb-enterprise')
else:
sudo('apt-key adv --keyserver hkp://keyserver.ubuntu.com --recv 7F0CEB10')
append('/etc/apt/sources.list.d/mongodb.list', 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen', use_sudo=True)
sudo('apt-get update')
sudo('apt-get -y install mongodb-org')
def install_old(self, version, enterprise=False):
if enterprise:
sudo('apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10')
append('/etc/apt/sources.list.d/mongodb-enterprise.list', 'deb http://repo.mongodb.com/apt/ubuntu ' + self.ubuntuname + '/mongodb-enterprise/stable multiverse', use_sudo=True)
sudo('apt-get update')
sudo('apt-get -y install mongodb-enterprise=' + version + ' mongodb-enterprise-server=' + version + ' mongodb-enterprise-shell=' + version + ' mongodb-enterprise-mongos=' + version + ' mongodb-enterprise-tools=' + version)
else:
sudo('apt-key adv --keyserver hkp://keyserver.ubuntu.com --recv 7F0CEB10')
append('/etc/apt/sources.list.d/mongodb.list', 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen', use_sudo=True)
sudo('apt-get update')
sudo('apt-get -y install mongodb-org=' + version + ' mongodb-org-server=' + version + ' mongodb-org-shell=' + version + ' mongodb-org-mongos=' + version + ' mongodb-org-tools=' + version)
def start(self):
sudo('service mongod start')
def stop(self):
sudo('service mongod stop')
def restart(self):
sudo('service mongod restart')
def check_installed(self, version=None):
basemsg = 'check_installed failed: '
basic_install_check(basemsg,
self.locations['config_loc'],
self.locations['mongod_bin_loc'],
self.locations['data_dir_loc'])
if version is not None:
foundversion = run(self.locations['mongod_bin_loc'] + ' --version')
if version not in foundversion:
abort_with_message(basemsg + 'version is not correct')
def check_started(self):
basemsg = 'check_mongod_started failed: '
basic_running_check(basemsg,
self.locations['log_loc'],
self.locations['lock_file_loc'])
def check_stopped(self):
basemsg = 'check_mongod_stopped failed: '
basic_stopped_check(basemsg,
self.locations['lock_file_loc'])
class rhel_operator(system_operator):
def __init__(self, version, spawn_host):
self.name = 'rhel'
self.locations = {}
self.locations['config_loc'] = '/etc/mongod.conf'
self.locations['mongod_bin_loc'] = '/usr/bin/mongod'
self.locations['data_dir_loc'] = '/var/lib/mongo'
self.locations['log_loc'] = '/var/log/mongodb/mongod.log'
self.locations['lock_file_loc'] = '/var/lib/mongo/mongod.lock'
self.locations['pid_file_loc'] = '/var/run/mongodb/mongod.pid'
self.version = version
self.spawn_host = spawn_host
def install(self, enterprise=False):
if enterprise:
if self.version == 7 and self.spawn_host:
repo = '[mongodb-enterprise]\nname=MongoDB Enterprise Repository\nbaseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/stable/$basearch/\ngpgcheck=0\nenabled=1\n'
append('/etc/yum.repos.d/mongodb-enterprise-2.6.repo', repo)
run('yum -y install mongodb-enterprise')
else:
repo = '[mongodb-enterprise]\nname=MongoDB Enterprise Repository\nbaseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/stable/$basearch/\ngpgcheck=0\nenabled=1\n'
append('/etc/yum.repos.d/mongodb-enterprise-2.6.repo', repo, use_sudo=True)
sudo('yum -y install mongodb-enterprise')
else:
repo = '[mongodb]\nname=MongoDB Repository\nbaseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/\ngpgcheck=0\nenabled=1\n'
append('/etc/yum.repos.d/mongodb.repo', repo, use_sudo=True)
sudo('yum -y install mongodb-org')
def install_old(self, version, enterprise=False):
if enterprise:
if self.version == 7 and self.spawn_host:
repo = '[mongodb-enterprise]\nname=MongoDB Enterprise Repository\nbaseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/stable/$basearch/\ngpgcheck=0\nenabled=1\n'
append('/etc/yum.repos.d/mongodb-enterprise-2.6.repo', repo)
run('yum -y install mongodb-enterprise')
else:
repo = '[mongodb-enterprise]\nname=MongoDB Enterprise Repository\nbaseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/stable/$basearch/\ngpgcheck=0\nenabled=1\n'
append('/etc/yum.repos.d/mongodb-enterprise-2.6.repo', repo, use_sudo=True)
sudo('yum -y install mongodb-enterprise-2.6.1 mongodb-enterprise-server-2.6.1 mongodb-enterprise-shell-2.6.1 mongodb-enterprise-mongos-2.6.1 mongodb-enterprise-tools-2.6.1')
else:
repo = '[mongodb]\nname=MongoDB Repository\nbaseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/\ngpgcheck=0\nenabled=1\n'
append('/etc/yum.repos.d/mongodb.repo', repo, use_sudo=True)
sudo('yum -y install mongodb-org-' + version + ' mongodb-org-server-' + version + ' mongodb-org-shell-' + version +' mongodb-org-mongos-' + version + ' mongodb-org-tools-' + version)
def start(self):
if self.version == 7 and self.spawn_host:
run("service mongod start")
else:
sudo('service mongod start')
def stop(self):
if self.version == 7 and self.spawn_host:
run("service mongod stop")
else:
sudo('service mongod stop')
def restart(self):
if self.version == 7 and self.spawn_host:
run("service mongod restart")
else:
sudo('service mongod restart')
def check_installed(self, version=None):
basemsg = 'check_installed failed: '
basic_install_check(basemsg,
self.locations['config_loc'],
self.locations['mongod_bin_loc'],
self.locations['data_dir_loc'])
if version is not None:
foundversion = run(self.locations['mongod_bin_loc'] + ' --version')
if version not in foundversion:
abort_with_message(basemsg + 'version is not correct')
def check_started(self):
basemsg = 'check_mongod_started failed: '
basic_running_check(basemsg,
self.locations['log_loc'],
self.locations['lock_file_loc'])
#confirm pidfile exists
if not exists(self.locations['pid_file_loc']):
abort_with_message(basemsg + 'mongod pidfile not found')
def check_stopped(self):
basemsg = 'check_mongod_stopped failed: '
basic_stopped_check(basemsg,
self.locations['lock_file_loc'])