added option to set yacy configuration values using environment

variables
To use that feature, set an environment variable with prefix "yacy." and
suffix identical to the yacy configuration attribute name.
Additionaly we implemented a way to set a peer name using the setting
"network.unit.agent". This can therefore now be used to set a peer name
with the java call parameter
-Dyacy.network.unit.agent=anonymous
The purpose for this feature is the ability to set peer names in
mass-deployed kubernetes clusters to the same name to prevent that we
are flooding peer name statistics with auto-deployment-generated names.
pull/402/head
Michael Peter Christen 4 years ago
parent 198826c362
commit 96592a10cf

@ -135,10 +135,10 @@ network.unit.definition = defaults/yacy.network.freeworld.unit
# This option is only valid if the network.unit.domain property is set to 'any'
network.unit.domain.nocheck = false
# in addition to non-dht networks a client may have its own agent name
# this option is only used if the value is non-empty and network.unit.dht = false
# that means it is not usable in YaCy p2p-configurations, only in private portal configurations
network.unit.tenant.agent =
# A client may have its own agent name. This name can be set by the user and is set to a random value
# if not overwritten by the user. As an alternative, the name can be set with this property.
# This option is only used if the value is non-empty.
network.unit.agent =
# Prefer https for in-protocol operations when available on remote peers
# A distinct general setting is available to control whether https sould be used for remote search queries : remotesearch.https.preferred

