mirror of https://github.com/qortal/qortal
Browse Source
ApplyUpdate is the 2nd-stage of the auto-update system, called after core has downloaded the update. As old versions of the Windows launcher EXE selects a 'client' JVM mode, heap memory could be limited to only 256MB. Until users upgrade via Windows installer, which replaces the EXE with 'server' JVM mode baked-in, then a work-around is to pass -XX:MaxRAMFraction=4 to the new JVM in order to emulate heap size in 'server' JVM mode.pull/16/head
catbref
4 years ago
2 changed files with 90 additions and 14 deletions
@ -0,0 +1,63 @@
|
||||
package org.qortal.test.apps; |
||||
|
||||
import java.io.IOException; |
||||
import java.lang.management.ManagementFactory; |
||||
import java.nio.file.Files; |
||||
import java.nio.file.Path; |
||||
import java.nio.file.Paths; |
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
|
||||
public class LaunchExeWIthJvmOptions { |
||||
|
||||
private static final String JAR_FILENAME = "qortal.jar"; |
||||
private static final String WINDOWS_EXE_LAUNCHER = "qortal.exe"; |
||||
private static final String JAVA_TOOL_OPTIONS_NAME = "JAVA_TOOL_OPTIONS"; |
||||
private static final String JAVA_TOOL_OPTIONS_VALUE = "-XX:MaxRAMFraction=4"; |
||||
|
||||
public static void main(String[] args) { |
||||
String javaHome = System.getProperty("java.home"); |
||||
System.out.println(String.format("Java home: %s", javaHome)); |
||||
|
||||
Path javaBinary = Paths.get(javaHome, "bin", "java"); |
||||
System.out.println(String.format("Java binary: %s", javaBinary)); |
||||
|
||||
Path exeLauncher = Paths.get(WINDOWS_EXE_LAUNCHER); |
||||
System.out.println(String.format("Windows EXE launcher: %s", exeLauncher)); |
||||
|
||||
List<String> javaCmd; |
||||
if (Files.exists(exeLauncher)) { |
||||
javaCmd = Arrays.asList(exeLauncher.toString()); |
||||
} else { |
||||
javaCmd = new ArrayList<>(); |
||||
// Java runtime binary itself
|
||||
javaCmd.add(javaBinary.toString()); |
||||
|
||||
// JVM arguments
|
||||
javaCmd.addAll(ManagementFactory.getRuntimeMXBean().getInputArguments()); |
||||
|
||||
// Call mainClass in JAR
|
||||
javaCmd.addAll(Arrays.asList("-jar", JAR_FILENAME)); |
||||
|
||||
// Add saved command-line args
|
||||
javaCmd.addAll(Arrays.asList(args)); |
||||
} |
||||
|
||||
try { |
||||
System.out.println(String.format("Restarting node with: %s", String.join(" ", javaCmd))); |
||||
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(javaCmd); |
||||
|
||||
if (Files.exists(exeLauncher)) { |
||||
System.out.println(String.format("Setting env %s to %s", JAVA_TOOL_OPTIONS_NAME, JAVA_TOOL_OPTIONS_VALUE)); |
||||
processBuilder.environment().put(JAVA_TOOL_OPTIONS_NAME, JAVA_TOOL_OPTIONS_VALUE); |
||||
} |
||||
|
||||
processBuilder.start(); |
||||
} catch (IOException e) { |
||||
System.err.println(String.format("Failed to restart node (BAD): %s", e.getMessage())); |
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue