def Install(cls, startupMode="auto", username=None, password=None):
        print "Installing service %s" % (cls._svc_name_)

        # Configure master.xml, which drives the java subprocess32
        java_path = get_java_exe_path()
        java_args = _build_master_java_args(username)

        config_file_path = _get_config_file_path()

        xmlFileContents = _MasterXml()
        xmlFileContents.service.id = EMBEDDED_HBASE_MASTER_SERVICE
        xmlFileContents.service.name = EMBEDDED_HBASE_MASTER_SERVICE
        xmlFileContents.service.description = "This service runs " + EMBEDDED_HBASE_MASTER_SERVICE
        xmlFileContents.service.executable = java_path
        xmlFileContents.service.arguments = java_args

        xmlFile = open(config_file_path, "w")
        xmlFile.write(str(xmlFileContents))
        xmlFile.close()

        startType = cls._get_start_type(startupMode)
        serviceType = win32service.SERVICE_WIN32_OWN_PROCESS
        errorControl = win32service.SERVICE_ERROR_NORMAL

        commandLine = os.path.abspath(cls._exe_name_)
        hscm = win32service.OpenSCManager(None, None,
                                          win32service.SC_MANAGER_ALL_ACCESS)
        try:
            try:
                hs = win32service.CreateService(
                    hscm,
                    cls._svc_name_,
                    cls._svc_display_name_,
                    win32service.SERVICE_ALL_ACCESS,  # desired access
                    serviceType,  # service type
                    startType,
                    errorControl,  # error control type
                    commandLine,
                    None,
                    0,
                    None,
                    username,
                    password)
                print "Service installed"
                win32service.CloseServiceHandle(hs)
            finally:
                win32service.CloseServiceHandle(hscm)
        except win32service.error, exc:
            if exc.winerror == winerror.ERROR_SERVICE_EXISTS:
                cls.Update(username, password)
            else:
                print "Error installing service: %s (%d)" % (exc.strerror,
                                                             exc.winerror)
                err = exc.winerror
  def Install(cls, startupMode = "auto", username = None, password = None):
    print "Installing service %s" % (cls._svc_name_)

    # Configure master.xml, which drives the java subprocess
    java_path = get_java_exe_path()
    java_args = _build_master_java_args(username)

    config_file_path = _get_config_file_path()

    xmlFileContents = _MasterXml()
    xmlFileContents.service.id = EMBEDDED_HBASE_MASTER_SERVICE
    xmlFileContents.service.name = EMBEDDED_HBASE_MASTER_SERVICE
    xmlFileContents.service.description = "This service runs " + EMBEDDED_HBASE_MASTER_SERVICE
    xmlFileContents.service.executable = java_path
    xmlFileContents.service.arguments = java_args

    xmlFile = open(config_file_path, "w")
    xmlFile.write( str(xmlFileContents) )
    xmlFile.close()

    startType = cls._get_start_type(startupMode)
    serviceType = win32service.SERVICE_WIN32_OWN_PROCESS
    errorControl = win32service.SERVICE_ERROR_NORMAL

    commandLine = os.path.abspath(cls._exe_name_)
    hscm = win32service.OpenSCManager(None,None,win32service.SC_MANAGER_ALL_ACCESS)
    try:
      try:
        hs = win32service.CreateService(hscm,
                                        cls._svc_name_,
                                        cls._svc_display_name_,
                                        win32service.SERVICE_ALL_ACCESS,         # desired access
                                        serviceType,        # service type
                                        startType,
                                        errorControl,       # error control type
                                        commandLine,
                                        None,
                                        0,
                                        None,
                                        username,
                                        password)
        print "Service installed"
        win32service.CloseServiceHandle(hs)
      finally:
        win32service.CloseServiceHandle(hscm)
    except win32service.error, exc:
      if exc.winerror==winerror.ERROR_SERVICE_EXISTS:
        cls.Update(username, password)
      else:
        print "Error installing service: %s (%d)" % (exc.strerror, exc.winerror)
        err = exc.winerror
