1. 程式人生 > >Elasticsearch python 啟動指令碼

Elasticsearch python 啟動指令碼

import os
import sys

def endpcess():
    nb= os.popen("jps|grep Elasticsearch").read()
    oldid=nb.split(' ')[0]
    #print 'oldid'+oldid
    nb=os.system("kill "+oldid)
    return 'Elasticsearch is end'
def startprcess():
    os.system("su - es -c '/home/es/es/es-2.4.4/bin/elasticsearch -d'")
    #nb= os.popen("jps|grep Elasticsearch").read()
    #print 'newid'+nb.split(' ')[0]
    return 'Elasticsearch is start'

def restartprcess():
    endpcess()
    startprcess()
    return 'Elasticsearch is restart'

if __name__ =='__main__':
    try:
        name=sys.argv[1]
        if name=='-e':
            info=endpcess()
            print info
        elif name=='-s':
            info=startprcess()
            print info
        elif name=='-r':
            info=restartprcess()
            print info
        elif name=='-h':
            print 'cmd:python es.py -e  ----stop Elasticsearch service'
            print 'cmd:python es.py -s  ----start Elasticsearch service'
            print 'cmd:python es.py -r  ----restart Elasticsearch service'
            print 'cmd:python es.py -h  ----cmd help'
    except:
            print 'cmd:python es.py -e  ----stop Elasticsearch service'
            print 'cmd:python es.py -s  ----start Elasticsearch service'
            print 'cmd:python es.py -r  ----restart Elasticsearch service'
            print 'cmd:python es.py -h  ----cmd help'