@ -224,7 +224,7 @@ public class ConfigNetwork_p
prop.putHTML("network.unit.name", sb.getConfig(SwitchboardConstants.NETWORK_NAME, ""));
prop.putHTML("network.unit.description", sb.getConfig("network.unit.description", ""));
prop.putHTML("network.unit.domain", sb.getConfig(SwitchboardConstants.NETWORK_DOMAIN, ""));
prop.putHTML("network.unit.dht", sb.getConfig(SwitchboardConstants.DHT_ENABLED, ""));
prop.putHTML("network.unit.dht", sb.getConfig(SwitchboardConstants.NETWORK_UNIT_DHT, ""));
networkBootstrapLocations.remove(sb.getConfig("network.unit.definition", ""));
int c = 0;
for ( final String s : networkBootstrapLocations ) {

@ -1039,7 +1039,7 @@ public class YaCyDefaultServlet extends HttpServlet {
templatePatterns.put("simpleheadernavbar", sb.getConfig("decoration.simpleheadernavbar", "navbar-default"));
// add navigation keys to enable or disable menu items
templatePatterns.put("navigation-p2p", sb.getConfigBool(SwitchboardConstants.DHT_ENABLED, true) || !sb.isRobinsonMode() ? 1 : 0);
templatePatterns.put("navigation-p2p", sb.getConfigBool(SwitchboardConstants.NETWORK_UNIT_DHT, true) || !sb.isRobinsonMode() ? 1 : 0);
templatePatterns.put("navigation-p2p_authorized", authorized ? 1 : 0);
String submitted = sb.getConfig("server.servlets.submitted", "");
boolean crawler_enabled = true; /*

@ -629,6 +629,8 @@ public final class Switchboard extends serverSwitch {
partitionExponent,
false,
this.exceed134217727);
String agent = getConfig(SwitchboardConstants.NETWORK_UNIT_AGENT, "");
if (!agent.isEmpty()) this.peers.setMyName(agent); // this can thus be set using the environment variable yacy.network.unit.agent
this.localpeers = Collections.newSetFromMap(new ConcurrentHashMap<>());
new OneTimeBusyThread("Switchboard.scanForOtherYaCyInIntranet") {
@Override
@ -3469,7 +3471,7 @@ public final class Switchboard extends serverSwitch {
condenser,
searchEvent,
sourceName,
getConfigBool(SwitchboardConstants.DHT_ENABLED, false),
getConfigBool(SwitchboardConstants.NETWORK_UNIT_DHT, false),
this.getConfigBool(SwitchboardConstants.PROXY_TRANSPARENT_PROXY, false) ? "http://127.0.0.1:" + sb.getConfigInt(SwitchboardConstants.SERVER_PORT, 8090) : null,
this.getConfig("crawler.http.acceptLanguage", null));
final RSSFeed feed =
@ -4123,7 +4125,7 @@ public final class Switchboard extends serverSwitch {
if ( this.peers.noDHTActivity() ) {
return "no DHT distribution: network too small";
}
if ( !getConfigBool(SwitchboardConstants.DHT_ENABLED, true) ) {
if ( !getConfigBool(SwitchboardConstants.NETWORK_UNIT_DHT, true) ) {
return "no DHT distribution: disabled by network.unit.dht";
}
if ( getConfig(SwitchboardConstants.INDEX_DIST_ALLOW, "false").equalsIgnoreCase("false") ) {

@ -268,8 +268,8 @@ public final class SwitchboardConstants {
public static final String REFERRER_META_POLICY_DEFAULT = "origin-when-cross-origin";
public static final String DHT_ENABLED = "network.unit.dht";
public static final String NETWORK_UNIT_DHT = "network.unit.dht";
public static final String NETWORK_UNIT_AGENT = "network.unit.agent";
public static final String REMOTESEARCH_MAXCOUNT_DEFAULT = "network.unit.remotesearch.maxcount";
public static final String REMOTESEARCH_MAXTIME_DEFAULT = "network.unit.remotesearch.maxtime";
public static final String REMOTESEARCH_MAXCOUNT_USER = "remotesearch.maxcount";

@ -77,8 +77,7 @@ public class serverSwitch {
private ConcurrentMap<String, Integer> upnpPortMap = new ConcurrentHashMap<>();
private boolean isConnectedViaUpnp;
public serverSwitch(final File dataPath, final File appPath,
final String initPath, final String configPath) {
public serverSwitch(final File dataPath, final File appPath, final String initPath, final String configPath) {
// we initialize the switchboard with a property file,
// but maintain these properties then later in a new 'config' file
// to reset all changed configs, the config file must
@ -87,13 +86,10 @@ public class serverSwitch {
// file name of the config file
this.dataPath = dataPath;
this.appPath = appPath;
this.configComment = "This is an automatically generated file, updated by serverAbstractSwitch and initialized by "
+ initPath;
this.configComment = "This is an automatically generated file, updated by serverAbstractSwitch and initialized by " + initPath;
final File initFile = new File(appPath, initPath);
this.configFile = new File(dataPath, configPath); // propertiesFile(config);
this.firstInit = !this.configFile.exists(); // this is true if the
// application was started
// for the first time
this.firstInit = !this.configFile.exists(); // this is true if the application was started for the first time
new File(this.configFile.getParent()).mkdir();
// predefine init's
@ -111,6 +107,15 @@ public class serverSwitch {
this.configProps = new ConcurrentHashMap<String, String>();
}
// overwrite configs with values from environment variables that start with "yacy_"
Properties sysprops = System.getProperties();
sysprops.forEach((key, value) -> {
String k = (String) key;
if (k.startsWith("yacy.")) {
this.configProps.put(k.substring(5), (String) value);
}
});
// remove all values from config that do not appear in init
this.configRemoved = new ConcurrentHashMap<String, String>();
Iterator<String> i = this.configProps.keySet().iterator();

@ -194,7 +194,6 @@ public final class yacy {
ConcurrentLog.config("STARTUP", "Maximum file system path length: " + OS.maxPathLength);
f = new File(dataHome, "DATA/yacy.running");
final String conf = "DATA/SETTINGS/yacy.conf".replace("/", File.separator);
if (!f.createNewFile()) ConcurrentLog.severe("STARTUP", "WARNING: the file " + f + " can not be created!");
try { new FileOutputStream(f).write(Integer.toString(OS.getPID()).getBytes()); } catch (final Exception e) { } // write PID
f.deleteOnExit();
@ -205,6 +204,7 @@ public final class yacy {
lock = channel.tryLock(); // lock yacy.running
} catch (final Exception e) { }
final String conf = "DATA/SETTINGS/yacy.conf".replace("/", File.separator);
try {
sb = new Switchboard(dataHome, appHome, "defaults/yacy.init".replace("/", File.separator), conf);
} catch (final RuntimeException e) {

Loading…
Cancel
Save