Exemplo n.º 1
0
    def start_process(plugin, notify=True):

        id = plugin.get("config", "plugin_id")
        process = plugin.get("config", "process")
        process_aux = plugin.get("config", "process_aux")
        name = plugin.get("config", "name")
        command = plugin.get("config", "startup")

        # start service
        if command:
            logger.info("Starting service %s (%s): %s.." % (id, name, command))
            task = Task(command)
            task.Run(1, 0)
            timeout = 300
            start = datetime.now()
            plugin.start_time = float(time.time())

            while not task.Done():
                time.sleep(0.1)
                now = datetime.now()

                if (now - start).seconds > timeout:
                    task.Kill()
                    logger.warning(
                        "Could not start %s, returning after %s second(s) wait time."
                        % (command, timeout))

        # notify result to server
        if notify:

            if not process:
                logger.debug("plugin (%s) has an unknown state" % (name))
                Output.plugin_state(Watchdog.PLUGIN_UNKNOWN_STATE_MSG % (id))

            elif Watchdog.pidof(process, process_aux) is not None:
                logger.info(WATCHDOG_PROCESS_STARTED % (process, id))
                Output.plugin_state(Watchdog.PLUGIN_START_STATE_MSG % (id))
                for pid in Watchdog.__pluginID_stoppedByServer:
                    if pid == id:
                        Watchdog.__pluginID_stoppedByServer.remove(id)
                        break

            else:
                logger.warning(WATCHDOG_ERROR_STARTING_PROCESS % (process, id))
Exemplo n.º 2
0
    suitefile = sys.argv[1]
    caserange = sys.argv[2]
    args = sys.argv[3:]
    print('suitefile:', suitefile)
    print('caserange:', caserange)
    print('args:', args)
    try:
        args = ' '.join(sys.argv[3:])
    except:
        pass
    #tcpport=50009
    #svr = CServer('localhost', tcpport,'Task', 'Task',{}, 'IsAlive')
    #t = svr.Handler
    t = Task()
    #args = ' '.join(args)
    t.LoadFile(suitefile, caserange, args)
    print('start..............')
    #t.Load(suitfile)#'CaseListFile'
    t.Run()
    #print(cmd2('localhost', tcpport, ['Load', 'CaseListFile']))
    #print(cmd2('localhost', tcpport, ['Run']))
    import time
    time.sleep(5)
    #print(cmd2('localhost', tcpport, ['CancelTask', True]))
    import time
    #while svr.IsHandlerAlive():

    #    time.sleep(1)
    #svr.StopServer()
    print('end..............')