python 中tar打包

本文介绍了一个具体的Node.js应用程序的部署过程,包括停止旧服务、删除原有安装目录、打包新版本并将其复制到指定目录、最后启动新服务等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


for file in files:
if not os.path.isfile(temp+"/"+file):
print (temp+"/"+file)
shutil.copyfile(root+"/"+file,temp+"/"+file)
filePath=fileDir+tarRealName
#停止安装目录下的node.js 进程
commend = nodeCommend %("stop",projectName+"*",projectName+"*",projectName+"*",projectName+"*")
print "停止安装目录下的node.js 进程"
print commend
os.system(commend)
print "结束关闭服务命令"
time.sleep(5)
# for root, dir, files in os.walk(install_home):
# if projectName in root:
# print root
# shutil.rmtree(root)
# for file in files:
# if projectName in file:
# os.remove(root + file)
#删除旧的安装目录和tar.gz包
print "删除旧的安装目录"
commend = "rm -fr %s%s" %(install_home,projectName+"*")
time.sleep(5)
print commend
os.system(commend)
shutil.copytree(filePath,install_home+tarRealName)
time.sleep(10)


tarName = tarRealName + ".tar.gz"
tar = tarfile.open(fileDir+tarName,"w:gz")
for root,dir,files in os.walk(filePath):
kk = root.replace(fileDir,"")+"/"
for file in files:
fullpath = os.path.join(root,file)
#,arcname=file
tar.add(fullpath,arcname=kk+file)
tar.close()
# 复制tar.gz包到download_dir目录
os.makedirs(download_dir);
msg = "复制到下载目录:"+download_dir;
print msg
shutil.copyfile(fileDir+ tarName, download_dir + "/" + tarName)
#执行启动命令
# startcommend = "forever start --minUptime 1000 --spinSleepTime 1000 -l /home/appuser/app/%s/app.js"
# startcommend = startcommend %(tarRealName,tarRealName,tarRealName,tarRealName)
print "执行启动命令"
print 'sh -x /home/jenkins/resin_jenkins/install/data_collect_init.sh start'
os.system('sh -x /home/jenkins/resin_jenkins/install/data_collect_init.sh start')
print "执行启动命令完成"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值