Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
Handle more propertly local port configuration by system property
luccioman9b9c11226334
diff --git a/Procfile b/Procfileindex 65a9880e6..e6944606a 100755--- a/Procfile+++ b/Procfile@@ -1 +1 @@-web: java $JAVA_OPTS -Dhttp.port=$PORT -classpath target/classes:lib/* net.yacy.yacy\ No newline at end of file+web: java $JAVA_OPTS -Dnet.yacy.server.localPort=$PORT -classpath target/classes:lib/* net.yacy.yacy\ No newline at end of filediff --git a/htroot/ConfigBasic.html b/htroot/ConfigBasic.htmlindex daef4777a..1d0c0df91 100644--- a/htroot/ConfigBasic.html+++ b/htroot/ConfigBasic.html@@ -90,7 +90,7 @@<dl><dt><label for="port">Peer Port: </label></dt><dd>- <input type="text" name="port" id="port" value="#[defaultPort]#" size="5" maxlength="5" /> + <input type="text" name="port" id="port" value="#[defaultPort]#" size="5" maxlength="5" #(hasSystemDefinedPort)#::disabled="disabled"#(/hasSystemDefinedPort)#/> #(hasSystemDefinedPort)#::(Set by system property '#[systemProperty]#')#(/hasSystemDefinedPort)# <input type="checkbox" name="withssl" id="withssl" #(withsslenabled)#::checked="checked"#(/withsslenabled)#>with SSL (https enabled#(withsslenabled)#:: on port <a href="Settings_p.html?page=ProxyAccess">#[sslport]#</a>#(/withsslenabled)#)</dd>#(upnp)#::<dt>diff --git a/htroot/ConfigBasic.java b/htroot/ConfigBasic.javaindex 6144bd5af..155b23d6c 100644--- a/htroot/ConfigBasic.java+++ b/htroot/ConfigBasic.java@@ -266,6 +266,8 @@ public class ConfigBasic {// set default valuesprop.putHTML("defaultName", sb.peers.mySeed().getName());+ prop.put("hasSystemDefinedPort", env.getLocalPortSystemProperty() != null ? 1 : 0);+ prop.put("hasSystemDefinedPort_systemProperty", serverSwitch.LOCAL_PORT_SYSTEM_PROPERTY);prop.put("defaultPort", env.getLocalPort());prop.put("withsslenabled", env.getConfigBool("server.https", false) ? 1 : 0);lang = env.getConfig("locale.language", "default"); // re-assign lang, may have changeddiff --git a/source/net/yacy/server/serverSwitch.java b/source/net/yacy/server/serverSwitch.javaindex 0f3bbcbf0..fbcc982e5 100644--- a/source/net/yacy/server/serverSwitch.java+++ b/source/net/yacy/server/serverSwitch.java@@ -58,6 +58,9 @@ import net.yacy.peers.Seed;import net.yacy.search.SwitchboardConstants;public class serverSwitch {++ /** Key of system property defining locally open http port */+ public static final String LOCAL_PORT_SYSTEM_PROPERTY = "net.yacy.server.localPort";// configuration managementprivate final File configFile;@@ -217,26 +220,39 @@ public class serverSwitch {return getConfigInt(key, dflt);}++ /**+ * @return local http server port or null if system property is not defined+ */+ public Integer getLocalPortSystemProperty() {+ String systemDefinedPort = System.getProperty(LOCAL_PORT_SYSTEM_PROPERTY);+ Integer localPort = null;+ if(systemDefinedPort != null) {+ try {+ localPort = Integer.parseInt(systemDefinedPort);+ } catch(NumberFormatException e) {+ log.warn("System property " + LOCAL_PORT_SYSTEM_PROPERTY + " is not valid : it should be a integer.");+ }+ }+ return localPort;+ }/*** Wrapper for {@link #getConfigInt(String, int)} to have a more consistent* API.*- * Default value 8090 will be used if no value is found- *- * @return the local port of this system+ * Default value 8090 will be used if no value is found in system properties and in configuration.+ *+ * @return the local http port of this system* @see #getPublicPort(String, int)*/public int getLocalPort() {- /* A system property "http.port" may override configuration+ /* A system property "net.yacy.server.localPort" may override configuration* This is useful when running YaCy inside a container manager such as Heroku which decide which http port to use */- String systemDefinedPort = System.getProperty("http.port");- if(systemDefinedPort != null) {- try {- return Integer.parseInt(systemDefinedPort);- } catch(NumberFormatException e) {- }+ Integer localPort = getLocalPortSystemProperty();+ if(localPort != null) {+ return localPort;}return getConfigInt("port", 8090);}