自动安装与配置gitlab
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自动安装与配置gitlab相关的知识,希望对你有一定的参考价值。
#!/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 "--------------安装完成--------------"
本文出自 “黎明前的黑暗” 博客,谢绝转载!
以上是关于自动安装与配置gitlab的主要内容,如果未能解决你的问题,请参考以下文章
gitlab-8.7.4一键自动安装以及邮件通知配置参考示例