Exemplo n.º 1
0
def create(request_info):
    if 'program_name' not in request_info:
        raise exceptions.LackParamException("请求参数缺少program_name")
    if 'command' not in request_info:
        raise exceptions.LackParamException("请求参数缺少command")
    program_name = request_info['program_name']
    command = request_info['command']
    directory = request_info.get('directory')
    environment = request_info.get('environment')
    auto_start = request_info.get('auto_start', True)
    auto_restart = request_info.get('auto_restart', True)
    touch_timeout = request_info.get('touch_timeout', 10 * 365 * 24 * 3600)
    max_fail_count = request_info.get('max_fail_count', 1)
    stdout_logfile = request_info.get('stdout_logfile', '')
    stderr_logfile = request_info.get('stderr_logfile', '')
    machines = request_info.get('machines', "localhost")
    if not machines:
        raise exceptions.ParamValueException("machines不能为空")
    if not command:
        raise exceptions.ParamValueException("command不能为空")
    if not program_name:
        raise exceptions.ParamValueException("program_name不能为空")

    program_id = tools.gen_uuid()
    logger.info(program_id)
    program = create_process(program_id, program_name, command, machines,
                             directory, environment, auto_start, auto_restart,
                             touch_timeout, max_fail_count, stdout_logfile,
                             stderr_logfile)
    logger.info(program.id)

    if program.auto_start:
        start_process(program.id)

    return {"program_id": program.id}
Exemplo n.º 2
0
def _status(request_info):
    if 'program_id' not in request_info:
        raise exceptions.LackParamException("请求参数缺少program_id")

    program_id = request_info['program_id']
    status = get_status(program_id)

    return {"status": status}
Exemplo n.º 3
0
def stop(request_info):
    if 'program_id' not in request_info:
        raise exceptions.LackParamException("请求参数缺少program_id")

    program_id = request_info['program_id']
    local_stop(program_id)

    return {}
Exemplo n.º 4
0
def start(request_info):
    if 'program_id' not in request_info:
        raise exceptions.LackParamException("请求参数缺少program_id")

    program_id = request_info['program_id']
    pid = local_start(program_id)

    return {"pid": pid}
Exemplo n.º 5
0
def stop(request_info):
    program_id = request_info.get('program_id')
    program_name = request_info.get('program_name')

    if program_id is None and program_name is None:
        raise exceptions.LackParamException("参数program_id和program_name至少存在一个")

    program = operate.get_program(program_id=program_id,
                                  program_name=program_name)

    return {"program_id": stop_process(program.id)}
Exemplo n.º 6
0
def restart(request_info):
    program_id = request_info.get('program_id')
    program_name = request_info.get('program_name')

    if program_id is None and program_name is None:
        raise exceptions.LackParamException("参数program_id和program_name至少存在一个")

    program = operate.get_program(program_id=program_id,
                                  program_name=program_name)
    if program.status in CAN_STOP_STATUS:
        stop_process(program.id) and start_process(program.id)
    elif program.status in CAN_START_STATUS:
        start_process(program.id)
    else:
        raise exceptions.RestartException()

    return {"program_id": program.id}