1
This commit is contained in:
parent
4499be6acd
commit
1680f0d93b
70
scripts/publish_java/manage.py
Normal file → Executable file
70
scripts/publish_java/manage.py
Normal file → Executable file
@ -0,0 +1,70 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
#coding utf8
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
def getRuningProgramPids(jar_name):
|
||||||
|
pids = []
|
||||||
|
lines = os.popen('ps -ef |grep java|grep %s' % jar_name).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' % jar_name:
|
||||||
|
pids.append(line[1])
|
||||||
|
return pids
|
||||||
|
|
||||||
|
def getExePath(pid):
|
||||||
|
return os.popen('ls -l /proc/%d | grep "exe ->" | cut -d " " -f 7-' % int(pid)).read()
|
||||||
|
|
||||||
|
def getExeCmdLine(pid):
|
||||||
|
return os.popen('cat /proc/%d/cmdline' % int(pid)).read()
|
||||||
|
|
||||||
|
def stop(instance_id, jar_name):
|
||||||
|
pids = getRuningProgramPids(jar_name)
|
||||||
|
for pid in pids:
|
||||||
|
exepath = getExePath(pid)
|
||||||
|
cmdline = getExeCmdLine(pid)
|
||||||
|
if cmdline == ("./%s\0-i\0%d\0-n\0%d\0" % (jar_name, instance_id, node_id)):
|
||||||
|
os.popen('kill -9 %d' % int(pid))
|
||||||
|
|
||||||
|
def listServer(jar_name):
|
||||||
|
pids = getRuningProgramPids(jar_name)
|
||||||
|
for pid in pids:
|
||||||
|
exepath = getExePath(pid)
|
||||||
|
cmdline = getExeCmdLine(pid)
|
||||||
|
print(pid, exepath, cmdline)
|
||||||
|
|
||||||
|
def restartServer(str_instance_ids, jar_name):
|
||||||
|
instance_ids = str_instance_ids.split(',')
|
||||||
|
for instance_id in instance_ids:
|
||||||
|
instance_id = int(instance_id)
|
||||||
|
stop(instance_id, jar_name)
|
||||||
|
time.sleep(0.5)
|
||||||
|
print('%s %d starting......' % (jar_name, instance_id))
|
||||||
|
cmd = 'sh start_instance.sh %d %d' % (instance_id)
|
||||||
|
os.popen(cmd)
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
def printHelp():
|
||||||
|
print('usuage: [restart stop list]')
|
||||||
|
|
||||||
|
def main(argv):
|
||||||
|
if len(argv) == 1:
|
||||||
|
printHelp()
|
||||||
|
else:
|
||||||
|
if argv[1] == 'restart':
|
||||||
|
restartServer(argv[2], argv[3])
|
||||||
|
elif argv[1] == 'list':
|
||||||
|
listServer(argv[2])
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main(sys.argv)
|
@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
source ./common.sh
|
source ./common.sh
|
||||||
|
|
||||||
python manage.py restart $1 $2 ${JAR_NAME}
|
python manage.py restart $1 ${JAR_NAME}
|
||||||
|
|
||||||
echo 'success'
|
echo 'success'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user