Пример #1
0
    def SvcDoRun(self):
        from ambari_server_main import server_process_main

        scmStatus = SvcStatusCallback(self)

        properties = get_ambari_properties()
        self.options.verbose = get_value_from_properties(
            properties, VERBOSE_OUTPUT_KEY, False)
        self.options.debug = get_value_from_properties(properties,
                                                       DEBUG_MODE_KEY, False)
        self.options.suspend_start = get_value_from_properties(
            properties, SUSPEND_START_MODE_KEY, False)

        # set verbose
        set_verbose(self.options.verbose)

        self.redirect_output_streams()

        childProc = server_process_main(self.options, scmStatus)

        if not self._StopOrWaitForChildProcessToFinish(childProc):
            return

        pid_file_path = os.path.join(configDefaults.PID_DIR, PID_NAME)
        remove_file(pid_file_path)
        pass
Пример #2
0
def server_process_main(stop_handler, scmStatus=None):
  if scmStatus is not None:
    scmStatus.reportStartPending()

  _init_logging(main_config)
  controller = Controller(main_config, stop_handler)

  logger.info('Starting Server RPC Thread: %s' % ' '.join(sys.argv))
  controller.start()

  print "Server out at: " + main_config.ams_monitor_out_file()
  print "Server log at: " + main_config.ams_monitor_log_file()

  save_pid(os.getpid(), PID_OUT_FILE)

  if scmStatus is not None:
    scmStatus.reportStarted()

  # For some reason this is needed to catch system signals like SIGTERM
  # TODO fix if possible
  signal.pause()

  #The controller thread finishes when the stop event is signaled
  controller.join()

  remove_file(PID_OUT_FILE)
  pass
Пример #3
0
def archive_dir_via_temp_file(archive, directory):
  _, temp_output = tempfile.mkstemp()
  try:
    archive_directory_dereference(temp_output, directory)
  except:
    os_utils.remove_file(temp_output)
    raise
  else:
    Execute(("mv", temp_output, archive))
Пример #4
0
def start(options):
  AMCollectorService.set_ctrl_c_handler(ctrlHandler)

  if options.is_process:
    #Run as a normal process. Invoke the ServiceMain directly.
    childProc = server_process_main(options)

    childProc.wait()

    remove_file(PID_OUT_FILE)
  else:
    AMCollectorService.Start()
Пример #5
0
def start(options):
    AMCollectorService.set_ctrl_c_handler(ctrlHandler)

    if options.is_process:
        #Run as a normal process. Invoke the ServiceMain directly.
        childProc = server_process_main(options)

        childProc.wait()

        remove_file(PID_OUT_FILE)
    else:
        AMCollectorService.Start()
Пример #6
0
  def SvcDoRun(self):
    scmStatus = SvcStatusCallback(self)

    properties = get_properties()
    self.options.debug = get_value_from_properties(properties, DEBUG_MODE_KEY, self.options.debug)
    self.options.suspend_start = get_value_from_properties(properties, SUSPEND_START_MODE_KEY, self.options.suspend_start)

    self.redirect_output_streams()

    childProc = server_process_main(self.options, scmStatus)

    if not self._StopOrWaitForChildProcessToFinish(childProc):
      return

    remove_file(PID_OUT_FILE)
    pass
Пример #7
0
def start(options):
    from ambari_windows_service import AmbariServerService, ctrlHandler

    status, pid = is_server_runing()
    if status:
        err = "Ambari Server is already running."
        raise FatalException(1, err)

    AmbariServerService.set_ctrl_c_handler(ctrlHandler)

    #Run as a normal process. Invoke the ServiceMain directly.
    childProc = server_process_main(options)

    childProc.wait()

    pid_file_path = os.path.join(configDefaults.PID_DIR, PID_NAME)
    remove_file(pid_file_path)
