艾辉 发表于 2018-9-19 10:38:24

自动安装与配置gitlab

#!/usr/bin/python  
#-*- coding: UTF-8 -*-
  
import commands
  
import urllib
  
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
  
#显示下载进度
  
def report(count,blockSize,totalSize):
  
    percent=int(count*blockSize*100/totalSize)
  
    if percent
页: [1]
查看完整版本: 自动安装与配置gitlab