Example #1
0
def run(config):
    print "command start: %s" % config
    agents = _parse_agents_from_args(config)
    agents |= _parse_agents_from_file(config)
    running_agents = []
    for ag in agents:
        ag_exec = agents_map.get(ag)
        if ag_exec:
            ag_p = subprocess.Popen(ag_exec.split(), stdout=subprocess.PIPE)
            running_agents.append(ag_p)
    time.sleep(15)
    data = []
    for ag_p in running_agents:
        # shell scripts has depend child which can't be killed by subprocess' API
        # it should be ag_p.kill()
        #os.system("pkill -P %s" % ag_p.pid)
        ag_p.send_signal(signal.SIGINT)
        stdout = ag_p.stdout.read()
        data.append(stdout)
    rets = []
    ret = db_api.result_create(data)
    rets.append(ret.uuid)
    task = db_api.task_create(rets)
    print "task: %s runs successfully!" % task.uuid
    return
Example #2
0
    def start_tracers(self, ctx, tracers):
        all_tr = self.tracer_list(ctx)
        running_tr = map(lambda t: t["name"],
                         filter(lambda t: t["running"], all_tr))
        task = db_api.task_create(results=[], pids=[])

        pids = []
        for tr in tracers:
            if tr in running_tr:
                LOG.info("%s is running, skipped" % tr)
            else:
                pid = base.run_agent(task.uuid, tr)
                LOG.debug("saving pid %s" % pid)
                self.set_tracer_pid(ctx, tr, pid)
                pids.append(pid)

        task = db_api.task_update(task.uuid, pids=pids)
        print "[LOG] task <%s> runs successfully!" % task.uuid