Пример #8
0
def start(options):
  from ambari_windows_service import AmbariServerService, ctrlHandler

  status, pid = is_server_runing()
  if status:
    err = "Ambari Server is already running."
    raise FatalException(1, err)

  AmbariServerService.set_ctrl_c_handler(ctrlHandler)

  #Run as a normal process. Invoke the ServiceMain directly.
  childProc = server_process_main(options)

  childProc.wait()

  pid_file_path = os.path.join(configDefaults.PID_DIR, PID_NAME)
  remove_file(pid_file_path)
 def _setup_local_database(self):
   print 'Checking PostgreSQL...'
   (pg_status, retcode, out, err) = PGConfig._check_postgre_up()
   if not retcode == 0:
     err = 'Unable to start PostgreSQL server. Exiting'
     raise FatalException(retcode, err)
   print 'Configuring local database...'
   retcode, out, err = self._setup_db()
   if not retcode == 0:
     err = 'Running database init script failed. Exiting.'
     raise FatalException(retcode, err)
   if self._is_user_changed:
     #remove backup for pg_hba in order to reconfigure postgres
     remove_file(PGConfig.PG_HBA_CONF_FILE_BACKUP)
   print 'Configuring PostgreSQL...'
   retcode, out, err = self._configure_postgres()
   if not retcode == 0:
     err = 'Unable to configure PostgreSQL server. Exiting'
     raise FatalException(retcode, err)
Пример #10
0
    def SvcDoRun(self):
        scmStatus = SvcStatusCallback(self)

        properties = get_properties()
        self.options.debug = get_value_from_properties(properties,
                                                       DEBUG_MODE_KEY,
                                                       self.options.debug)
        self.options.suspend_start = get_value_from_properties(
            properties, SUSPEND_START_MODE_KEY, self.options.suspend_start)

        self.redirect_output_streams()

        childProc = server_process_main(self.options, scmStatus)

        if not self._StopOrWaitForChildProcessToFinish(childProc):
            return

        remove_file(PID_OUT_FILE)
        pass
Пример #11
0
 def _setup_local_database(self):
   print 'Checking PostgreSQL...'
   (pg_status, retcode, out, err) = PGConfig._check_postgre_up()
   if not retcode == 0:
     err = 'Unable to start PostgreSQL server. Exiting'
     raise FatalException(retcode, err)
   print 'Configuring local database...'
   retcode, out, err = self._setup_db()
   if not retcode == 0:
     err = 'Running database init script failed. Exiting.'
     raise FatalException(retcode, err)
   if self._is_user_changed:
     #remove backup for pg_hba in order to reconfigure postgres
     remove_file(PGConfig.PG_HBA_CONF_FILE_BACKUP)
   print 'Configuring PostgreSQL...'
   retcode, out, err = self._configure_postgres()
   if not retcode == 0:
     err = 'Unable to configure PostgreSQL server. Exiting'
     raise FatalException(retcode, err)
Пример #12
0
  def delete_keytab_file(self):
    import params

    if params.kerberos_command_params is not None:
      for item in params.kerberos_command_params:
        keytab_file_path = get_property_value(item, 'keytab_file_path')
        if (keytab_file_path is not None) and (len(keytab_file_path) > 0):
          print 'Removing keytab file, ', keytab_file_path, "\n"
          remove_file(keytab_file_path)

          principal = get_property_value(item, 'principal')
          if principal is not None:
            curr_content = Script.structuredOut

            if "keytabs" not in curr_content:
              curr_content['keytabs'] = {}

            curr_content['keytabs'][principal.replace("_HOST", params.hostname)] = '_REMOVED_'

            self.put_structured_out(curr_content)
Пример #13
0
    def delete_keytab_file(self):
        import params

        if params.kerberos_command_params is not None:
            for item in params.kerberos_command_params:
                keytab_file_path = get_property_value(item, 'keytab_file_path')
                if (keytab_file_path
                        is not None) and (len(keytab_file_path) > 0):
                    print 'Removing keytab file, ', keytab_file_path, "\n"
                    remove_file(keytab_file_path)

                    principal = get_property_value(item, 'principal')
                    if principal is not None:
                        curr_content = Script.structuredOut

                        if "keytabs" not in curr_content:
                            curr_content['keytabs'] = {}

                        curr_content['keytabs'][principal.replace(
                            "_HOST", params.hostname)] = '_REMOVED_'

                        self.put_structured_out(curr_content)
  def SvcDoRun(self):
    from ambari_server_main import server_process_main

    scmStatus = SvcStatusCallback(self)

    properties = get_ambari_properties()
    self.options.verbose = get_value_from_properties(properties, VERBOSE_OUTPUT_KEY, False)
    self.options.debug = get_value_from_properties(properties, DEBUG_MODE_KEY, False)
    self.options.suspend_start = get_value_from_properties(properties, SUSPEND_START_MODE_KEY, False)

    # set verbose
    set_verbose(self.options.verbose)

    self.redirect_output_streams()

    childProc = server_process_main(self.options, scmStatus)

    if not self._StopOrWaitForChildProcessToFinish(childProc):
      return

    pid_file_path = os.path.join(configDefaults.PID_DIR, PID_NAME)
    remove_file(pid_file_path)
    pass
