def server_process_main()

in ambari-metrics-timelineservice/src/main/python/main.py [0: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, 0o755)

  #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