/** * Like {@link #terminate(int, Throwable)} without a message. * * @param status exit code * @throws ExitException if {@link System#exit(int)} is disabled. */ public static void terminate(int status) throws ExitException { terminate(status, EXIT_EXCEPTION_MESSAGE); }
/** * Exit the JVM. * * This is method can be overridden for testing, throwing an * exception instead. Any subclassed method MUST raise an * {@code ExitException} instance/subclass. * The service launcher code assumes that after this method is invoked, * no other code in the same method is called. * @param exitCode code to exit */ protected void exit(int exitCode, String message) { ExitUtil.terminate(exitCode, message); }
/** * Exit the JVM using an exception for the exit code and message, * invoking {@link ExitUtil#terminate(ExitUtil.ExitException)}. * * This is the standard way a launched service exits. * An error code of 0 means success -nothing is printed. * * If {@link ExitUtil#disableSystemExit()} has been called, this * method will throw the exception. * * The method <i>may</i> be subclassed for testing * @param ee exit exception * @throws ExitUtil.ExitException if ExitUtil exceptions are disabled */ protected void exit(ExitUtil.ExitException ee) { ExitUtil.terminate(ee); }
/** * Prints a message to stderr and exits with a status code. * * @param status exit code * @param msg message */ private static void terminate(int status, String msg) { System.err.println(msg); ExitUtil.terminate(status, msg); } }
/** * Like {@link #terminate(int, String)} but uses the given throwable to * build the message to display or throw as an * {@link ExitException}. * <p> * @param status exit code to use if the exception is not an ExitException. * @param t throwable which triggered the termination. If this exception * is an {@link ExitException} its status overrides that passed in. * @throws ExitException if {@link System#exit(int)} is disabled. */ public static void terminate(int status, Throwable t) throws ExitException { if (t instanceof ExitException) { terminate((ExitException) t); } else { terminate(new ExitException(status, t)); } }
/** * Exit with a printed message. * @param status status code * @param message message message to print before exiting * @throws ExitUtil.ExitException if exceptions are disabled */ protected static void exitWithMessage(int status, String message) { ExitUtil.terminate(new ServiceLaunchException(status, message)); }
/** * Terminate the current process. Note that terminate is the *only* method * that should be used to terminate the daemon processes. * * @param status exit code * @param msg message used to create the {@code ExitException} * @throws ExitException if {@link System#exit(int)} is disabled. */ public static void terminate(int status, String msg) throws ExitException { terminate(new ExitException(status, msg)); }
@Override public void uncaughtException(Thread t, Throwable e) { LOG.info("UncaughtExceptionHandler invoked"); if(ShutdownHookManager.isShutdownInProgress()) { LOG.warn("Thread {} threw a Throwable, but we are shutting down, so ignoring this", t, e); } else if(e instanceof Error) { try { LOG.error("Thread {} threw an Error. Shutting down now...", t, e); } catch (Throwable err) { //We don't want to not exit because of an issue with logging } if(e instanceof OutOfMemoryError) { //After catching an OOM java says it is undefined behavior, so don't //even try to clean up or we can get stuck on shutdown. try { System.err.println("Halting due to Out Of Memory Error..."); e.printStackTrace(); } catch (Throwable err) { //Again we done want to exit because of logging issues. } ExitUtil.halt(-1); } else { ExitUtil.terminate(-1); } } else { LOG.error("Thread {} threw an Exception. Shutting down now...", t, e); ExitUtil.terminate(-1); } } }
/** * Main entry point. * @param argv args list */ public static void main(String[] argv) { try { ExitUtil.terminate(exec(new Configuration(), argv)); } catch (ExitUtil.ExitException e) { LOG.error(e.toString()); System.exit(e.status); } catch (Exception e) { LOG.error(e.toString(), e); ExitUtil.halt(-1, e); } }
} catch (Throwable re) { LOG.error("Bug in read selector!", re); ExitUtil.terminate(1, "Bug in read selector!");
/** * @param args Command line args */ public static void main(String[] args) { boolean result = false; try { JstormMaster appMaster = new JstormMaster(); LOG.info("Initializing Jstorm Master!"); boolean doRun = appMaster.init(args); if (!doRun) { System.exit(JOYConstants.EXIT_SUCCESS); } appMaster.run(); // LRS won't finish at all result = appMaster.finish(); } catch (Throwable t) { LOG.fatal("Error running JstormMaster", t); LogManager.shutdown(); ExitUtil.terminate(JOYConstants.EXIT_FAIL1, t); } if (result) { LOG.info("Application Master completed successfully. exiting"); System.exit(JOYConstants.EXIT_SUCCESS); } else { LOG.info("Application Master failed. exiting"); System.exit(JOYConstants.EXIT_FAIL2); } }
ExitUtil.terminate(EXIT_INTERRUPTED, message);
ExitUtil.terminate(ee.status, ee);
static JobHistoryServer launchJobHistoryServer(String[] args) { Thread. setDefaultUncaughtExceptionHandler(new YarnUncaughtExceptionHandler()); StringUtils.startupShutdownMessage(JobHistoryServer.class, args, LOG); JobHistoryServer jobHistoryServer = null; try { jobHistoryServer = new JobHistoryServer(); ShutdownHookManager.get().addShutdownHook( new CompositeServiceShutdownHook(jobHistoryServer), SHUTDOWN_HOOK_PRIORITY); YarnConfiguration conf = new YarnConfiguration(new JobConf()); new GenericOptionsParser(conf, args); jobHistoryServer.init(conf); jobHistoryServer.start(); } catch (Throwable t) { LOG.fatal("Error starting JobHistoryServer", t); ExitUtil.terminate(-1, "Error starting JobHistoryServer"); } return jobHistoryServer; }
private void terminate(Throwable t) { String message = "Exception while edit logging: "+t.getMessage(); LOG.error(message, t); ExitUtil.terminate(1, message); }
public static void main(String[] args) throws Exception { StringUtils.startupShutdownMessage(JournalNode.class, args, LOG); try { System.exit(ToolRunner.run(new JournalNode(), args)); } catch (Throwable e) { LOG.error("Failed to start journalnode.", e); terminate(-1, e); } }
@Override public void run() { try { processQueue(); } catch (Throwable t) { ExitUtil.terminate(1, getName() + " encountered fatal exception: " + t); } }
void enqueue(Runnable action) throws InterruptedException { if (!queue.offer(action)) { if (!isAlive() && namesystem.isRunning()) { ExitUtil.terminate(1, getName()+" is not running"); } long now = Time.monotonicNow(); if (now - lastFull > 4000) { lastFull = now; LOG.info("Block report queue is full"); } queue.put(action); } } }
/** */ public static void main(String argv[]) throws Exception { if (DFSUtil.parseHelpArgument(argv, NameNode.USAGE, System.out, true)) { System.exit(0); } try { StringUtils.startupShutdownMessage(NameNode.class, argv, LOG); NameNode namenode = createNameNode(argv, null); if (namenode != null) { namenode.join(); } } catch (Throwable e) { LOG.error("Failed to start namenode.", e); terminate(1, e); } }