0

摘要:我必须通过在远程服务器上运行的脚本从命令行启动各种服务,该脚本为每个服务创建子进程并以某种形式存储 PID。

我无法通过我的这个脚本让每个进程在后台运行。除了前2个,即es和redis外,其他的都在前台运行,不给终端返回给下一个命令执行。

我哪里错了?这是脚本:

import os
import sys
import commands
from var import key_loc
import subprocess
import pipes
import shlex

def check(status):
    if status != 0:
        print 'Error! '
        quit()
    else:
        print 'Success :) '
    file1=open('/home/modiuser/status.txt','a')
    file1.write("Success :)\n") 

if(sys.argv[1]=="ES"):
    os.chdir('/home/modiuser/elasticsearch-0.90.0/bin/')
    #proc1=subprocess.Popen(shlex.split("nohup ./elasticsearch -p /home/modiuser/es.pid"))
    os.system('nohup ./elasticsearch -p /home/modiuser/es.pid > /dev/null 2>&1 &')
if(sys.argv[1]=="REDIS"):
    os.chdir('/home/modiuser/redis-2.6.13/src')
    #proc2=subprocess.Popen(shlex.split("./redis_ss -p /home/modiuser/redis.pid"))
    os.system('nohup ./redis_ss -p /home/modiuser/redis.pid > /dev/null 2>&1 &')
if(sys.argv[1]=="PARSER"):
    proc3=subprocess.Popen(shlex.split("nohup java -jar logstash-1.1.12-flatjar.jar agent -f parser.conf"))
    file1=open('/home/modiuser/pid.txt','a')
    file1.write("PARSER-"+str(proc3.pid)+"\n")
    file1.close()
    os.wait(proc3.pid)
if(sys.argv[1]=="SHIPPER_TCP"):
    proc4=subprocess.Popen(shlex.split("nohup java -jar logstash-1.1.12-flatjar.jar agent -f shipper_TCP.conf"))
    file1=open('/home/modiuser/pid.txt','a')
    file1.write("SHIPPER_TCP-"+str(proc4.pid)+"\n")
    file1.close()
if(sys.argv[1]=="SHIPPER"):
    proc5=subprocess.Popen(shlex.split("nohup java -jar logstash-1.1.12-flatjar.jar agent -f shipper_test.conf"))
    file1=open('/home/modiuser/pid.txt','a')
    file1.write("SHIPPER-"+str(proc5.pid)+"\n")
    file1.close()
4

0 回答 0