List of usage examples for org.apache.commons.exec DaemonExecutor DaemonExecutor
DaemonExecutor
From source file:org.apache.karaf.decanter.kibana6.KibanaController.java
public KibanaController(File workingDirectory) { this.workingDirectory = workingDirectory; this.workingDirectory.mkdirs(); this.executor = new DaemonExecutor(); PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(new LogOutputStream() { @Override//from ww w .jav a 2 s . c o m protected void processLine(String line, int logLevel) { KIBANA_LOGGER.info(line); } }); executor.setStreamHandler(pumpStreamHandler); executor.setWatchdog(new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT)); executeResultHandler = new DefaultExecuteResultHandler(); }
From source file:org.fuin.esmp.EventStoreStartMojo.java
@Override protected final void executeGoal() throws MojoExecutionException { init();/* w w w.j av a 2 s . c om*/ LOG.info("command={}", command); LOG.info("arguments={}", Arrays.toString(arguments)); final CommandLine cmdLine = createCommandLine(); final DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); final DaemonExecutor executor = new DaemonExecutor(); try { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final PumpStreamHandler psh = new PumpStreamHandler(bos); executor.setStreamHandler(psh); executor.setWorkingDirectory(getEventStoreDir()); executor.execute(cmdLine, resultHandler); final List<String> messages = waitForHttpServer(resultHandler, bos); logDebug(messages); final String pid = extractPid(messages); LOG.info("Event store process ID: {}", pid); writePid(pid); } catch (final IOException ex) { throw new MojoExecutionException("Error executing the command line: " + cmdLine, ex); } }
From source file:org.lucidj.launcher.Launcher.java
private boolean launch_cmdline(CommandLine cmdline) { // TODO: HANDLE CTRL+C SHUTDOWN BUG DaemonExecutor executor = new DaemonExecutor(); // Do NOT destroy processes on VM exit executor.setProcessDestroyer(null);/*from w w w . j av a 2s. c o m*/ // Wait a resonable amount of time for process start watchdog = new LauncherWatchdog(15000); executor.setWatchdog(watchdog); try { // TODO: DUMP stdout/stderr if (daemon_mode) { // Launch and waits until the process becomes alive executor.execute(cmdline, this); watchdog.waitForProcessStarted(); } else { // Synchronous run executor.execute(cmdline); } } catch (Exception e) { System.out.println("Exception on exec: " + e.toString()); } if (watchdog.failureReason() != null) { System.out.println("Launcher: Failed: " + watchdog.failureReason().toString()); return (false); } System.out.println("Launcher: Successful"); return (true); }