public static void appendEnvPath(Map<String, String> env, String prop, String value) { String oldValue = env.get(prop); if (oldValue == null && CauchoSystem.isWindows()) { String winProp = prop.toUpperCase(Locale.ENGLISH); oldValue = env.get(winProp); if (oldValue != null) prop = winProp; } if (oldValue != null && !"".equals(oldValue)) value = value + File.pathSeparator + oldValue; env.put(prop, value); }
public Process launchManager(String[] argv) throws IOException { System.out.println( L.l( "Resin/{0} launching watchdog at {1}:{2}", VersionFactory.getVersion(), getWatchdogAddress(), getWatchdogPort())); log.fine(this + " starting ResinWatchdogManager"); Path resinHome = getResinHome(); Path resinRoot = getRootDirectory(); ProcessBuilder builder = new ProcessBuilder(); builder.directory(new File(resinRoot.getNativePath())); Map<String, String> env = builder.environment(); env.putAll(System.getenv()); String classPath = WatchdogArgs.calculateClassPath(resinHome); env.put("CLASSPATH", classPath); String libexecPath; if (is64bit()) { libexecPath = resinHome.lookup("libexec64").getNativePath(); appendEnvPath(env, "LD_LIBRARY_PATH", libexecPath); appendEnvPath(env, "LD_LIBRARY_PATH_64", libexecPath); appendEnvPath(env, "DYLD_LIBRARY_PATH", libexecPath); if (CauchoSystem.isWindows()) appendEnvPath(env, "Path", resinHome.lookup("win64").getNativePath()); } else { libexecPath = resinHome.lookup("libexec").getNativePath(); appendEnvPath(env, "LD_LIBRARY_PATH", libexecPath); appendEnvPath(env, "DYLD_LIBRARY_PATH", libexecPath); if (CauchoSystem.isWindows()) appendEnvPath(env, "Path", resinHome.lookup("win32").getNativePath()); } ArrayList<String> list = new ArrayList<String>(); list.add(_config.getJavaExe()); // #3759 - user args are first so they're displayed by ps list.addAll(_config.getWatchdogJvmArgs()); list.add("-Dresin.watchdog=" + _id); list.add("-Djava.util.logging.manager=com.caucho.log.LogManagerImpl"); list.add("-Djavax.management.builder.initial=com.caucho.jmx.MBeanServerBuilderImpl"); list.add("-Djava.awt.headless=true"); list.add("-Dresin.home=" + resinHome.getFullPath()); list.add("-Dresin.root=" + resinRoot.getFullPath()); for (int i = 0; i < argv.length; i++) { if (argv[i].startsWith("-Djava.class.path=")) { // IBM JDK startup issues } else if (argv[i].startsWith("-J")) { list.add(argv[i].substring(2)); } } // #2566 list.add("-Xrs"); if (!_config.hasWatchdogXss()) list.add("-Xss256k"); if (!_config.hasWatchdogXmx()) list.add("-Xmx32m"); // XXX: can this just be copied from original args? if (!list.contains("-d32") && !list.contains("-d64") && is64bit() && !CauchoSystem.isWindows()) { list.add("-d64"); } if (!list.contains("-server") && !list.contains("-client") && !CauchoSystem.isWindows()) { // #3331, windows can't add -server automatically list.add("-server"); } list.add("com.caucho.boot.WatchdogManager"); for (int i = 0; i < argv.length; i++) { if (argv[i].equals("-conf") || argv[i].equals("--conf")) { list.add(argv[i]); list.add(resinHome.lookup(argv[i + 1]).getNativePath()); i++; } else list.add(argv[i]); } list.add("--log-directory"); list.add(getLogDirectory().getFullPath()); builder = builder.command(list); // builder.redirectErrorStream(true); Process process = null; try { process = builder.start(); } catch (Exception e) { e.printStackTrace(); } InputStream stdIs = process.getInputStream(); InputStream stdErr = process.getErrorStream(); OutputStream stdOs = process.getOutputStream(); ProcessThreadReader reader = new ProcessThreadReader(stdIs); reader.setDaemon(true); reader.start(); ProcessThreadReader errorReader = new ProcessThreadReader(stdErr); errorReader.setDaemon(true); errorReader.start(); try { Thread.sleep(1000); } catch (Exception e) { } // stdIs.close(); stdOs.close(); return process; }