Пример #15
0
def server_process_main(stop_handler, scmStatus=None):
    if scmStatus is not None:
        scmStatus.reportStartPending()

    config = Configuration()
    _init_logging(config)
    controller = Controller(config, stop_handler)

    logger.info("Starting Server RPC Thread: %s" % " ".join(sys.argv))
    controller.start()

    print "Server out at: " + SERVER_OUT_FILE
    print "Server log at: " + SERVER_LOG_FILE

    save_pid(os.getpid(), PID_OUT_FILE)

    if scmStatus is not None:
        scmStatus.reportStarted()

    # The controller thread finishes when the stop event is signaled
    controller.join()

    remove_file(PID_OUT_FILE)
    pass
Пример #16
0
def server_process_main(stop_handler, scmStatus=None):
    if scmStatus is not None:
        scmStatus.reportStartPending()

    save_pid(os.getpid(), PID_OUT_FILE)

    config = Configuration()
    _init_logging(config)
    controller = Controller(config, stop_handler)

    logger.info('Starting Server RPC Thread: %s' % ' '.join(sys.argv))
    controller.start()

    print "Server out at: " + SERVER_OUT_FILE
    print "Server log at: " + SERVER_LOG_FILE

    if scmStatus is not None:
        scmStatus.reportStarted()

    #The controller thread finishes when the stop event is signaled
    controller.join()

    remove_file(PID_OUT_FILE)
    pass
Пример #17
0
def import_cert_and_key(security_server_keys_dir):
  import_cert_path = get_validated_filepath_input( \
      "Enter path to Certificate: ", \
      "Certificate not found")
  import_key_path  =  get_validated_filepath_input( \
      "Enter path to Private Key: ", "Private Key not found")
  pem_password = get_validated_string_input("Please enter password for Private Key: ", "", None, None, True)

  certInfoDict = get_cert_info(import_cert_path)

  if not certInfoDict:
    print_warning_msg('Unable to get Certificate information')
  else:
    #Validate common name of certificate
    if not is_valid_cert_host(certInfoDict):
      print_warning_msg('Unable to validate Certificate hostname')

    #Validate issue and expirations dates of certificate
    if not is_valid_cert_exp(certInfoDict):
      print_warning_msg('Unable to validate Certificate issue and expiration dates')

  #jetty requires private key files with non-empty key passwords
  retcode = 0
  err = ''
  if not pem_password:
    print 'Generating random password for HTTPS keystore...done.'
    pem_password = generate_random_string()
    retcode, out, err = run_os_command(CHANGE_KEY_PWD_CND.format(
        import_key_path, pem_password))
    import_key_path += '.secured'

  if retcode == 0:
    keystoreFilePath = os.path.join(security_server_keys_dir, \
                                    SSL_KEYSTORE_FILE_NAME)
    keystoreFilePathTmp = os.path.join(tempfile.gettempdir(), \
                                       SSL_KEYSTORE_FILE_NAME)
    passFilePath = os.path.join(security_server_keys_dir, \
                                SSL_KEY_PASSWORD_FILE_NAME)
    passFilePathTmp = os.path.join(tempfile.gettempdir(), \
                                   SSL_KEY_PASSWORD_FILE_NAME)
    passinFilePath = os.path.join(tempfile.gettempdir(), \
                                  SSL_PASSIN_FILE)
    passwordFilePath = os.path.join(tempfile.gettempdir(), \
                                    SSL_PASSWORD_FILE)

    with open(passFilePathTmp, 'w+') as passFile:
      passFile.write(pem_password)
      passFile.close
      pass

    set_file_permissions(passFilePath, "660", read_ambari_user(), False)

    copy_file(passFilePathTmp, passinFilePath)
    copy_file(passFilePathTmp, passwordFilePath)

    retcode, out, err = run_os_command(EXPRT_KSTR_CMD.format(import_cert_path, \
                                                             import_key_path, passwordFilePath, passinFilePath, keystoreFilePathTmp))
  if retcode == 0:
    print 'Importing and saving Certificate...done.'
    import_file_to_keystore(keystoreFilePathTmp, keystoreFilePath)
    import_file_to_keystore(passFilePathTmp, passFilePath)

    import_file_to_keystore(import_cert_path, os.path.join( \
        security_server_keys_dir, SSL_CERT_FILE_NAME))
    import_file_to_keystore(import_key_path, os.path.join( \
        security_server_keys_dir, SSL_KEY_FILE_NAME))

    #Validate keystore
    retcode, out, err = run_os_command(VALIDATE_KEYSTORE_CMD.format(keystoreFilePath, \
                                                                    passwordFilePath, passinFilePath))

    remove_file(passinFilePath)
    remove_file(passwordFilePath)

    if not retcode == 0:
      print 'Error during keystore validation occured!:'
      print err
      return False

    return True
  else:
    print_error_msg('Could not import Certificate and Private Key.')
    print 'SSL error on exporting keystore: ' + err.rstrip() + \
        '.\nPlease ensure that provided Private Key password is correct and ' + \
        're-import Certificate.'

    return False
