Skip to content
Newer
Older
100755 717 lines (595 sloc) 22.6 KB
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
1 #!/usr/bin/env python
2 import getpass, logging, os, re, signal, sys, time, urllib
3 from optparse import OptionParser
4
5 SIN_HOME = os.path.normpath(os.path.join(os.path.normpath(__file__), '..'))
6
7 APP_HOME = os.path.join(SIN_HOME, 'app')
8
9 app_settings = 'settings'
10 app_path = APP_HOME
11
12 os.environ['DJANGO_SETTINGS_MODULE'] = app_settings
13 if app_path:
14 sys.path.insert(0, app_path)
15
16 from django.conf import settings
17
18 try:
19 import paramiko
20 except ImportError:
21 print "paramiko is not installed. Please go to http://www.lag.net/paramiko/"
22 print "download the latest package, untar, cd into that directory, and run"
23 print "sudo easy_install ./"
24 sys.exit(1)
25
26 global_pass = ''
27
28 class BaseDeployer(object):
38368ee @wonlay Init nodes on zookeeper.
wonlay authored Nov 15, 2011
29 def __init__(self, host, home, node_id, login=None, server=False, user='root', upgrade=False, base=None):
191ccae @wonlay add login and upgrade options.
wonlay authored Nov 15, 2011
30 global global_pass
31
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
32 self.host = host
255b727 @wonlay Fix repo change.
wonlay authored Dec 5, 2011
33 self.home = os.path.normpath(home)
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
34 self.node_id = node_id
191ccae @wonlay add login and upgrade options.
wonlay authored Nov 15, 2011
35 self.login = login
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
36 self.server = server
37 self.user = user
191ccae @wonlay add login and upgrade options.
wonlay authored Nov 15, 2011
38 self.upgrade = upgrade
38368ee @wonlay Init nodes on zookeeper.
wonlay authored Nov 16, 2011
39 self.base = base
191ccae @wonlay add login and upgrade options.
wonlay authored Nov 15, 2011
40
41 self.password = None
42 self.pass_sent = False
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
43
38368ee @wonlay Init nodes on zookeeper.
wonlay authored Nov 16, 2011
44 if base:
45 self.ssh = base.ssh
46 self.sftp = base.sftp
47 self.shell = base.shell
48 else:
49 self.ssh = paramiko.SSHClient()
50 self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
51 retry = 0
52 while True:
53 try:
54 self.ssh.connect(self.host, username=self.login, password=self.password)
55 break
56 except paramiko.AuthenticationException:
57 retry += 1
58 if retry > 3:
59 print "Authentication failed."
60 sys.exit(1)
61 self.password = global_pass = getpass.getpass()
62 self.sftp = self.ssh.open_sftp()
63 self.shell = self.ssh.invoke_shell()
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
64
9d5d9a5 Start shell ``sh'' on remote server in deployment script.
Baoqiu Cui authored Jan 8, 2012
65 # Start a new shell with ``sh'' (in case the user is using other shells like tcsh)
66 self.shell.send('sh\n')
f580eb2 @wonlay Fix problem when user environment values are different.
wonlay authored Jan 5, 2012
67 # set PS1
68 self.shell.send('export PS1="deploy $ " 2>&1\n')
69
d5b1e14 @wonlay fix typo
wonlay authored Nov 15, 2011
70 # Read welcome message:
38368ee @wonlay Init nodes on zookeeper.
wonlay authored Nov 16, 2011
71 self._read_data()
72 print self.command('sudo -u %s sh' % 'root')
73
74 def get_deployer(self):
75 data = self.command('uname -a')
76 print data
77 if 'el6.x86_64' in data:
78 deployer_class = DeployerRHEL6_X86_64
79 elif 'Darwin' in data:
80 if 'x86_64' in data:
81 deployer_class = DeployerDarwin_X86_64
82 elif 'i386' in data:
83 deployer_class = DeployerDarwin_I386
84 else:
9578f8f @wonlay add deployer for systems with apt-get.
wonlay authored Jan 16, 2012
85 data = self.command('apt-get --version')
86 if 'command not found' in data:
87 print 'Platform not supported. You may have to install manually by'
88 print 'following: http://linkedin.jira.com/wiki/display/SIN/Developer+Setup'
89 sys.exit(1)
90 else:
91 deployer_class = DeployerWithApt
38368ee @wonlay Init nodes on zookeeper.
wonlay authored Nov 16, 2011
92
93 return deployer_class(self.host,
94 self.home,
95 self.node_id,
96 login = self.login,
97 server = self.server,
98 user = self.user,
99 upgrade = self.upgrade,
100 base = self)
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
101
102 def _check_sudo(self, data):
103 global global_pass
104 lines = re.split(r'[\r\n]+', data)
9d5d9a5 Start shell ``sh'' on remote server in deployment script.
Baoqiu Cui authored Jan 8, 2012
105 prompt = lines[-1]
106 if re.match(r'(^\[sudo\] password for \w+: |Password:)$', prompt):
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
107 # Need password
108 if self.pass_sent:
109 if data:
110 print data
111 data = ''
112 self.password = global_pass = getpass.getpass()
113
114 if not self.password:
115 if not global_pass:
116 if data:
117 print data
118 data = ''
119 self.password = global_pass = getpass.getpass()
120 else:
121 self.password = global_pass
122
123 self.pass_sent = True
124 self.shell.send('%s\n' % self.password)
125 else:
126 if self.pass_sent:
9d5d9a5 Start shell ``sh'' on remote server in deployment script.
Baoqiu Cui authored Jan 8, 2012
127 if re.match(r'^[#\$] $', prompt[-2:]): # Looking for shell prompt '$ ' or '# '.
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
128 if len(lines) > 1:
129 if re.match(r'sudo: \d+ incorrect password attempts', lines[-2]):
130 # Wrong password
131 self.password = global_pass = ''
132 raise Exception(lines[-2])
133 self.pass_sent = False
134
135 return data
136
137 def _read_data(self):
138 d = ''
9d5d9a5 Start shell ``sh'' on remote server in deployment script.
Baoqiu Cui authored Jan 8, 2012
139 while not re.match(r'^[#\$] $', d[-2:]): # Looking for shell prompt '$ ' or '# '.
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
140 while not self.shell.recv_ready():
141 time.sleep(.1)
142 d += self.shell.recv(8192)
143 d = self._check_sudo(d)
144
145 return d
146
147 def command(self, cmd):
148 self.shell.send('%s 2>&1\n' % cmd)
149 return self._read_data()
150
707e4ca @wonlay dev deploy alpha for macos.
wonlay authored Nov 17, 2011
151 def get_python_version(self):
152 data = self.command('python --version')
153 version = None
154 m = re.search(r'(?m)^Python (?P<version>[\d\.]+)', data)
155 if m:
156 version = m.group('version')
157
158 if version:
159 return version.split('.')
160
161 return None
162
191ccae @wonlay add login and upgrade options.
wonlay authored Nov 15, 2011
163 def autostart(self, service, on=True):
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
164 raise Exception("Not implemented")
165
166 def check_zkpython(self):
167 data = self.command('python -c "import zookeeper"')
168 print data
169 if 'ImportError:' in data:
170 return False
171 return True
172
173 def install_zkpython(self):
174 if self.check_zkpython():
175 return
176
177 self.do_install_zkpython()
178
179 def do_install_zkpython(self):
180 raise Exception("Not implemented")
181
0146ad2 @wonlay setuptools are required.
wonlay authored Nov 14, 2011
182 def check_setuptools(self):
183 data = self.command('easy_install --version')
184 print data
185 if 'command not found' in data:
186 return False
187 return True
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
188
0146ad2 @wonlay setuptools are required.
wonlay authored Nov 15, 2011
189 def install_setuptools(self):
190 if self.check_setuptools():
191 return
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
192
0146ad2 @wonlay setuptools are required.
wonlay authored Nov 15, 2011
193 self.do_install_setuptools()
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
194
0146ad2 @wonlay setuptools are required.
wonlay authored Nov 15, 2011
195 def do_install_setuptools(self):
707e4ca @wonlay dev deploy alpha for macos.
wonlay authored Nov 18, 2011
196 print 'Installing setuptools...'
197 py_version = self.get_python_version()
198 tmpfile = 'setuptools-0.6c11-py%s.%s.egg' % (py_version[0], py_version[1])
199 tmpfile_local = os.path.expanduser('~/local-%s' % tmpfile)
200 if not os.path.exists(tmpfile_local):
201 urllib.urlretrieve('http://pypi.python.org/packages/%s.%s/s/setuptools/%s' % (py_version[0],
202 py_version[1],
203 tmpfile), tmpfile_local)
204 try: self.sftp.remove(tmpfile)
205 except: pass
206
207 self.sftp.put(tmpfile_local, tmpfile)
208
209 print self.command('sh %s' % tmpfile)
210
211 try: self.sftp.remove(tmpfile)
212 except: pass
213
214 if not self.check_setuptools():
215 raise Exception("setuptools install failed!")
216 print 'setuptools installed.'
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
217
218 def check_django(self):
219 data = self.command('python -c "import django"')
220 print data
221 if 'ImportError:' in data:
222 return False
223 return True
224
225 def install_django(self):
226 if self.check_django():
227 return
228
229 print 'Installing django...'
230 version = '1.3.1'
231 name = 'Django-%s' % version
232 tmpfile = '%s.tar.gz' % name
ff9a3ca @wonlay deploy working for the same host.
wonlay authored Nov 15, 2011
233 tmpfile_local = os.path.expanduser('~/local-%s' % tmpfile)
234 if not os.path.exists(tmpfile_local):
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
235 urllib.urlretrieve('http://www.djangoproject.com/download/%s/tarball/' % version, tmpfile_local)
236
237 try: self.sftp.remove(tmpfile)
238 except: pass
239 self.command('\\rm -Rf %s' % name) # Remove the tmp dir
240
241 self.sftp.put(tmpfile_local, tmpfile)
ff9a3ca @wonlay deploy working for the same host.
wonlay authored Nov 15, 2011
242
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
243 self.command('tar xzf %s' % tmpfile)
244 print self.command('python %s/setup.py install' % name)
245
246 self.command('\\rm -Rf %s' % name) # Remove the tmp dir
247 try: self.sftp.remove(tmpfile)
248 except: pass
249 # Local file are not removed.
250
251 if not self.check_django():
252 raise Exception("django install failed!")
253 print 'django installed.'
254
255 def check_twisted(self):
256 data = self.command('python -c "import twisted.web"')
257 print data
258 if 'ImportError:' in data:
259 return False
260 return True
261
262 def install_twisted(self):
263 if self.check_twisted():
264 return
265
ff9a3ca @wonlay deploy working for the same host.
wonlay authored Nov 15, 2011
266 self.do_install_twisted()
267
268 def do_install_twisted(self):
707e4ca @wonlay dev deploy alpha for macos.
wonlay authored Nov 18, 2011
269 print 'Installing twisted...'
270 print self.command('easy_install Twisted')
271 if not self.check_twisted():
272 raise Exception("twisted install failed!")
273 print 'twisted installed.'
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
274
275 def check_cronolog(self):
276 data = self.command('cronolog --version')
277 print data
278 if 'command not found' in data:
279 return False
280 return True
281
282 def install_cronolog(self):
283 if self.check_cronolog():
284 return
285
286 self.do_install_cronolog()
287
288 def do_install_cronolog(self):
289 raise Exception("Not implemented")
290
291 def check_pyparsing(self):
292 data = self.command('python -c "import pyparsing"')
293 print data
294 if 'ImportError:' in data:
295 return False
296 return True
297
298 def install_pyparsing(self):
299 if self.check_pyparsing():
300 return
301
302 print 'Installing pyparsing...'
303 version = '1.5.5'
304 name = 'pyparsing-%s' % version
305 tmpfile = '%s.tar.gz' % name
ff9a3ca @wonlay deploy working for the same host.
wonlay authored Nov 15, 2011
306 tmpfile_local = os.path.expanduser('~/local-%s' % tmpfile)
307 if not os.path.exists(tmpfile_local):
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
308 urllib.urlretrieve('http://cheeseshop.python.org/packages/source/p/pypar'
309 'sing/pyparsing-%s.tar.gz' % version, tmpfile_local)
310
311 try: self.sftp.remove(tmpfile)
312 except: pass
313 self.command('\\rm -Rf %s' % name) # Remove the tmp dir
314
315 self.sftp.put(tmpfile_local, tmpfile)
ff9a3ca @wonlay deploy working for the same host.
wonlay authored Nov 15, 2011
316
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
317 self.command('tar xzf %s' % tmpfile)
318 print self.command('easy_install %s' % name)
319
320 self.command('\\rm -Rf %s' % name) # Remove the tmp dir
321 try: self.sftp.remove(tmpfile)
322 except: pass
323 # Local file are not removed.
324
325 if not self.check_pyparsing():
326 raise Exception("pyparsing install failed!")
327 print 'pyparsing installed.'
328
a0aa3cf @wonlay Cleanup sin client and add deployment script.
wonlay authored Nov 14, 2011
329 def check_pysensei(self):
330 data = self.command('python -c "import sensei"')
331 print data
332 if 'ImportError:' in data:
333 return False
334 return True
335
336 def install_pysensei(self):
337 if self.check_pysensei():
338 return
339
340 print 'Installing sensei-python...'
341 version = '1.0'
342 name = 'sensei-python-%s' % version
343 tmpfile = '%s.tar.gz' % name
ff9a3ca @wonlay deploy working for the same host.
wonlay authored Nov 15, 2011
344 tmpfile_local = os.path.expanduser('~/local-%s' % tmpfile)
345 if not os.path.exists(tmpfile_local):
255b727 @wonlay Fix repo change.
wonlay authored Dec 5, 2011
346 urllib.urlretrieve('https://github.com/downloads/senseidb/sensei/sensei-'
a0aa3cf @wonlay Cleanup sin client and add deployment script.
wonlay authored Nov 15, 2011
347 'python-%s.tar.gz' % version, tmpfile_local)
348
349 try: self.sftp.remove(tmpfile)
350 except: pass
351 self.command('\\rm -Rf %s' % name) # Remove the tmp dir
352
353 self.sftp.put(tmpfile_local, tmpfile)
ff9a3ca @wonlay deploy working for the same host.
wonlay authored Nov 15, 2011
354
a0aa3cf @wonlay Cleanup sin client and add deployment script.
wonlay authored Nov 15, 2011
355 self.command('tar xzf %s' % tmpfile)
356 print self.command('easy_install %s' % name)
357
358 self.command('\\rm -Rf %s' % name) # Remove the tmp dir
359 try: self.sftp.remove(tmpfile)
360 except: pass
361 # Local file are not removed.
362
363 if not self.check_pysensei():
364 raise Exception("sensei-python install failed!")
365 print 'sensei-python installed.'
366
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
367 def check_sin(self):
368 sin_server = '/etc/init.d/sin_server'
369 data = self.command('ls %s' % sin_server)
370 print data
371 if 'No such file or directory' in data:
372 return False
373 return True
374
375 def install_sin(self):
191ccae @wonlay add login and upgrade options.
wonlay authored Nov 15, 2011
376 if not self.upgrade and self.check_sin():
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
377 return
378
379 print 'Installing sin...'
380 tmpfile = 'sin.tar.gz'
ff9a3ca @wonlay deploy working for the same host.
wonlay authored Nov 15, 2011
381 tmpfile_local = os.path.expanduser('~/local-%s' % tmpfile)
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
382 # Packaging:
ff9a3ca @wonlay deploy working for the same host.
wonlay authored Nov 15, 2011
383 os.system('tar -C %s -czf %s --exclude log --exclude app/django --exclude '
191ccae @wonlay add login and upgrade options.
wonlay authored Nov 15, 2011
384 'demo/django --exclude admin/um --exclude "*.swp" --exclude "*.pyc" ./' % (SIN_HOME, tmpfile_local))
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
385
386 sin_server = '/etc/init.d/sin_server'
387 sin_agent = '/etc/init.d/sin_agent'
388 tmp_sin_server = 'sin_server'
389 tmp_sin_agent = 'sin_agent'
390
391 sin_server_src = 'start_script/linux/sin_server'
392 sin_agent_src = 'start_script/linux/sin_agent'
393 f = open(os.path.join(SIN_HOME, sin_server_src))
394 server = f.read()
395 f.close()
396 f = open(os.path.join(SIN_HOME, sin_agent_src))
397 agent = f.read()
398 f.close()
399
400 server = re.sub(r'(?m)^HOME=.*$', 'HOME=%s' % self.home, server)
401 server = re.sub(r'(?m)^USER=.*$', 'USER=%s' % self.user, server)
402 agent = re.sub(r'(?m)^HOME=.*$', 'HOME=%s' % self.home, agent)
403 agent = re.sub(r'(?m)^USER=.*$', 'USER=%s' % self.user, agent)
404 agent = re.sub(r'(?m)^NODE_ID=.*$', 'NODE_ID=%s' % self.node_id, agent)
405
406 # Install:
407 try: self.sftp.remove(tmpfile)
408 except: pass
409 try: self.sftp.remove(tmp_sin_server)
410 except: pass
411 try: self.sftp.remove(tmp_sin_agent)
412 except: pass
413
414 self.sftp.put(tmpfile_local, tmpfile)
415
416 f = self.sftp.file(tmp_sin_server, 'w')
417 f.write(server)
418 f.flush()
419 f.close()
420
421 f = self.sftp.file(tmp_sin_agent, 'w')
422 f.write(agent)
423 f.flush()
424 f.close()
425 print self.command('chmod 755 %s' % tmp_sin_server)
426 print self.command('chmod 755 %s' % tmp_sin_agent)
427
428 # Find out the default group the run as user in:
429 data = self.command('groups %s' % self.user)
430 group = None
431 m = re.search(r'(?m)^\S+ : (?P<group>\S+).*$', data)
432 if m:
433 group = m.group('group')
434
191ccae @wonlay add login and upgrade options.
wonlay authored Nov 15, 2011
435 if self.upgrade:
21e335d @wonlay Fix cleanup errors.
wonlay authored Dec 5, 2011
436 self.autostart('sin_server', on=False)
437 self.autostart('sin_agent', on=False)
191ccae @wonlay add login and upgrade options.
wonlay authored Nov 15, 2011
438 print self.command('%s stop' % sin_server)
439 print self.command('%s stop' % sin_agent)
440
d66e726 @wonlay Fix deploying problems.
wonlay authored Dec 7, 2011
441 print self.command('su %s -c "mkdir -p %s"' % (self.user, os.path.join(self.home, 'log/sin_server')))
442 print self.command('su %s -c "mkdir -p %s"' % (self.user, os.path.join(self.home, 'log/sin_agent')))
255b727 @wonlay Fix repo change.
wonlay authored Dec 5, 2011
443 # remove old version:
21e335d @wonlay Fix cleanup errors.
wonlay authored Dec 6, 2011
444 print self.command("\\ls %(home)s | \\grep -v 'log' | \\grep -v 'admin' | "
445 "\\awk '{print \"%(home)s/\"$0}' | \\xargs \\rm -Rf" % {'home': self.home})
255b727 @wonlay Fix repo change.
wonlay authored Dec 5, 2011
446
707e4ca @wonlay dev deploy alpha for macos.
wonlay authored Nov 18, 2011
447 print self.command('tar -C %s -xzf %s' % (self.home, tmpfile))
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
448
449 print self.command('\\cp -f %s %s' % (tmp_sin_server, os.path.join(self.home, sin_server_src)))
450 data = self.command('\\cp -f %s %s' % (tmp_sin_agent, os.path.join(self.home, sin_agent_src)))
451 if not 'No such file or directory' in data:
452 if group:
453 print self.command('chown -R %s:%s %s' % (self.user, group, self.home))
454 else:
455 print self.command('chown -R %s %s' % (self.user, self.home))
456
c68e522 @wonlay detect hostname changes in settings; deploy is working on mac.
wonlay authored Dec 20, 2011
457 print self.command('mkdir -p /etc/init.d')
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
458 print self.command('\\cp -f %s %s' % (tmp_sin_server, sin_server))
459 print self.command('\\cp -f %s %s' % (tmp_sin_agent, sin_agent))
460
461 if self.server:
462 self.autostart('sin_server')
463 # syncdb:
464 print self.command('su %s -c "python %s syncdb --noinput 2>&1"' % (self.user,
38368ee @wonlay Init nodes on zookeeper.
wonlay authored Nov 16, 2011
465 os.path.join(self.home, 'app/manage.py')))
466 print self.command('su %s -c "python %s -i 2>&1"' % (self.user,
467 os.path.join(self.home, 'app/sin_server.py')))
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
468 print self.command('%s restart' % sin_server)
469
470 self.autostart('sin_agent')
471 print self.command('%s restart' % sin_agent)
472
473 # Cleanup:
474 try: os.remove(tmpfile_local)
475 except: pass
476 try: self.sftp.remove(tmpfile)
477 except: pass
478 try: self.sftp.remove(tmp_sin_server)
479 except: pass
480 try: self.sftp.remove(tmp_sin_agent)
481 except: pass
482
483 if not self.check_sin():
484 raise Exception("sin install failed!")
485 print 'sin installed.'
486
487 def deploy(self):
38368ee @wonlay Init nodes on zookeeper.
wonlay authored Nov 16, 2011
488 if not self.base:
489 print 'Please call get_deployer() to get your deployer.'
490 sys.exit(1)
491
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
492 self.install_zkpython()
0146ad2 @wonlay setuptools are required.
wonlay authored Nov 15, 2011
493 self.install_setuptools()
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
494 self.install_django()
495 self.install_twisted()
496 self.install_cronolog()
497 self.install_pyparsing()
a0aa3cf @wonlay Cleanup sin client and add deployment script.
wonlay authored Nov 15, 2011
498 self.install_pysensei()
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
499 self.install_sin()
500
9578f8f @wonlay add deployer for systems with apt-get.
wonlay authored Jan 17, 2012
501 class DeployerWithApt(BaseDeployer):
502 def __init__(self, *args, **kwargs):
503 super(DeployerWithApt, self).__init__(*args, **kwargs)
504
505 def autostart(self, service, on=True):
506 if on:
507 print self.command('update-rc.d %s defaults' % service)
508 else:
509 print self.command('update-rc.d -f %s remove' % service)
510
511 def do_install_zkpython(self):
512 print 'Installing zkpython...'
513 self.command('apt-get -y install python-zookeeper')
514 if not self.check_zkpython():
515 raise Exception("zkpython install failed!")
516 print 'zkpython installed.'
517
518 def do_install_setuptools(self):
519 print 'Installing setuptools...'
520 print self.command('apt-get -y install python-setuptools')
521 if not self.check_setuptools():
522 raise Exception("setuptools install failed!")
523 print 'setuptools installed.'
524
525 def do_install_twisted(self):
526 print 'Installing twisted...'
527 print self.command('apt-get -y install python-twisted')
528 if not self.check_twisted():
529 raise Exception("twisted install failed!")
530 print 'twisted installed.'
531
532 def do_install_cronolog(self):
533 print 'Installing cronolog...'
534 print self.command('apt-get -y install cronolog')
535 if not self.check_cronolog():
536 raise Exception("cronolog install failed!")
537 print 'cronolog installed.'
538
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
539 class DeployerRHEL6_X86_64(BaseDeployer):
540 def __init__(self, *args, **kwargs):
541 super(DeployerRHEL6_X86_64, self).__init__(*args, **kwargs)
542
191ccae @wonlay add login and upgrade options.
wonlay authored Nov 15, 2011
543 def autostart(self, service, on=True):
544 if on:
545 print self.command('chkconfig %s on' % service)
546 else:
547 print self.command('chkconfig %s off' % service)
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
548
549 def do_install_zkpython(self):
550 print 'Installing zkpython...'
551 tmpfile = 'zkpython.tar.gz'
552 try: self.sftp.remove(tmpfile)
553 except: pass
554 self.sftp.put(os.path.join(SIN_HOME, 'lib/zk-client/linux-x86_64-2.6/zkpython.tar.gz'), tmpfile)
555 self.command('tar -C / -xzf %s' % tmpfile)
556 try: self.sftp.remove(tmpfile)
557 except: pass
558 if not self.check_zkpython():
559 raise Exception("zkpython install failed!")
560 print 'zkpython installed.'
561
0146ad2 @wonlay setuptools are required.
wonlay authored Nov 15, 2011
562 def do_install_setuptools(self):
563 print 'Installing setuptools...'
564 print self.command('yum -y install python-setuptools')
565 if not self.check_setuptools():
566 raise Exception("setuptools install failed!")
567 print 'setuptools installed.'
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
568
ff9a3ca @wonlay deploy working for the same host.
wonlay authored Nov 15, 2011
569 def do_install_twisted(self):
570 print 'Installing twisted...'
571 print self.command('yum -y install python-twisted-web')
572 if not self.check_twisted():
573 raise Exception("twisted install failed!")
574 print 'twisted installed.'
575
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
576 def do_install_cronolog(self):
577 print 'Installing cronolog...'
578 tmpfile = 'cronolog-1.6.2-10.el6.x86_64.rpm'
579 try: self.sftp.remove(tmpfile)
580 except: pass
581 self.sftp.put(os.path.join(SIN_HOME, 'lib/cronolog/%s' % tmpfile), tmpfile)
582 print self.command('rpm -i --quiet %s' % tmpfile)
583 try: self.sftp.remove(tmpfile)
584 except: pass
585 if not self.check_cronolog():
586 raise Exception("cronolog install failed!")
587 print 'cronolog installed.'
588
38368ee @wonlay Init nodes on zookeeper.
wonlay authored Nov 16, 2011
589 class DeployerDarwin_I386(BaseDeployer):
590 def __init__(self, *args, **kwargs):
591 super(DeployerDarwin_I386, self).__init__(*args, **kwargs)
592
c68e522 @wonlay detect hostname changes in settings; deploy is working on mac.
wonlay authored Dec 21, 2011
593 def autostart(self, service, on=True):
8535b4d @wonlay add launchd script.
wonlay authored Dec 21, 2011
594 sin_server = '/Library/LaunchDaemons/com.senseidb.sin_server.plist'
595 sin_agent = '/Library/LaunchDaemons/com.senseidb.sin_agent.plist'
596 if on:
597 tmp_sin_server = 'sin_server.plist'
598 tmp_sin_agent = 'sin_agent.plist'
599
600 sin_server_src = 'start_script/mac/sin_server.plist'
601 sin_agent_src = 'start_script/mac/sin_agent.plist'
602
603 # Install:
604 try: self.sftp.remove(tmp_sin_server)
605 except: pass
606 try: self.sftp.remove(tmp_sin_agent)
607 except: pass
608
609 self.sftp.put(sin_server_src, tmp_sin_server)
610 self.sftp.put(sin_agent_src, tmp_sin_agent)
611
612 print self.command('\\cp -f %s %s' % (tmp_sin_server, sin_server))
613 print self.command('\\cp -f %s %s' % (tmp_sin_agent, sin_agent))
614
615 print self.command('\\launchctl load -F %s' % sin_server)
616 print self.command('\\launchctl load -F %s' % sin_agent)
617
618 try: self.sftp.remove(tmp_sin_server)
619 except: pass
620 try: self.sftp.remove(tmp_sin_agent)
621 except: pass
622 else:
623 print self.command('\\launchctl unload -w %s' % sin_server)
624 print self.command('\\launchctl unload -w %s' % sin_agent)
625 try: self.sftp.remove(sin_server)
626 except: pass
627 try: self.sftp.remove(sin_agent)
628 except: pass
c68e522 @wonlay detect hostname changes in settings; deploy is working on mac.
wonlay authored Dec 21, 2011
629
707e4ca @wonlay dev deploy alpha for macos.
wonlay authored Nov 18, 2011
630 def do_install_zkpython(self):
631 print 'Installing zkpython...'
632 tmpfile = 'zkpython.tar.gz'
633 try: self.sftp.remove(tmpfile)
634 except: pass
635 self.sftp.put(os.path.join(SIN_HOME, 'lib/zk-client/darwin-i386-2.6/zkpython.tar.gz'), tmpfile)
636 self.command('tar -C / -xzf %s' % tmpfile)
637 try: self.sftp.remove(tmpfile)
638 except: pass
639 if not self.check_zkpython():
640 raise Exception("zkpython install failed!")
641 print 'zkpython installed.'
642
643 def do_install_cronolog(self):
644 print 'Installing cronolog...'
645 tmpfile = 'cronolog.tar.gz'
646 try: self.sftp.remove(tmpfile)
647 except: pass
648 self.sftp.put(os.path.join(SIN_HOME, 'lib/cronolog/cronolog-1.6.2.darwin.i386.tar.gz'), tmpfile)
649 self.command('tar -C / -xzf %s' % tmpfile)
650 try: self.sftp.remove(tmpfile)
651 except: pass
652 if not self.check_cronolog():
653 raise Exception("cronolog install failed!")
654 print 'cronolog installed.'
655
656 class DeployerDarwin_X86_64(DeployerDarwin_I386):
657 def __init__(self, *args, **kwargs):
658 super(DeployerDarwin_X86_64, self).__init__(*args, **kwargs)
659
660 def do_install_zkpython(self):
661 print 'Installing zkpython...'
662 tmpfile = 'zkpython.tar.gz'
663 try: self.sftp.remove(tmpfile)
664 except: pass
665 self.sftp.put(os.path.join(SIN_HOME, 'lib/zk-client/darwin-x86_64-2.6/zkpython.tar.gz'), tmpfile)
666 self.command('tar -C / -xzf %s' % tmpfile)
667 try: self.sftp.remove(tmpfile)
668 except: pass
669 if not self.check_zkpython():
670 raise Exception("zkpython install failed!")
671 print 'zkpython installed.'
672
673 def do_install_cronolog(self):
674 print 'Installing cronolog...'
675 tmpfile = 'cronolog.tar.gz'
676 try: self.sftp.remove(tmpfile)
677 except: pass
678 self.sftp.put(os.path.join(SIN_HOME, 'lib/cronolog/cronolog-1.6.2.darwin.x86_64.tar.gz'), tmpfile)
679 self.command('tar -C / -xzf %s' % tmpfile)
680 try: self.sftp.remove(tmpfile)
681 except: pass
682 if not self.check_cronolog():
683 raise Exception("cronolog install failed!")
684 print 'cronolog installed.'
685
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
686 def main(argv):
687 usage = "usage: %prog [options] <install dir>"
688 parser = OptionParser(usage=usage)
191ccae @wonlay add login and upgrade options.
wonlay authored Nov 15, 2011
689 parser.add_option("-l", "--login", type="string", dest="login", default=None, help="The login user you want to run the deployment script on each node.")
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
690 parser.add_option("-u", "--user", type="string", dest="user", default="root", help="The user sin will running as.")
191ccae @wonlay add login and upgrade options.
wonlay authored Nov 15, 2011
691 parser.add_option("-g", "--upgrade", action="store_true", dest="upgrade", help="Install or upgrade if installed.")
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
692 (options, args) = parser.parse_args()
693 if len(args) != 1:
694 parser.error("Please give me a install dir (/var/sin for example).")
695 home = args[0]
696
697 server = True
698 sin_nodes = sorted(list(settings.SIN_NODES.get('nodes', [])), key=lambda node:node['node_id'])
699 for node in sin_nodes:
38368ee @wonlay Init nodes on zookeeper.
wonlay authored Nov 16, 2011
700 deployer = BaseDeployer(
701 node['host'],
702 home,
703 node['node_id'],
704 login = options.login,
705 server = server,
706 user = options.user,
707 upgrade = options.upgrade
708 ).get_deployer()
75cee5a @wonlay First simple deploy script for el6.
wonlay authored Nov 14, 2011
709 deployer.deploy()
710 server = False
711
712 def target(*args):
713 return main, None
714
715 if __name__ == '__main__':
716 main(sys.argv)
Something went wrong with that request. Please try again.