def run_schema_upgrade(args): db_title = get_db_type(get_ambari_properties()).title confirm = get_YN_input( "Ambari Server configured for %s. Confirm " "you have made a backup of the Ambari Server database [y/n] (y)? " % db_title, True) if not confirm: print_error_msg("Database backup is not confirmed") return 1 jdk_path = get_java_exe_path() if jdk_path is None: print_error_msg( "No JDK found, please run the \"setup\" " "command to install a JDK automatically or install any " "JDK manually to " + configDefaults.JDK_INSTALL_DIR) return 1 ensure_jdbc_driver_is_installed(args, get_ambari_properties()) print_info_msg('Upgrading database schema', True) serverClassPath = ServerClassPath(get_ambari_properties(), args) class_path = serverClassPath.get_full_ambari_classpath_escaped_for_shell( validate_classpath=True) set_debug_mode_from_options(args) debug_mode = get_debug_mode() debug_start = (debug_mode & 1) or SCHEMA_UPGRADE_DEBUG suspend_start = (debug_mode & 2) or SUSPEND_START_MODE suspend_mode = 'y' if suspend_start else 'n' command = SCHEMA_UPGRADE_HELPER_CMD_DEBUG.format( jdk_path, class_path, suspend_mode) if debug_start else SCHEMA_UPGRADE_HELPER_CMD.format( jdk_path, class_path) ambari_user = read_ambari_user() current_user = ensure_can_start_under_current_user(ambari_user) environ = generate_env(args, ambari_user, current_user) (retcode, stdout, stderr) = run_os_command(command, env=environ) print_info_msg( "Return code from schema upgrade command, retcode = {0}".format( str(retcode)), True) if stdout: print_info_msg("Console output from schema upgrade command:", True) print_info_msg(stdout, True) print if retcode > 0: print_error_msg( "Error executing schema upgrade, please check the server logs.") if stderr: print_error_msg("Error output from schema upgrade command:") print_error_msg(stderr) print else: print_info_msg('Schema upgrade completed', True) return retcode
def server_process_main(options, scmStatus=None): # debug mode, including stop Java process at startup try: set_debug_mode_from_options(options) except AttributeError: pass if not check_reverse_lookup(): print_warning_msg( "The hostname was not found in the reverse DNS lookup. " "This may result in incorrect behavior. " "Please check the DNS setup and fix the issue.") check_database_name_property() parse_properties_file(options) is_active_instance = get_is_active_instance() if not is_active_instance: print_warning_msg( "This instance of ambari server is not designated as active. Cannot start ambari server." ) err = "This is not an active instance. Shutting down..." raise FatalException(1, err) ambari_user = read_ambari_user() current_user = ensure_can_start_under_current_user(ambari_user) print_info_msg("Ambari Server is not running...") jdk_path = find_jdk() if jdk_path is None: err = "No JDK found, please run the \"ambari-server setup\" " \ "command to install a JDK automatically or install any " \ "JDK manually to " + configDefaults.JDK_INSTALL_DIR raise FatalException(1, err) properties = get_ambari_properties() if not options.skip_properties_validation: missing_properties = get_missing_properties(properties) if missing_properties: err = "Required properties are not found: " + str(missing_properties) + ". To skip properties validation " \ "use \"--skip-properties-validation\"" raise FatalException(1, err) # Preparations if is_root(): print configDefaults.MESSAGE_SERVER_RUNNING_AS_ROOT ensure_jdbc_driver_is_installed(options, properties) ensure_dbms_is_running(options, properties, scmStatus) if scmStatus is not None: scmStatus.reportStartPending() refresh_stack_hash(properties) if scmStatus is not None: scmStatus.reportStartPending() ensure_server_security_is_configured() if scmStatus is not None: scmStatus.reportStartPending() java_exe = get_java_exe_path() serverClassPath = ServerClassPath(properties, options) debug_mode = get_debug_mode() debug_start = (debug_mode & 1) or SERVER_START_DEBUG suspend_start = (debug_mode & 2) or SUSPEND_START_MODE suspend_mode = 'y' if suspend_start else 'n' if options.skip_database_validation: global jvm_args jvm_args += " -DskipDatabaseConsistencyValidation" param_list = generate_child_process_param_list( ambari_user, java_exe, serverClassPath.get_full_ambari_classpath_escaped_for_shell( validate_classpath=True), debug_start, suspend_mode) environ = generate_env(options, ambari_user, current_user) if not os.path.exists(configDefaults.PID_DIR): os.makedirs(configDefaults.PID_DIR, 0755) # The launched shell process and sub-processes should have a group id that # is different from the parent. def make_process_independent(): if IS_FOREGROUND: # upstart script is not able to track process from different pgid. return processId = os.getpid() if processId > 0: try: os.setpgid(processId, processId) except OSError, e: print_warning_msg('setpgid({0}, {0}) failed - {1}'.format( pidJava, str(e))) pass
def server_process_main(options, scmStatus=None): properties = get_ambari_properties() if properties == -1: err = "Error getting ambari properties" raise FatalException(-1, err) properties_for_print = [] logger.info("Ambari server properties config:") for key, value in properties.getPropertyDict().items(): if "passwd" not in key and "password" not in key: properties_for_print.append(key + "=" + value) logger.info(properties_for_print) # debug mode, including stop Java process at startup try: set_debug_mode_from_options(options) except AttributeError: pass if not check_reverse_lookup(): print_warning_msg( "The hostname was not found in the reverse DNS lookup. " "This may result in incorrect behavior. " "Please check the DNS setup and fix the issue.") check_database_name_property() parse_properties_file(options) is_active_instance = get_is_active_instance() if not is_active_instance: print_warning_msg( "This instance of ambari server is not designated as active. Cannot start ambari server." ) err = "This is not an active instance. Shutting down..." raise FatalException(1, err) ambari_user = read_ambari_user() current_user = ensure_can_start_under_current_user(ambari_user) print_info_msg("Ambari Server is not running...") jdk_path = find_jdk() if jdk_path is None: err = "No JDK found, please run the \"ambari-server setup\" " \ "command to install a JDK automatically or install any " \ "JDK manually to " + configDefaults.JDK_INSTALL_DIR raise FatalException(1, err) if not options.skip_properties_validation: missing_properties = get_missing_properties(properties) if missing_properties: err = "Required properties are not found: " + str(missing_properties) + ". To skip properties validation " \ "use \"--skip-properties-validation\"" raise FatalException(1, err) # Preparations if is_root(): print configDefaults.MESSAGE_SERVER_RUNNING_AS_ROOT ensure_jdbc_driver_is_installed(options, properties) ensure_dbms_is_running(options, properties, scmStatus) if scmStatus is not None: scmStatus.reportStartPending() refresh_stack_hash(properties) if scmStatus is not None: scmStatus.reportStartPending() ensure_server_security_is_configured() if scmStatus is not None: scmStatus.reportStartPending() java_exe = get_java_exe_path() serverClassPath = ServerClassPath(properties, options) debug_mode = get_debug_mode() debug_start = (debug_mode & 1) or SERVER_START_DEBUG suspend_start = (debug_mode & 2) or SUSPEND_START_MODE suspend_mode = 'y' if suspend_start else 'n' environ = generate_env(options, ambari_user, current_user) class_path = serverClassPath.get_full_ambari_classpath_escaped_for_shell( validate_classpath=True) if options.skip_database_check: global jvm_args jvm_args += " -DskipDatabaseConsistencyCheck" print "Ambari Server is starting with the database consistency check skipped. Do not make any changes to your cluster " \ "topology or perform a cluster upgrade until you correct the database consistency issues. See \"" \ + configDefaults.DB_CHECK_LOG + "\" for more details on the consistency issues." properties.process_pair(CHECK_DATABASE_SKIPPED_PROPERTY, "true") else: print "Ambari database consistency check started..." if options.fix_database_consistency: jvm_args += " -DfixDatabaseConsistency" properties.process_pair(CHECK_DATABASE_SKIPPED_PROPERTY, "false") update_properties(properties) param_list = generate_child_process_param_list(ambari_user, java_exe, class_path, debug_start, suspend_mode) # The launched shell process and sub-processes should have a group id that # is different from the parent. def make_process_independent(): if IS_FOREGROUND: # upstart script is not able to track process from different pgid. return processId = os.getpid() if processId > 0: try: os.setpgid(processId, processId) except OSError, e: print_warning_msg('setpgid({0}, {0}) failed - {1}'.format( pidJava, str(e))) pass
def main(options, args, parser): # set silent set_silent(options.silent) # debug mode set_debug_mode_from_options(options) init_debug(options) #perform checks options.warnings = [] if are_cmd_line_db_args_blank(options): options.must_set_database_options = True elif not are_cmd_line_db_args_valid(options): parser.error( 'All database options should be set. Please see help for the options.' ) else: options.must_set_database_options = False #correct database fix_database_options(options, parser) if len(args) == 0: print parser.print_help() parser.error("No action entered") action_map = create_user_action_map(args, options) action = args[0] try: action_obj = action_map[action] except KeyError: parser.error("Invalid action: " + action) matches = 0 for args_number_required in action_obj.possible_args_numbers: matches += int(len(args) == args_number_required) if matches == 0: print parser.print_help() possible_args = ' or '.join( str(x) for x in action_obj.possible_args_numbers) parser.error("Invalid number of arguments. Entered: " + str(len(args)) + ", required: " + possible_args) options.exit_message = "Ambari Server '%s' completed successfully." % action try: action_obj.execute() if action_obj.need_restart: pstatus, pid = is_server_runing() if pstatus: print 'NOTE: Restart Ambari Server to apply changes' + \ ' ("ambari-server restart|stop+start")' if options.warnings: for warning in options.warnings: print_warning_msg(warning) pass options.exit_message = "Ambari Server '%s' completed with warnings." % action pass except FatalException as e: if e.reason is not None: print_error_msg("Exiting with exit code {0}. \nREASON: {1}".format( e.code, e.reason)) sys.exit(e.code) except NonFatalException as e: options.exit_message = "Ambari Server '%s' completed with warnings." % action if e.reason is not None: print_warning_msg(e.reason) if options.exit_message is not None: print options.exit_message
def server_process_main(options, scmStatus=None): # debug mode, including stop Java process at startup try: set_debug_mode_from_options(options) except AttributeError: pass if not check_reverse_lookup(): print_warning_msg( "The hostname was not found in the reverse DNS lookup. " "This may result in incorrect behavior. " "Please check the DNS setup and fix the issue.") check_database_name_property() parse_properties_file(options) ambari_user = read_ambari_user() current_user = ensure_can_start_under_current_user(ambari_user) print_info_msg("Ambari Server is not running...") jdk_path = find_jdk() if jdk_path is None: err = "No JDK found, please run the \"ambari-server setup\" " \ "command to install a JDK automatically or install any " \ "JDK manually to " + configDefaults.JDK_INSTALL_DIR raise FatalException(1, err) properties = get_ambari_properties() # Preparations if is_root(): print configDefaults.MESSAGE_SERVER_RUNNING_AS_ROOT ensure_jdbc_driver_is_installed(options, properties) ensure_dbms_is_running(options, properties, scmStatus) if scmStatus is not None: scmStatus.reportStartPending() refresh_stack_hash(properties) if scmStatus is not None: scmStatus.reportStartPending() ensure_server_security_is_configured() if scmStatus is not None: scmStatus.reportStartPending() java_exe = get_java_exe_path() class_path = get_conf_dir() class_path = os.path.abspath( class_path) + os.pathsep + get_ambari_classpath() debug_mode = get_debug_mode() debug_start = (debug_mode & 1) or SERVER_START_DEBUG suspend_start = (debug_mode & 2) or SUSPEND_START_MODE suspend_mode = 'y' if suspend_start else 'n' (param_list, environ) = generate_child_process_param_list(ambari_user, current_user, java_exe, class_path, debug_start, suspend_mode) if not os.path.exists(configDefaults.PID_DIR): os.makedirs(configDefaults.PID_DIR, 0755) print_info_msg("Running server: " + str(param_list)) procJava = subprocess.Popen(param_list, env=environ) pidJava = procJava.pid if pidJava <= 0: procJava.terminate() exitcode = procJava.returncode exitfile = os.path.join(configDefaults.PID_DIR, EXITCODE_NAME) save_pid(exitcode, exitfile) if scmStatus is not None: scmStatus.reportStopPending() raise FatalException( -1, AMBARI_SERVER_DIE_MSG.format(exitcode, configDefaults.SERVER_OUT_FILE)) else: pidfile = os.path.join(configDefaults.PID_DIR, PID_NAME) save_pid(pidJava, pidfile) print "Server PID at: " + pidfile print "Server out at: " + configDefaults.SERVER_OUT_FILE print "Server log at: " + configDefaults.SERVER_LOG_FILE wait_for_server_start(pidfile, scmStatus) if scmStatus is not None: scmStatus.reportStarted() return procJava
def main(options, args, parser): init_logging() # set silent set_silent(options.silent) # debug mode set_debug_mode_from_options(options) init_debug(options) #perform checks options.warnings = [] if len(args) == 0: print parser.print_help() parser.error("No action entered") action_map = create_user_action_map(args, options) action = args[0] try: action_obj = action_map[action] except KeyError: parser.error("Invalid action: " + action) if action == SETUP_ACTION: if are_cmd_line_db_args_blank(options): options.must_set_database_options = True elif not are_cmd_line_db_args_valid(options): parser.error('All database options should be set. Please see help for the options.') else: options.must_set_database_options = False #correct database fix_database_options(options, parser) matches = 0 for args_number_required in action_obj.possible_args_numbers: matches += int(len(args) == args_number_required) if matches == 0: print parser.print_help() possible_args = ' or '.join(str(x) for x in action_obj.possible_args_numbers) parser.error("Invalid number of arguments. Entered: " + str(len(args)) + ", required: " + possible_args) options.exit_message = "Ambari Server '%s' completed successfully." % action options.exit_code = None try: if action in _action_option_dependence_map: required, optional = _action_option_dependence_map[action] for opt_str, opt_dest in required: if hasattr(options, opt_dest) and getattr(options, opt_dest) is None: print "Missing option {0} for action {1}".format(opt_str, action) print_action_arguments_help(action) print "Run ambari-server.py --help to see detailed description of each option" raise FatalException(1, "Missing option") action_obj.execute() if action_obj.need_restart: pstatus, pid = is_server_runing() if pstatus: print 'NOTE: Restart Ambari Server to apply changes' + \ ' ("ambari-server restart|stop+start")' if options.warnings: for warning in options.warnings: print_warning_msg(warning) pass options.exit_message = "Ambari Server '%s' completed with warnings." % action pass except FatalException as e: if e.reason is not None: print_error_msg("Exiting with exit code {0}. \nREASON: {1}".format(e.code, e.reason)) logger.exception(str(e)) sys.exit(e.code) except NonFatalException as e: options.exit_message = "Ambari Server '%s' completed with warnings." % action if e.reason is not None: print_warning_msg(e.reason) if options.exit_message is not None: print options.exit_message if options.exit_code is not None: # not all actions may return a system exit code sys.exit(options.exit_code)
def server_process_main(options, scmStatus=None): # debug mode, including stop Java process at startup try: set_debug_mode_from_options(options) except AttributeError: pass if not check_reverse_lookup(): print_warning_msg("The hostname was not found in the reverse DNS lookup. " "This may result in incorrect behavior. " "Please check the DNS setup and fix the issue.") check_database_name_property() parse_properties_file(options) ambari_user = read_ambari_user() current_user = ensure_can_start_under_current_user(ambari_user) print_info_msg("Ambari Server is not running...") jdk_path = find_jdk() if jdk_path is None: err = "No JDK found, please run the \"ambari-server setup\" " \ "command to install a JDK automatically or install any " \ "JDK manually to " + configDefaults.JDK_INSTALL_DIR raise FatalException(1, err) properties = get_ambari_properties() # Preparations if is_root(): print configDefaults.MESSAGE_SERVER_RUNNING_AS_ROOT ensure_jdbc_driver_is_installed(options, properties) ensure_dbms_is_running(options, properties, scmStatus) if scmStatus is not None: scmStatus.reportStartPending() refresh_stack_hash(properties) if scmStatus is not None: scmStatus.reportStartPending() ensure_server_security_is_configured() if scmStatus is not None: scmStatus.reportStartPending() java_exe = get_java_exe_path() serverClassPath = ServerClassPath(properties, options) debug_mode = get_debug_mode() debug_start = (debug_mode & 1) or SERVER_START_DEBUG suspend_start = (debug_mode & 2) or SUSPEND_START_MODE suspend_mode = 'y' if suspend_start else 'n' param_list = generate_child_process_param_list(ambari_user, java_exe, serverClassPath.get_full_ambari_classpath_escaped_for_shell(), debug_start, suspend_mode) environ = generate_env(options, ambari_user, current_user) if not os.path.exists(configDefaults.PID_DIR): os.makedirs(configDefaults.PID_DIR, 0755) # The launched shell process and sub-processes should have a group id that # is different from the parent. def make_process_independent(): processId = os.getpid() if processId > 0: try: os.setpgid(processId, processId) except OSError, e: print_warning_msg('setpgid({0}, {0}) failed - {1}'.format(pidJava, str(e))) pass
def main(options, args, parser): # set silent set_silent(options.silent) # debug mode set_debug_mode_from_options(options) init_debug(options) #perform checks options.warnings = [] if are_cmd_line_db_args_blank(options): options.must_set_database_options = True elif not are_cmd_line_db_args_valid(options): parser.error('All database options should be set. Please see help for the options.') else: options.must_set_database_options = False #correct database fix_database_options(options, parser) if len(args) == 0: print parser.print_help() parser.error("No action entered") action_map = create_user_action_map(args, options) action = args[0] try: action_obj = action_map[action] except KeyError: parser.error("Invalid action: " + action) matches = 0 for args_number_required in action_obj.possible_args_numbers: matches += int(len(args) == args_number_required) if matches == 0: print parser.print_help() possible_args = ' or '.join(str(x) for x in action_obj.possible_args_numbers) parser.error("Invalid number of arguments. Entered: " + str(len(args)) + ", required: " + possible_args) options.exit_message = "Ambari Server '%s' completed successfully." % action try: action_obj.execute() if action_obj.need_restart: pstatus, pid = is_server_runing() if pstatus: print 'NOTE: Restart Ambari Server to apply changes' + \ ' ("ambari-server restart|stop+start")' if options.warnings: for warning in options.warnings: print_warning_msg(warning) pass options.exit_message = "Ambari Server '%s' completed with warnings." % action pass except FatalException as e: if e.reason is not None: print_error_msg("Exiting with exit code {0}. \nREASON: {1}".format(e.code, e.reason)) sys.exit(e.code) except NonFatalException as e: options.exit_message = "Ambari Server '%s' completed with warnings." % action if e.reason is not None: print_warning_msg(e.reason) if options.exit_message is not None: print options.exit_message
def server_process_main(options, scmStatus=None): # debug mode, including stop Java process at startup try: set_debug_mode_from_options(options) except AttributeError: pass if not check_reverse_lookup(): print_warning_msg("The hostname was not found in the reverse DNS lookup. " "This may result in incorrect behavior. " "Please check the DNS setup and fix the issue.") check_database_name_property() parse_properties_file(options) is_active_instance = get_is_active_instance() if not is_active_instance: print_warning_msg("This instance of ambari server is not designated as active. Cannot start ambari server.") err = "This is not an active instance. Shutting down..." raise FatalException(1, err) ambari_user = read_ambari_user() current_user = ensure_can_start_under_current_user(ambari_user) print_info_msg("Ambari Server is not running...") jdk_path = find_jdk() if jdk_path is None: err = "No JDK found, please run the \"ambari-server setup\" " \ "command to install a JDK automatically or install any " \ "JDK manually to " + configDefaults.JDK_INSTALL_DIR raise FatalException(1, err) properties = get_ambari_properties() # Preparations if is_root(): print configDefaults.MESSAGE_SERVER_RUNNING_AS_ROOT ensure_jdbc_driver_is_installed(options, properties) ensure_dbms_is_running(options, properties, scmStatus) if scmStatus is not None: scmStatus.reportStartPending() refresh_stack_hash(properties) if scmStatus is not None: scmStatus.reportStartPending() ensure_server_security_is_configured() if scmStatus is not None: scmStatus.reportStartPending() java_exe = get_java_exe_path() class_path = get_conf_dir() class_path = os.path.abspath(class_path) + os.pathsep + get_ambari_classpath() jdbc_driver_path = get_jdbc_driver_path(options, properties) if jdbc_driver_path not in class_path: class_path = class_path + os.pathsep + jdbc_driver_path if SERVER_CLASSPATH_KEY in os.environ: class_path = os.environ[SERVER_CLASSPATH_KEY] + os.pathsep + class_path native_libs_path = get_native_libs_path(options, properties) if native_libs_path is not None: if LIBRARY_PATH_KEY in os.environ: native_libs_path = os.environ[LIBRARY_PATH_KEY] + os.pathsep + native_libs_path os.environ[LIBRARY_PATH_KEY] = native_libs_path debug_mode = get_debug_mode() debug_start = (debug_mode & 1) or SERVER_START_DEBUG suspend_start = (debug_mode & 2) or SUSPEND_START_MODE suspend_mode = 'y' if suspend_start else 'n' param_list = generate_child_process_param_list(ambari_user, java_exe, class_path, debug_start, suspend_mode) environ = generate_env(ambari_user, current_user) if not os.path.exists(configDefaults.PID_DIR): os.makedirs(configDefaults.PID_DIR, 0755) print_info_msg("Running server: " + str(param_list)) procJava = subprocess.Popen(param_list, env=environ) pidJava = procJava.pid if pidJava <= 0: procJava.terminate() exitcode = procJava.returncode exitfile = os.path.join(configDefaults.PID_DIR, EXITCODE_NAME) save_pid(exitcode, exitfile) if scmStatus is not None: scmStatus.reportStopPending() raise FatalException(-1, AMBARI_SERVER_DIE_MSG.format(exitcode, configDefaults.SERVER_OUT_FILE)) else: # Change the group id to the process id of the parent so that the launched # process and sub-processes have a group id that is different from the parent. try: os.setpgid(pidJava, 0) except OSError, e: print_warning_msg('setpgid({0}, 0) failed - {1}'.format(pidJava, str(e))) pass pidfile = os.path.join(configDefaults.PID_DIR, PID_NAME) save_pid(pidJava, pidfile) print "Server PID at: "+pidfile print "Server out at: "+configDefaults.SERVER_OUT_FILE print "Server log at: "+configDefaults.SERVER_LOG_FILE wait_for_server_start(pidfile, scmStatus)
def server_process_main(options, scmStatus=None): # debug mode, including stop Java process at startup try: set_debug_mode_from_options(options) except AttributeError: pass if not check_reverse_lookup(): print_warning_msg("The hostname was not found in the reverse DNS lookup. " "This may result in incorrect behavior. " "Please check the DNS setup and fix the issue.") check_database_name_property() parse_properties_file(options) ambari_user = read_ambari_user() current_user = ensure_can_start_under_current_user(ambari_user) print_info_msg("TBDS Server is not running...") jdk_path = find_jdk() if jdk_path is None: err = "No JDK found, please run the \"tbds-server setup\" " \ "command to install a JDK automatically or install any " \ "JDK manually to " + configDefaults.JDK_INSTALL_DIR raise FatalException(1, err) properties = get_ambari_properties() # Preparations if is_root(): print configDefaults.MESSAGE_SERVER_RUNNING_AS_ROOT ensure_jdbc_driver_is_installed(options, properties) ensure_dbms_is_running(options, properties, scmStatus) if scmStatus is not None: scmStatus.reportStartPending() refresh_stack_hash(properties) if scmStatus is not None: scmStatus.reportStartPending() ensure_server_security_is_configured() if scmStatus is not None: scmStatus.reportStartPending() java_exe = get_java_exe_path() class_path = get_conf_dir() class_path = os.path.abspath(class_path) + os.pathsep + get_ambari_classpath() debug_mode = get_debug_mode() debug_start = (debug_mode & 1) or SERVER_START_DEBUG suspend_start = (debug_mode & 2) or SUSPEND_START_MODE suspend_mode = 'y' if suspend_start else 'n' (param_list, environ) = generate_child_process_param_list(ambari_user, current_user, java_exe, class_path, debug_start, suspend_mode) if not os.path.exists(configDefaults.PID_DIR): os.makedirs(configDefaults.PID_DIR, 0755) print_info_msg("Running server: " + str(param_list)) procJava = subprocess.Popen(param_list, env=environ) pidJava = procJava.pid if pidJava <= 0: procJava.terminate() exitcode = procJava.returncode exitfile = os.path.join(configDefaults.PID_DIR, EXITCODE_NAME) save_pid(exitcode, exitfile) if scmStatus is not None: scmStatus.reportStopPending() raise FatalException(-1, AMBARI_SERVER_DIE_MSG.format(exitcode, configDefaults.SERVER_OUT_FILE)) else: pidfile = os.path.join(configDefaults.PID_DIR, PID_NAME) save_pid(pidJava, pidfile) print "Server PID at: "+pidfile print "Server out at: "+configDefaults.SERVER_OUT_FILE print "Server log at: "+configDefaults.SERVER_LOG_FILE wait_for_server_start(pidfile, scmStatus) if scmStatus is not None: scmStatus.reportStarted() return procJava
def main(options, args, parser): # init logger properties = get_ambari_properties() python_log_level = logging.INFO python_log_name = "ambari-server-command.log" custom_log_level = properties["server.python.log.level"] if custom_log_level: if custom_log_level == "INFO": python_log_level = logging.INFO if custom_log_level == "DEBUG": python_log_level = logging.DEBUG custom_log_name = properties["server.python.log.name"] if custom_log_name: python_log_name = custom_log_name python_log = os.path.join(configDefaults.OUT_DIR, python_log_name) setup_logging(logger, python_log, python_log_level) # set silent set_silent(options.silent) # debug mode set_debug_mode_from_options(options) init_debug(options) #perform checks options.warnings = [] if are_cmd_line_db_args_blank(options): options.must_set_database_options = True elif not are_cmd_line_db_args_valid(options): parser.error( 'All database options should be set. Please see help for the options.' ) else: options.must_set_database_options = False #correct database fix_database_options(options, parser) if len(args) == 0: print parser.print_help() parser.error("No action entered") action_map = create_user_action_map(args, options) action = args[0] try: action_obj = action_map[action] except KeyError: parser.error("Invalid action: " + action) matches = 0 for args_number_required in action_obj.possible_args_numbers: matches += int(len(args) == args_number_required) if matches == 0: print parser.print_help() possible_args = ' or '.join( str(x) for x in action_obj.possible_args_numbers) parser.error("Invalid number of arguments. Entered: " + str(len(args)) + ", required: " + possible_args) options.exit_message = "Ambari Server '%s' completed successfully." % action options.exit_code = None try: action_obj.execute() if action_obj.need_restart: pstatus, pid = is_server_runing() if pstatus: print 'NOTE: Restart Ambari Server to apply changes' + \ ' ("ambari-server restart|stop+start")' if options.warnings: for warning in options.warnings: print_warning_msg(warning) pass options.exit_message = "Ambari Server '%s' completed with warnings." % action pass except FatalException as e: if e.reason is not None: print_error_msg("Exiting with exit code {0}. \nREASON: {1}".format( e.code, e.reason)) logger.exception(str(e)) sys.exit(e.code) except NonFatalException as e: options.exit_message = "Ambari Server '%s' completed with warnings." % action if e.reason is not None: print_warning_msg(e.reason) if options.exit_message is not None: print options.exit_message if options.exit_code is not None: # not all actions may return a system exit code sys.exit(options.exit_code)