Fix headless issue without reboot.

This commit is contained in:
mathiasdm
2011-02-14 17:12:12 +00:00
parent 581cd72032
commit a6686cbed4
4 changed files with 18 additions and 47 deletions

View File

@ -56,9 +56,10 @@ public class Main {
*/ */
public static void beginStartup(String[] args) { public static void beginStartup(String[] args) {
try { try {
String headless = RouterManager.getRouterContext().getProperty("router.isHeadless"); String headless = System.getProperty("java.awt.headless");
boolean isHeadless = Boolean.parseBoolean(headless); boolean isHeadless = Boolean.parseBoolean(headless);
if(isHeadless) { if(isHeadless) {
log.warn("Headless environment: not starting desktopgui!");
return; return;
} }
} }

View File

@ -55,50 +55,17 @@ public class RouterConsoleRunner {
private static final String DEFAULT_WEBAPPS_DIR = "./webapps/"; private static final String DEFAULT_WEBAPPS_DIR = "./webapps/";
private static final String USAGE = "Bad RouterConsoleRunner arguments, check clientApp.0.args in your clients.config file! " + private static final String USAGE = "Bad RouterConsoleRunner arguments, check clientApp.0.args in your clients.config file! " +
"Usage: [[port host[,host]] [-s sslPort [host[,host]]] [webAppsDir]]"; "Usage: [[port host[,host]] [-s sslPort [host[,host]]] [webAppsDir]]";
private static final String PROP_HEADLESS = "router.isHeadless";
static { static {
System.setProperty("org.mortbay.http.Version.paranoid", "true"); System.setProperty("org.mortbay.http.Version.paranoid", "true");
//Check if we are in a headless environment, set properties accordingly //Check if we are in a headless environment, set properties accordingly
List<RouterContext> contexts = RouterContext.listContexts(); String headless = "java.awt.headless";
if(contexts != null && contexts.size() > 0) { if(GraphicsEnvironment.isHeadless()) {
RouterContext context = contexts.get(0); System.setProperty(headless, "true");
String headless = context.getProperty(PROP_HEADLESS); }
if(headless == null) { else {
/* System.setProperty(headless, "false");
* Let's check if we are in a headless environment.
* We do this by setting headless to false
* and trying to get the graphics environment.
* If this fails, we should be headless.
*/
System.setProperty("java.awt.headless", "false");
try {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.isHeadlessInstance();
context.setProperty(PROP_HEADLESS, "false");
}
catch(InternalError e) {
context.setProperty(PROP_HEADLESS, "true");
}
context.router().setConfigSetting(PROP_HEADLESS, context.getProperty(PROP_HEADLESS));
context.router().saveConfig();
context.router().shutdown(0);
}
boolean isHeadless = true;
try {
isHeadless = Boolean.parseBoolean(headless);
}
catch(Exception e) {
//Incorrect setting, let's choose headless for safety
isHeadless = true;
}
if(isHeadless) {
System.setProperty("java.awt.headless", "true");
}
else {
System.setProperty("java.awt.headless", "false");
}
} }
} }
@ -359,13 +326,13 @@ public class RouterConsoleRunner {
} }
try { try {
//TODO: move away from routerconsole into a separate application. //TODO: move away from routerconsole into a separate application.
//ApplicationManager? //ApplicationManager?
VersionComparator v = new VersionComparator(); VersionComparator v = new VersionComparator();
if(v.compare(System.getProperty("java.runtime.version"), "1.6") >= 0) { if(v.compare(System.getProperty("java.runtime.version"), "1.6") >= 0) {
String[] args = new String[0]; String[] args = new String[0];
net.i2p.desktopgui.Main.beginStartup(args); net.i2p.desktopgui.Main.beginStartup(args);
} }
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();
} }

View File

@ -1,3 +1,6 @@
2011-02-14 Mathiasdm
* Fix headless issue without reboot
2011-02-13 zzz 2011-02-13 zzz
* Connect Client: Minor NPE fix cleanup * Connect Client: Minor NPE fix cleanup
* JobQueue: Prevet NPE at shutdown (thanks liberty) * JobQueue: Prevet NPE at shutdown (thanks liberty)

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */ /** deprecated */
public final static String ID = "Monotone"; public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION; public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 10; public final static long BUILD = 11;
/** for example "-test" */ /** for example "-test" */
public final static String EXTRA = ""; public final static String EXTRA = "";