示例#3
0
def server_process_main(options, scmStatus=None):
    if scmStatus is not None:
        scmStatus.reportStartPending()

    # debug mode
    try:
        global DEBUG_MODE
        DEBUG_MODE = options.debug
    except AttributeError:
        pass

    # stop Java process at startup?
    try:
        global SUSPEND_START_MODE
        SUSPEND_START_MODE = options.suspend_start
    except AttributeError:
        pass

    #options.conf_dir <= --config
    if not os.path.isdir(options.conf_dir):
        err = 'ERROR: Cannot find configuration directory "{0}"'.format(
            options.conf_dir)
        raise FatalException(1, err)

    #execute ams-env.cmd
    exec_ams_env_cmd(options)

    #Ensure the 3 Hadoop services required are started on the local machine
    if not options.no_embedded_hbase:
        from amc_service import ensure_hadoop_service_soft_dependencies
        ensure_hadoop_service_soft_dependencies()

    if scmStatus is not None:
        scmStatus.reportStartPending()

    java_exe = get_java_exe_path()
    java_class_path = get_java_cp()
    java_heap_max = build_jvm_args()
    command_base = SERVER_START_CMD_DEBUG if (
        DEBUG_MODE or SERVER_START_DEBUG) else SERVER_START_CMD
    suspend_mode = 'y' if SUSPEND_START_MODE else 'n'
    command = command_base.format(java_class_path, java_heap_max, suspend_mode)
    if not os.path.exists(PID_DIR):
        os.makedirs(PID_DIR, 0755)

    #Ignore the requirement to run as root. In Windows, by default the child process inherits the security context
    # and the environment from the parent process.
    param_list = java_exe + " " + command

    print_info_msg("Running server: " + str(param_list))
    procJava = subprocess32.Popen(param_list, env=os.environ)

    #wait for server process for SERVER_START_TIMEOUT seconds
    print "Waiting for server start..."

    pidJava = procJava.pid
    if pidJava <= 0:
        procJava.terminate()
        exitcode = procJava.returncode
        save_pid(exitcode, EXITCODE_OUT_FILE)

        if scmStatus is not None:
            scmStatus.reportStopPending()

        raise FatalException(-1, AMC_DIE_MSG.format(exitcode, SERVER_OUT_FILE))
    else:
        save_pid(pidJava, PID_OUT_FILE)
        print "Server PID at: " + PID_OUT_FILE
        print "Server out at: " + SERVER_OUT_FILE
        print "Server log at: " + SERVER_LOG_FILE

    if scmStatus is not None:
        scmStatus.reportStarted()

    return procJava
示例#4
0
def server_process_main(options, scmStatus=None):
  if scmStatus is not None:
    scmStatus.reportStartPending()

  # debug mode
  try:
    global DEBUG_MODE
    DEBUG_MODE = options.debug
  except AttributeError:
    pass

  # stop Java process at startup?
  try:
    global SUSPEND_START_MODE
    SUSPEND_START_MODE = options.suspend_start
  except AttributeError:
    pass

  #options.conf_dir <= --config
  if not os.path.isdir(options.conf_dir):
    err = 'ERROR: Cannot find configuration directory "{0}"'.format(options.conf_dir)
    raise FatalException(1, err)

  #execute ams-env.cmd
  exec_ams_env_cmd(options)

  #Ensure the 3 Hadoop services required are started on the local machine
  if not options.no_embedded_hbase:
    from amc_service import ensure_hdp_service_soft_dependencies
    ensure_hdp_service_soft_dependencies()

  if scmStatus is not None:
    scmStatus.reportStartPending()

  java_exe = get_java_exe_path()
  java_class_path = get_java_cp()
  java_heap_max = build_jvm_args()
  command_base = SERVER_START_CMD_DEBUG if (DEBUG_MODE or SERVER_START_DEBUG) else SERVER_START_CMD
  suspend_mode = 'y' if SUSPEND_START_MODE else 'n'
  command = command_base.format(java_class_path, java_heap_max, suspend_mode)
  if not os.path.exists(PID_DIR):
    os.makedirs(PID_DIR, 0755)

  #Ignore the requirement to run as root. In Windows, by default the child process inherits the security context
  # and the environment from the parent process.
  param_list = java_exe + " " + command

  print_info_msg("Running server: " + str(param_list))
  procJava = subprocess.Popen(param_list, env=os.environ)

  #wait for server process for SERVER_START_TIMEOUT seconds
  print "Waiting for server start..."

  pidJava = procJava.pid
  if pidJava <= 0:
    procJava.terminate()
    exitcode = procJava.returncode
    save_pid(exitcode, EXITCODE_OUT_FILE)

    if scmStatus is not None:
      scmStatus.reportStopPending()

    raise FatalException(-1, AMC_DIE_MSG.format(exitcode, SERVER_OUT_FILE))
  else:
    save_pid(pidJava, PID_OUT_FILE)
    print "Server PID at: " + PID_OUT_FILE
    print "Server out at: " + SERVER_OUT_FILE
    print "Server log at: " + SERVER_LOG_FILE

  if scmStatus is not None:
    scmStatus.reportStarted()

  return procJava