Пример #18
0
def import_cert_and_key(security_server_keys_dir):
    import_cert_path = get_validated_filepath_input( \
        "Enter path to Certificate: ", \
        "Certificate not found")
    import_key_path  =  get_validated_filepath_input( \
        "Enter path to Private Key: ", "Private Key not found")
    pem_password = get_validated_string_input(
        "Please enter password for Private Key: ", "", None, None, True)

    certInfoDict = get_cert_info(import_cert_path)

    if not certInfoDict:
        print_warning_msg('Unable to get Certificate information')
    else:
        #Validate common name of certificate
        if not is_valid_cert_host(certInfoDict):
            print_warning_msg('Unable to validate Certificate hostname')

        #Validate issue and expirations dates of certificate
        if not is_valid_cert_exp(certInfoDict):
            print_warning_msg(
                'Unable to validate Certificate issue and expiration dates')

    #jetty requires private key files with non-empty key passwords
    retcode = 0
    err = ''
    if not pem_password:
        print 'Generating random password for HTTPS keystore...done.'
        pem_password = generate_random_string()
        retcode, out, err = run_os_command(
            CHANGE_KEY_PWD_CND.format(import_key_path, pem_password))
        import_key_path += '.secured'

    if retcode == 0:
        keystoreFilePath = os.path.join(security_server_keys_dir, \
                                        SSL_KEYSTORE_FILE_NAME)
        keystoreFilePathTmp = os.path.join(tempfile.gettempdir(), \
                                           SSL_KEYSTORE_FILE_NAME)
        passFilePath = os.path.join(security_server_keys_dir, \
                                    SSL_KEY_PASSWORD_FILE_NAME)
        passFilePathTmp = os.path.join(tempfile.gettempdir(), \
                                       SSL_KEY_PASSWORD_FILE_NAME)
        passinFilePath = os.path.join(tempfile.gettempdir(), \
                                      SSL_PASSIN_FILE)
        passwordFilePath = os.path.join(tempfile.gettempdir(), \
                                        SSL_PASSWORD_FILE)

        with open(passFilePathTmp, 'w+') as passFile:
            passFile.write(pem_password)
            passFile.close
            pass

        set_file_permissions(passFilePath, "660", read_ambari_user(), False)

        copy_file(passFilePathTmp, passinFilePath)
        copy_file(passFilePathTmp, passwordFilePath)

        retcode, out, err = run_os_command(EXPRT_KSTR_CMD.format(import_cert_path, \
                                                                 import_key_path, passwordFilePath, passinFilePath, keystoreFilePathTmp))
    if retcode == 0:
        print 'Importing and saving Certificate...done.'
        import_file_to_keystore(keystoreFilePathTmp, keystoreFilePath)
        import_file_to_keystore(passFilePathTmp, passFilePath)

        import_file_to_keystore(import_cert_path, os.path.join( \
            security_server_keys_dir, SSL_CERT_FILE_NAME))
        import_file_to_keystore(import_key_path, os.path.join( \
            security_server_keys_dir, SSL_KEY_FILE_NAME))

        #Validate keystore
        retcode, out, err = run_os_command(VALIDATE_KEYSTORE_CMD.format(keystoreFilePath, \
                                                                        passwordFilePath, passinFilePath))

        remove_file(passinFilePath)
        remove_file(passwordFilePath)

        if not retcode == 0:
            print 'Error during keystore validation occured!:'
            print err
            return False

        return True
    else:
        print_error_msg('Could not import Certificate and Private Key.')
        print 'SSL error on exporting keystore: ' + err.rstrip() + \
            '.\nPlease ensure that provided Private Key password is correct and ' + \
            're-import Certificate.'

        return False