python安装lap_一个python脚本解决安装mq的依赖问题
import tarfile
import sys,os
from _utils.patrol2 import run_cmd
import zipfile
def get_version(filename):
cmd="rpm -U {}".format(filename)
code,res=run_cmd(cmd,cwd=pkg_unzip_path)
if 'is already installed' in res or '已安裝' in res:
return True
else:
return False
def install_pkg(filename):
cmd = "yum -y localinstall {}".format(filename)
code,res=run_cmd(cmd,cwd=pkg_unzip_path)
if code:
print res
sys.exit(1)
if get_version(filename):
return True
else:
return False
def extract(tar_path, target_path):
try:
tar = tarfile.open(tar_path, "r:gz")
file_names = tar.getnames()
for file_name in file_names:
tar.extract(file_name, target_path)
tar.close()
except Exception, e:
print Exception, e
sys.exit(1)
def search(path, word):
for filename in os.listdir(path):
fp = os.path.join(path, filename)
if os.path.isfile(fp) and word in filename:
return filename
elif os.path.isdir(fp):
search(fp, word)
return False
def unpack_zip(filename, destpath, fix_path=None):
zf_obj = zipfile.ZipFile(filename)
if destpath.endswith(':'):
destpath = destpath + os.sep
zf_obj.extractall(path=destpath)
zf_obj.close()
if fix_path:
destpath = os.path.join(destpath, fix_path)
return destpath
if pkg_file.endswith('.gz'):
extract(pkg_file, pkg_unzip_path)
elif pkg_file.endswith('.zip'):
pkg_name=pkg_name.split('.zip')[0]
pkg_unzip_path=unpack_zip(pkg_file, pkg_unzip_path,fix_path=pkg_name)
print '-->解壓成功'
code,res=run_cmd('chmod 755 ./lap/jre/jre/bin/java', cwd=pkg_unzip_path)
if code:
print 'java執行權限賦權失敗',res
sys.exit(1)
else:
print 'java執行權限賦權成功'
#接受授權認證
cmd = "sh mqlicense.sh<
code,res = run_cmd(cmd,cwd=pkg_unzip_path)
if code:
print res
sys.exit(1)
else:
print res
print '-->權限認證成功'
#1、安裝系統依賴包
print '開始安裝rpm包,請等待'
names=["MQSeriesRuntime","MQSeriesSDK","MQSeriesJava","MQSeriesClient","MQSeriesSamples","MQSeriesServer"]
for name in names:
filename=search(pkg_unzip_path, name)
if not filename:
print '{}相關的包不存在'.format(name)
sys.exit(1)
elif get_version(filename):
print '{}已安裝'.format(filename)
elif filename and not get_version(filename):
res=install_pkg(filename)
if res:
print '安裝{}成功'.format(filename)
else:
print '安裝{}失敗'.format(filename)
sys.exit(1)
print '-->依賴包安裝成功'
#2、修改系統limits參數
with open('/etc/security/limits.conf','a') as f:
f.write("mqm soft nofile 10240\nmqm hard nofile 10240\nmqm soft nproc 4096\n")
print '-->修改系統limits參數成功'
#3、修改系統核心參數
with open('/etc/sysctl.conf','a') as f:
f.write("kernel.sem = 500 256000 250 1024\nfs.file-max = 524288\nnet.ipv4.tcp_keepalive_time = 300\n")
cmd = "sysctl -p"
code,res=run_cmd(cmd,cwd=pkg_unzip_path)
if 'kernel.sem = 500 256000 250 1024\nfs.file-max = 524288\nnet.ipv4.tcp_keepalive_time = 300' in res:
print '-->修改系統核心參數成功'
else:
print '-->修改系統核心參數失敗'
sys.exit(1)
總結
以上是生活随笔為你收集整理的python安装lap_一个python脚本解决安装mq的依赖问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 两个矩阵是否相交的算法_算法血拼:Goo
- 下一篇: android inset 标签,and