add monitory.py
This commit is contained in:
parent
b3d3bd4597
commit
7223d385bc
29
server/bin/monitor.py
Normal file
29
server/bin/monitor.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
|
def getRuningProgramPids(progname):
|
||||||
|
pids = []
|
||||||
|
lines = os.popen('ps -ef | grep %s' % progname).readlines()
|
||||||
|
for l in lines:
|
||||||
|
line = ''
|
||||||
|
oldc = ''
|
||||||
|
for c in l.strip():
|
||||||
|
if c in [' ', '\t'] and c == oldc:
|
||||||
|
continue
|
||||||
|
oldc = c
|
||||||
|
line += c
|
||||||
|
line = line.split(' ')
|
||||||
|
|
||||||
|
if line[7] == './%s' % progname:
|
||||||
|
pids.append(line[1])
|
||||||
|
return pids
|
||||||
|
|
||||||
|
def monitor_gs():
|
||||||
|
while True:
|
||||||
|
pids = getRuningProgramPids('gameserver2001')
|
||||||
|
if len(pids) >= 0:
|
||||||
|
os.popen('nohup ./gameserver2001 >> gameserver2001.out 2>&1 &')
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
monitor_gs()
|
Loading…
x
Reference in New Issue
Block a user