|
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
#!/usr/bin/python
#-*- coding: UTF-8 -*-
import commands
import urllib2
import os
import sys
import subprocess
import time
print "-----------安装gitlab程序--------------"
def exec_cmd(cmd,timeout=-1):
_p=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
if timeout >0:
timer=Timer(timeout,_p.kill)
timer.start()
_stdout,_stderr=p.communicate()
if time.is_alive:
timer.cancel()
ret={'return_code': _p.returncode,'stdout': _stdout,'stderr': _stderr}
else:
ret={'return_code': _p.returncode,'stdout': '','stderr': _stderr}
else:
_stdout, _stderr = _p.communicate()
ret={'return_code': _p.returncode,'stdout': _stdout,'stderr': _stderr}
return ret
#安装gitalb安装前的依赖软件
def install():
pakages=['openssh-server','epel-release','postfix','cronie','vim']
print "Installing pakages"
for each in pakages:
command="yum -y install %s" % each
ret=exec_cmd(command)
if ret['return_code']!=0:
print 'pakage({0}) install failed,reason:{1}'.format(each,ret['stderr'])
sys.exit(3)
else:
print 'pakage({0}) install success,'.format(each)
#做防火墙的
def command():
command='sudo lokkit -s http -s ssh'
ret=exec_cmd(command)
if ret['return_code']!=0:
print "the %s excute failed" % command
return True
#下载gitlab软件包
def download():
print "-----------------upload gitlab packages------------------!!!!"
url='http://192.168.100.127/gitlab-7.9.2_omnibus-1.el6.x86_64.rpm'
f=urllib2.urlopen(url)
data=f.read()
with open("/root/gitlab-7.9.2_omnibus-1.el6.x86_64.rpm","wb") as code:
code.write(data)
print "编译gitlab,此过程需要一段时间,请耐心等待"
command1='sudo rpm -i gitlab-7.9.2_omnibus-1.el6.x86_64.rpm'
ret1=exec_cmd(command1)
if ret1['return_code']!=0:
print "the %s excute failed" % command1
else:
print "the %s excute success" % command1
command2='gitlab-ctl reconfigure'
ret2=exec_cmd(command2)
if ret2['return_code']!=0:
print "the %s excute failed" % command2
else:
print "the %s excute success" % command2
#停掉服务,为了修改域名
command3='gitlab-ctl stop'
ret3=exec_cmd(command3)
if ret3['return_code']!=0:
print "the %s excute failed" % command3
#调用alter_host函数
alter_host()
command4='gitlab-ctl start'
ret4=exec_cmd(command4)
if ret3['return_code'] !=0:
print "the %s excute failed" % command4
return True
#修改邮箱的域名
def alter_host():
host=commands.getoutput("ifconfig eth0|grep Bcast|awk '{print $2}'|cut -d ':' -f 2")
config_file='/var/opt/gitlab/gitlab-rails/etc/gitlab.yml'
command1='sed -i "s/gitlab.example.com/{0}/g" {1} '.format(host,config_file)
ret1=exec_cmd(command1)
if ret1['return_code']!=0:
print "the % excute failed" % command1
else:
print "the command excute success"
install()
command()
download()
print "--------------安装完成--------------"
|
|
|