#!/usr/bin/env python
#coding:utf-8
import os,re,sys
def numSort():
global game_gen_path,noStart,alreadyStart
alreadyStart = set()
allservice = set()
game_gen_path = '/data/bz-tw-and/'
command="ps aux | grep bz-tw-and-s | awk '{print $11}' | awk -F'/' '{print $2}' | grep -v '^$' | cut -d'-' -f 4"
service = os.popen('%s' % command,'r').readlines() #popen需要用表格式形式阅读,会有\n出现,需要strip()去除
for service in service:
service_name = service.strip().strip()[1:]
alreadyStart.add(service_name)
for qu_name in os.listdir(game_gen_path):
if re.match('s\d+',qu_name):
allservice.add(qu_name[1:])
noStart = sorted(list(map(int,alreadyStart^allservice)))
alreadyStart = sorted(list(map(int,alreadyStart)))
def outer(fun):
def wrapper():
fun()
for qu_name in qu_service:
excutePath = game_gen_path + 's' + str(qu_name) + '/bin/'
for fileName in os.listdir(excutePath):
if fileName == script:
print('##### s\033[31m%s\033[0m now %s... #####' % (qu_name,status))
os.system('sh %s' % (excutePath + fileName))
return wrapper
@outer
def start():
global qu_service,script,status
numSort()
qu_service = noStart
script = 'start.sh'
status = 'start'
@outer
def stop():
global qu_service,script,status
numSort()
qu_service = alreadyStart
script = 'stop.sh'
status = 'stop'
def status():
command = "ps aux | grep bz-tw-and-s | awk '{print $11}' | awk -F'/' '{print $2}' | grep -v '^$' | sort -t's' -k 2n | awk -F's' '{print $2}'"
service = os.popen('%s' % command, 'r').readlines()
if service == []:
print '进程已经全部关闭'
else:
for process in service:
fushu = process.strip()
print('bz-tw-and-s'+'\033[31m%s\033[0m' % fushu)
def callable(input_key):
script_name = sys.argv[0]
try:
service_option = {'start': start, 'stop': stop, 'status': status}
return service_option[input_key]()
except KeyError as e:
print e
print ('Example: %s start|stop|status' % script_name)
if __name__ == '__main__':
callable(sys.argv[1])
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
本文题目:python批量启动关闭游戏程序-创新互联
本文来源:https://www.cdcxhl.com/article26/cssojg.html
成都网站建设公司_创新互联,为您提供全网营销推广、静态网站、定制开发、软件开发、品牌网站制作、微信公众号
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联