#!/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需要用表格式形式閱讀,會有\(zhòng)n出現(xià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 '進程已經(jīng)全部關(guān)閉'
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])
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
目前成都創(chuàng)新互聯(lián)公司已為上千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)站空間、成都網(wǎng)站托管、企業(yè)網(wǎng)站設(shè)計、廣宗網(wǎng)站維護等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。