mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-24 05:18:58 +00:00
Merge pull request #90 from MarginaliaSearch/run-outside-docker
Run outside of Docker
This commit is contained in:
commit
0f41105436
@ -6,7 +6,7 @@ plugins {
|
|||||||
|
|
||||||
// This is a workaround for a bug in the Jib plugin that causes it to stall randomly
|
// This is a workaround for a bug in the Jib plugin that causes it to stall randomly
|
||||||
// https://github.com/GoogleContainerTools/jib/issues/3347
|
// https://github.com/GoogleContainerTools/jib/issues/3347
|
||||||
id 'com.google.cloud.tools.jib' version '3.4.1' apply(false)
|
id 'com.google.cloud.tools.jib' version '3.4.2' apply(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
group 'marginalia'
|
group 'marginalia'
|
||||||
|
@ -10,7 +10,6 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
public class WmsaHome {
|
public class WmsaHome {
|
||||||
public static UserAgent getUserAgent() {
|
public static UserAgent getUserAgent() {
|
||||||
|
|
||||||
return new UserAgent(
|
return new UserAgent(
|
||||||
System.getProperty("crawler.userAgentString", "Mozilla/5.0 (compatible; Marginalia-like bot; +https://git.marginalia.nu/))"),
|
System.getProperty("crawler.userAgentString", "Mozilla/5.0 (compatible; Marginalia-like bot; +https://git.marginalia.nu/))"),
|
||||||
System.getProperty("crawler.userAgentIdentifier", "search.marginalia.nu")
|
System.getProperty("crawler.userAgentIdentifier", "search.marginalia.nu")
|
||||||
@ -40,7 +39,19 @@ public class WmsaHome {
|
|||||||
.findFirst();
|
.findFirst();
|
||||||
|
|
||||||
if (retStr.isEmpty()) {
|
if (retStr.isEmpty()) {
|
||||||
// Check if we are running in a test environment
|
// Check parent directories for a fingerprint of the project's installation boilerplate
|
||||||
|
var prodRoot = Stream.iterate(Paths.get("").toAbsolutePath(), f -> f != null && Files.exists(f), Path::getParent)
|
||||||
|
.filter(p -> Files.exists(p.resolve("conf/properties/system.properties")))
|
||||||
|
.filter(p -> Files.exists(p.resolve("model/tfreq-new-algo3.bin")))
|
||||||
|
.findAny();
|
||||||
|
if (prodRoot.isPresent()) {
|
||||||
|
return prodRoot.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if we are running in a test environment by looking for fingerprints
|
||||||
|
// matching the base of the source tree for the project, then looking up the
|
||||||
|
// run directory which contains a template for the installation we can use as
|
||||||
|
// though it's the project root for testing purposes
|
||||||
|
|
||||||
var testRoot = Stream.iterate(Paths.get("").toAbsolutePath(), f -> f != null && Files.exists(f), Path::getParent)
|
var testRoot = Stream.iterate(Paths.get("").toAbsolutePath(), f -> f != null && Files.exists(f), Path::getParent)
|
||||||
.filter(p -> Files.exists(p.resolve("run/env")))
|
.filter(p -> Files.exists(p.resolve("run/env")))
|
||||||
@ -50,8 +61,8 @@ public class WmsaHome {
|
|||||||
|
|
||||||
return testRoot.orElseThrow(() -> new IllegalStateException("""
|
return testRoot.orElseThrow(() -> new IllegalStateException("""
|
||||||
Could not find $WMSA_HOME, either set environment
|
Could not find $WMSA_HOME, either set environment
|
||||||
variable, the 'system.homePath' property,
|
variable, the 'system.homePath' java property,
|
||||||
or ensure either /wmssa or /var/lib/wmsa exists
|
or ensure either /wmsa or /var/lib/wmsa exists
|
||||||
"""));
|
"""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,13 +140,15 @@ public class ZkServiceRegistry implements ServiceRegistryIf {
|
|||||||
@Override
|
@Override
|
||||||
public int requestPort(String externalHost,
|
public int requestPort(String externalHost,
|
||||||
ServiceKey<?> key) {
|
ServiceKey<?> key) {
|
||||||
|
|
||||||
if (!Boolean.getBoolean("service.random-port")) {
|
if (!Boolean.getBoolean("service.random-port")) {
|
||||||
return switch (key) {
|
return switch (key) {
|
||||||
case ServiceKey.Rest rest -> 80;
|
case ServiceKey.Rest rest -> Integer.getInteger("service.http-port", 80);
|
||||||
case ServiceKey.Grpc<?> grpc -> 81;
|
case ServiceKey.Grpc<?> grpc -> Integer.getInteger("service.grpc-port",81);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int portRangeLow = 12_000;
|
int portRangeLow = 12_000;
|
||||||
int portRangeHigh = 12_999;
|
int portRangeHigh = 12_999;
|
||||||
|
|
||||||
|
@ -36,11 +36,15 @@ public class ServiceConfigurationModule extends AbstractModule {
|
|||||||
|
|
||||||
private int getPrometheusPort() {
|
private int getPrometheusPort() {
|
||||||
String prometheusPortEnv = System.getenv("WMSA_PROMETHEUS_PORT");
|
String prometheusPortEnv = System.getenv("WMSA_PROMETHEUS_PORT");
|
||||||
|
|
||||||
if (prometheusPortEnv != null) {
|
if (prometheusPortEnv != null) {
|
||||||
return Integer.parseInt(prometheusPortEnv);
|
return Integer.parseInt(prometheusPortEnv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Integer prometheusPortProperty = Integer.getInteger("service.prometheus-port");
|
||||||
|
if (prometheusPortProperty != null) {
|
||||||
|
return prometheusPortProperty;
|
||||||
|
}
|
||||||
|
|
||||||
return 7000;
|
return 7000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,10 @@ public class MetricsServer {
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@Inject
|
@Inject
|
||||||
public MetricsServer(ServiceConfiguration configuration) {
|
public MetricsServer(ServiceConfiguration configuration) {
|
||||||
|
// If less than zero, we forego setting up a metrics server
|
||||||
|
if (configuration.metricsPort() < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
Server server = new Server(configuration.metricsPort());
|
Server server = new Server(configuration.metricsPort());
|
||||||
ServletContextHandler context = new ServletContextHandler();
|
ServletContextHandler context = new ServletContextHandler();
|
||||||
context.setContextPath("/");
|
context.setContextPath("/");
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<MarkerFilter marker="HTTP" onMatch="DENY" onMismatch="NEUTRAL" />
|
<MarkerFilter marker="HTTP" onMatch="DENY" onMismatch="NEUTRAL" />
|
||||||
</Filters>
|
</Filters>
|
||||||
</Console>
|
</Console>
|
||||||
<RollingFile name="LogToFile" fileName="/var/log/wmsa/wmsa-${sys:service-name}-${env:WMSA_SERVICE_NODE:-0}.log" filePattern="/var/log/wmsa/wmsa-${sys:service-name}-${env:WMSA_SERVICE_NODE:-0}-log-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz"
|
<RollingFile name="LogToFile" fileName="${env:WMSA_LOG_DIR:/var/log/wmsa}/wmsa-${sys:service-name}-${env:WMSA_SERVICE_NODE:-0}.log" filePattern="/var/log/wmsa/wmsa-${sys:service-name}-${env:WMSA_SERVICE_NODE:-0}-log-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz"
|
||||||
ignoreExceptions="false">
|
ignoreExceptions="false">
|
||||||
<JSONLayout compact="true" eventEol="true" properties="true" stacktraceAsString="true" includeTimeMillis="true"/>
|
<JSONLayout compact="true" eventEol="true" properties="true" stacktraceAsString="true" includeTimeMillis="true"/>
|
||||||
<Filters>
|
<Filters>
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<MarkerFilter marker="HTTP" onMatch="DENY" onMismatch="NEUTRAL" />
|
<MarkerFilter marker="HTTP" onMatch="DENY" onMismatch="NEUTRAL" />
|
||||||
</Filters>
|
</Filters>
|
||||||
</Console>
|
</Console>
|
||||||
<RollingFile name="LogToFile" fileName="/var/log/wmsa/wmsa-${sys:service-name}-${env:WMSA_SERVICE_NODE:-0}.log" filePattern="/var/log/wmsa/wmsa-${sys:service-name}-${env:WMSA_SERVICE_NODE:-0}-log-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz"
|
<RollingFile name="LogToFile" fileName="${env:WMSA_LOG_DIR:/var/log/wmsa}/wmsa-${sys:service-name}-${env:WMSA_SERVICE_NODE:-0}.log" filePattern="/var/log/wmsa/wmsa-${sys:service-name}-${env:WMSA_SERVICE_NODE:-0}-log-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz"
|
||||||
ignoreExceptions="false">
|
ignoreExceptions="false">
|
||||||
<PatternLayout>
|
<PatternLayout>
|
||||||
<Pattern>%-5level %d{yyyy-MM-dd HH:mm:ss,SSS} %-20t %-20c{1}: %msg{nolookups}%n</Pattern>
|
<Pattern>%-5level %d{yyyy-MM-dd HH:mm:ss,SSS} %-20t %-20c{1}: %msg{nolookups}%n</Pattern>
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<MarkerFilter marker="HTTP" onMatch="DENY" onMismatch="NEUTRAL" />
|
<MarkerFilter marker="HTTP" onMatch="DENY" onMismatch="NEUTRAL" />
|
||||||
</Filters>
|
</Filters>
|
||||||
</Console>
|
</Console>
|
||||||
<RollingFile name="LogToFile" fileName="/var/log/wmsa/wmsa-${sys:service-name}-${env:WMSA_SERVICE_NODE:-0}.log" filePattern="/var/log/wmsa/wmsa-${sys:service-name}-${env:WMSA_SERVICE_NODE:-0}-log-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz"
|
<RollingFile name="LogToFile" fileName="${env:WMSA_LOG_DIR:/var/log/wmsa}/wmsa-${sys:service-name}-${env:WMSA_SERVICE_NODE:-0}.log" filePattern="/var/log/wmsa/wmsa-${sys:service-name}-${env:WMSA_SERVICE_NODE:-0}-log-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz"
|
||||||
ignoreExceptions="false">
|
ignoreExceptions="false">
|
||||||
<PatternLayout>
|
<PatternLayout>
|
||||||
<Pattern>%-5level %d{yyyy-MM-dd HH:mm:ss,SSS} %-20t %-20c{1}: %msg{nolookups}%n</Pattern>
|
<Pattern>%-5level %d{yyyy-MM-dd HH:mm:ss,SSS} %-20t %-20c{1}: %msg{nolookups}%n</Pattern>
|
||||||
|
@ -94,6 +94,7 @@ public class IndexResultValuationContext {
|
|||||||
|
|
||||||
CompiledQueryLong wordMetasQuery = new CompiledQueryLong(compiledQuery.root, new CqDataLong(wordMetas));
|
CompiledQueryLong wordMetasQuery = new CompiledQueryLong(compiledQuery.root, new CqDataLong(wordMetas));
|
||||||
|
|
||||||
|
|
||||||
boolean allSynthetic = CompiledQueryAggregates.booleanAggregate(wordMetasQuery, WordFlags.Synthetic::isPresent);
|
boolean allSynthetic = CompiledQueryAggregates.booleanAggregate(wordMetasQuery, WordFlags.Synthetic::isPresent);
|
||||||
int flagsCount = CompiledQueryAggregates.intMaxMinAggregate(wordMetasQuery, wordMeta -> Long.bitCount(wordMeta & flagsFilterMask));
|
int flagsCount = CompiledQueryAggregates.intMaxMinAggregate(wordMetasQuery, wordMeta -> Long.bitCount(wordMeta & flagsFilterMask));
|
||||||
int positionsCount = CompiledQueryAggregates.intMaxMinAggregate(wordMetasQuery, wordMeta -> Long.bitCount(WordMetadata.decodePositions(wordMeta)));
|
int positionsCount = CompiledQueryAggregates.intMaxMinAggregate(wordMetasQuery, wordMeta -> Long.bitCount(WordMetadata.decodePositions(wordMeta)));
|
||||||
|
@ -3,7 +3,7 @@ plugins {
|
|||||||
|
|
||||||
id 'application'
|
id 'application'
|
||||||
id 'jvm-test-suite'
|
id 'jvm-test-suite'
|
||||||
id 'com.google.cloud.tools.jib' version '3.4.1'
|
id 'com.google.cloud.tools.jib' version '3.4.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
|
@ -4,6 +4,7 @@ import com.google.inject.Guice;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import nu.marginalia.service.MainClass;
|
import nu.marginalia.service.MainClass;
|
||||||
|
import nu.marginalia.service.discovery.ServiceRegistryIf;
|
||||||
import nu.marginalia.service.module.ServiceDiscoveryModule;
|
import nu.marginalia.service.module.ServiceDiscoveryModule;
|
||||||
import nu.marginalia.service.ServiceId;
|
import nu.marginalia.service.ServiceId;
|
||||||
import nu.marginalia.service.module.ServiceConfigurationModule;
|
import nu.marginalia.service.module.ServiceConfigurationModule;
|
||||||
@ -23,6 +24,10 @@ public class ApiMain extends MainClass {
|
|||||||
new DatabaseModule(false),
|
new DatabaseModule(false),
|
||||||
new ServiceDiscoveryModule(),
|
new ServiceDiscoveryModule(),
|
||||||
new ServiceConfigurationModule(ServiceId.Api));
|
new ServiceConfigurationModule(ServiceId.Api));
|
||||||
|
|
||||||
|
// Ensure that the service registry is initialized early
|
||||||
|
injector.getInstance(ServiceRegistryIf.class);
|
||||||
|
|
||||||
injector.getInstance(ApiMain.class);
|
injector.getInstance(ApiMain.class);
|
||||||
injector.getInstance(Initialization.class).setReady();
|
injector.getInstance(Initialization.class).setReady();
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ plugins {
|
|||||||
|
|
||||||
id 'application'
|
id 'application'
|
||||||
id 'jvm-test-suite'
|
id 'jvm-test-suite'
|
||||||
id 'com.google.cloud.tools.jib' version '3.4.1'
|
id 'com.google.cloud.tools.jib' version '3.4.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
|
@ -4,6 +4,7 @@ import com.google.inject.Guice;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import nu.marginalia.service.MainClass;
|
import nu.marginalia.service.MainClass;
|
||||||
|
import nu.marginalia.service.discovery.ServiceRegistryIf;
|
||||||
import nu.marginalia.service.module.ServiceDiscoveryModule;
|
import nu.marginalia.service.module.ServiceDiscoveryModule;
|
||||||
import nu.marginalia.service.ServiceId;
|
import nu.marginalia.service.ServiceId;
|
||||||
import nu.marginalia.service.module.ServiceConfigurationModule;
|
import nu.marginalia.service.module.ServiceConfigurationModule;
|
||||||
@ -31,6 +32,9 @@ public class DatingMain extends MainClass {
|
|||||||
new DatabaseModule(false)
|
new DatabaseModule(false)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Ensure that the service registry is initialized early
|
||||||
|
injector.getInstance(ServiceRegistryIf.class);
|
||||||
|
|
||||||
injector.getInstance(DatingMain.class);
|
injector.getInstance(DatingMain.class);
|
||||||
injector.getInstance(Initialization.class).setReady();
|
injector.getInstance(Initialization.class).setReady();
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ plugins {
|
|||||||
|
|
||||||
id 'application'
|
id 'application'
|
||||||
id 'jvm-test-suite'
|
id 'jvm-test-suite'
|
||||||
id 'com.google.cloud.tools.jib' version '3.4.1'
|
id 'com.google.cloud.tools.jib' version '3.4.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
|
@ -4,6 +4,7 @@ import com.google.inject.Guice;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import nu.marginalia.service.MainClass;
|
import nu.marginalia.service.MainClass;
|
||||||
|
import nu.marginalia.service.discovery.ServiceRegistryIf;
|
||||||
import nu.marginalia.service.module.ServiceDiscoveryModule;
|
import nu.marginalia.service.module.ServiceDiscoveryModule;
|
||||||
import nu.marginalia.service.ServiceId;
|
import nu.marginalia.service.ServiceId;
|
||||||
import nu.marginalia.service.module.ServiceConfigurationModule;
|
import nu.marginalia.service.module.ServiceConfigurationModule;
|
||||||
@ -31,6 +32,9 @@ public class ExplorerMain extends MainClass {
|
|||||||
new DatabaseModule(false)
|
new DatabaseModule(false)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Ensure that the service registry is initialized early
|
||||||
|
injector.getInstance(ServiceRegistryIf.class);
|
||||||
|
|
||||||
injector.getInstance(ExplorerMain.class);
|
injector.getInstance(ExplorerMain.class);
|
||||||
injector.getInstance(Initialization.class).setReady();
|
injector.getInstance(Initialization.class).setReady();
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ plugins {
|
|||||||
id 'application'
|
id 'application'
|
||||||
id 'jvm-test-suite'
|
id 'jvm-test-suite'
|
||||||
|
|
||||||
id 'com.google.cloud.tools.jib' version '3.4.1'
|
id 'com.google.cloud.tools.jib' version '3.4.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
|
@ -4,6 +4,7 @@ import com.google.inject.Guice;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import nu.marginalia.service.MainClass;
|
import nu.marginalia.service.MainClass;
|
||||||
|
import nu.marginalia.service.discovery.ServiceRegistryIf;
|
||||||
import nu.marginalia.service.module.ServiceDiscoveryModule;
|
import nu.marginalia.service.module.ServiceDiscoveryModule;
|
||||||
import nu.marginalia.service.ServiceId;
|
import nu.marginalia.service.ServiceId;
|
||||||
import nu.marginalia.service.module.ServiceConfigurationModule;
|
import nu.marginalia.service.module.ServiceConfigurationModule;
|
||||||
@ -32,6 +33,9 @@ public class SearchMain extends MainClass {
|
|||||||
new DatabaseModule(false)
|
new DatabaseModule(false)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Ensure that the service registry is initialized early
|
||||||
|
injector.getInstance(ServiceRegistryIf.class);
|
||||||
|
|
||||||
injector.getInstance(SearchMain.class);
|
injector.getInstance(SearchMain.class);
|
||||||
injector.getInstance(Initialization.class).setReady();
|
injector.getInstance(Initialization.class).setReady();
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ plugins {
|
|||||||
|
|
||||||
id 'application'
|
id 'application'
|
||||||
id 'jvm-test-suite'
|
id 'jvm-test-suite'
|
||||||
id 'com.google.cloud.tools.jib' version '3.4.1'
|
id 'com.google.cloud.tools.jib' version '3.4.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
|
@ -4,6 +4,7 @@ import com.google.inject.Guice;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import nu.marginalia.service.MainClass;
|
import nu.marginalia.service.MainClass;
|
||||||
|
import nu.marginalia.service.discovery.ServiceRegistryIf;
|
||||||
import nu.marginalia.service.module.ServiceDiscoveryModule;
|
import nu.marginalia.service.module.ServiceDiscoveryModule;
|
||||||
import nu.marginalia.service.ServiceId;
|
import nu.marginalia.service.ServiceId;
|
||||||
import nu.marginalia.service.module.ServiceConfigurationModule;
|
import nu.marginalia.service.module.ServiceConfigurationModule;
|
||||||
@ -28,6 +29,10 @@ public class AssistantMain extends MainClass {
|
|||||||
new DatabaseModule(false)
|
new DatabaseModule(false)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// Ensure that the service registry is initialized early
|
||||||
|
injector.getInstance(ServiceRegistryIf.class);
|
||||||
|
|
||||||
injector.getInstance(AssistantMain.class);
|
injector.getInstance(AssistantMain.class);
|
||||||
injector.getInstance(Initialization.class).setReady();
|
injector.getInstance(Initialization.class).setReady();
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ plugins {
|
|||||||
id 'java'
|
id 'java'
|
||||||
id 'application'
|
id 'application'
|
||||||
id 'jvm-test-suite'
|
id 'jvm-test-suite'
|
||||||
id 'com.google.cloud.tools.jib' version '3.4.1'
|
id 'com.google.cloud.tools.jib' version '3.4.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
|
@ -4,6 +4,7 @@ import com.google.inject.Guice;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import nu.marginalia.service.MainClass;
|
import nu.marginalia.service.MainClass;
|
||||||
|
import nu.marginalia.service.discovery.ServiceRegistryIf;
|
||||||
import nu.marginalia.service.module.ServiceDiscoveryModule;
|
import nu.marginalia.service.module.ServiceDiscoveryModule;
|
||||||
import nu.marginalia.service.ServiceId;
|
import nu.marginalia.service.ServiceId;
|
||||||
import nu.marginalia.service.module.ServiceConfigurationModule;
|
import nu.marginalia.service.module.ServiceConfigurationModule;
|
||||||
@ -25,6 +26,9 @@ public class ControlMain extends MainClass {
|
|||||||
new ServiceDiscoveryModule(),
|
new ServiceDiscoveryModule(),
|
||||||
new ServiceConfigurationModule(ServiceId.Control));
|
new ServiceConfigurationModule(ServiceId.Control));
|
||||||
|
|
||||||
|
// Ensure that the service registry is initialized early
|
||||||
|
injector.getInstance(ServiceRegistryIf.class);
|
||||||
|
|
||||||
injector.getInstance(ControlMain.class);
|
injector.getInstance(ControlMain.class);
|
||||||
injector.getInstance(Initialization.class).setReady();
|
injector.getInstance(Initialization.class).setReady();
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ plugins {
|
|||||||
|
|
||||||
id 'application'
|
id 'application'
|
||||||
id 'jvm-test-suite'
|
id 'jvm-test-suite'
|
||||||
id 'com.google.cloud.tools.jib' version '3.4.1'
|
id 'com.google.cloud.tools.jib' version '3.4.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
@ -13,8 +13,6 @@ application {
|
|||||||
|
|
||||||
tasks.distZip.enabled = false
|
tasks.distZip.enabled = false
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
java {
|
java {
|
||||||
toolchain {
|
toolchain {
|
||||||
languageVersion.set(JavaLanguageVersion.of(rootProject.ext.jvmVersion))
|
languageVersion.set(JavaLanguageVersion.of(rootProject.ext.jvmVersion))
|
||||||
|
@ -4,6 +4,7 @@ import com.google.inject.Guice;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import nu.marginalia.service.MainClass;
|
import nu.marginalia.service.MainClass;
|
||||||
|
import nu.marginalia.service.discovery.ServiceRegistryIf;
|
||||||
import nu.marginalia.service.module.ServiceDiscoveryModule;
|
import nu.marginalia.service.module.ServiceDiscoveryModule;
|
||||||
import nu.marginalia.service.ServiceId;
|
import nu.marginalia.service.ServiceId;
|
||||||
import nu.marginalia.service.module.DatabaseModule;
|
import nu.marginalia.service.module.DatabaseModule;
|
||||||
@ -28,8 +29,11 @@ public class ExecutorMain extends MainClass {
|
|||||||
new ServiceDiscoveryModule(),
|
new ServiceDiscoveryModule(),
|
||||||
new ServiceConfigurationModule(ServiceId.Executor)
|
new ServiceConfigurationModule(ServiceId.Executor)
|
||||||
);
|
);
|
||||||
injector.getInstance(NodeStatusWatcher.class);
|
|
||||||
|
|
||||||
|
// Ensure that the service registry is initialized early
|
||||||
|
injector.getInstance(ServiceRegistryIf.class);
|
||||||
|
|
||||||
|
injector.getInstance(NodeStatusWatcher.class);
|
||||||
injector.getInstance(ExecutorMain.class);
|
injector.getInstance(ExecutorMain.class);
|
||||||
injector.getInstance(Initialization.class).setReady();
|
injector.getInstance(Initialization.class).setReady();
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ plugins {
|
|||||||
|
|
||||||
id 'application'
|
id 'application'
|
||||||
id 'jvm-test-suite'
|
id 'jvm-test-suite'
|
||||||
id 'com.google.cloud.tools.jib' version '3.4.1'
|
id 'com.google.cloud.tools.jib' version '3.4.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
|
@ -4,6 +4,7 @@ import com.google.inject.Guice;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import nu.marginalia.service.MainClass;
|
import nu.marginalia.service.MainClass;
|
||||||
|
import nu.marginalia.service.discovery.ServiceRegistryIf;
|
||||||
import nu.marginalia.service.module.ServiceDiscoveryModule;
|
import nu.marginalia.service.module.ServiceDiscoveryModule;
|
||||||
import nu.marginalia.service.ServiceId;
|
import nu.marginalia.service.ServiceId;
|
||||||
import nu.marginalia.service.module.ServiceConfigurationModule;
|
import nu.marginalia.service.module.ServiceConfigurationModule;
|
||||||
@ -29,6 +30,9 @@ public class IndexMain extends MainClass {
|
|||||||
new ServiceConfigurationModule(ServiceId.Index)
|
new ServiceConfigurationModule(ServiceId.Index)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Ensure that the service registry is initialized early
|
||||||
|
injector.getInstance(ServiceRegistryIf.class);
|
||||||
|
|
||||||
injector.getInstance(NodeStatusWatcher.class);
|
injector.getInstance(NodeStatusWatcher.class);
|
||||||
|
|
||||||
injector.getInstance(IndexMain.class);
|
injector.getInstance(IndexMain.class);
|
||||||
|
@ -3,7 +3,7 @@ plugins {
|
|||||||
|
|
||||||
id 'application'
|
id 'application'
|
||||||
id 'jvm-test-suite'
|
id 'jvm-test-suite'
|
||||||
id 'com.google.cloud.tools.jib' version '3.4.1'
|
id 'com.google.cloud.tools.jib' version '3.4.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
|
@ -4,6 +4,7 @@ import com.google.inject.Guice;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import nu.marginalia.service.MainClass;
|
import nu.marginalia.service.MainClass;
|
||||||
|
import nu.marginalia.service.discovery.ServiceRegistryIf;
|
||||||
import nu.marginalia.service.module.ServiceDiscoveryModule;
|
import nu.marginalia.service.module.ServiceDiscoveryModule;
|
||||||
import nu.marginalia.service.ServiceId;
|
import nu.marginalia.service.ServiceId;
|
||||||
import nu.marginalia.service.module.ServiceConfigurationModule;
|
import nu.marginalia.service.module.ServiceConfigurationModule;
|
||||||
@ -28,6 +29,9 @@ public class QueryMain extends MainClass {
|
|||||||
new ServiceConfigurationModule(ServiceId.Query)
|
new ServiceConfigurationModule(ServiceId.Query)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Ensure that the service registry is initialized early
|
||||||
|
injector.getInstance(ServiceRegistryIf.class);
|
||||||
|
|
||||||
injector.getInstance(QueryMain.class);
|
injector.getInstance(QueryMain.class);
|
||||||
injector.getInstance(Initialization.class).setReady();
|
injector.getInstance(Initialization.class).setReady();
|
||||||
}
|
}
|
||||||
|
34
code/services-core/single-service-runner/build.gradle
Normal file
34
code/services-core/single-service-runner/build.gradle
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
id 'application'
|
||||||
|
id 'jvm-test-suite'
|
||||||
|
}
|
||||||
|
|
||||||
|
application {
|
||||||
|
mainClass = 'nu.marginalia.SingleService'
|
||||||
|
applicationName = 'marginalia'
|
||||||
|
applicationDefaultJvmArgs = [ "--enable-preview" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.distZip.enabled = false
|
||||||
|
|
||||||
|
java {
|
||||||
|
toolchain {
|
||||||
|
languageVersion.set(JavaLanguageVersion.of(rootProject.ext.jvmVersion))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply from: "$rootProject.projectDir/srcsets.gradle"
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation project(':code:services-core:query-service')
|
||||||
|
implementation project(':code:services-core:index-service')
|
||||||
|
implementation project(':code:services-core:control-service')
|
||||||
|
implementation project(':code:services-core:executor-service')
|
||||||
|
|
||||||
|
testImplementation libs.bundles.slf4j.test
|
||||||
|
testImplementation libs.bundles.junit
|
||||||
|
testImplementation libs.mockito
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,112 @@
|
|||||||
|
package nu.marginalia;
|
||||||
|
|
||||||
|
/** Springboard for launching services outside of docker */
|
||||||
|
public class SingleService {
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
if (!configure(args)) {
|
||||||
|
System.out.println("Usage: SingleService <service> bind-address:bind-port-http:bind-port-grpc announce-address [args...]");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
requireEnv("ZOOKEEPER_HOSTS", "Comma-separated list of zookeeper hosts");
|
||||||
|
requireEnv("WMSA_HOME", "Path to the install directory of the project");
|
||||||
|
|
||||||
|
String serviceName = args[0];
|
||||||
|
String[] serviceArgs = new String[args.length - 3];
|
||||||
|
System.arraycopy(args, 3, serviceArgs, 0, serviceArgs.length);
|
||||||
|
|
||||||
|
for (var service : Service.values()) {
|
||||||
|
if (service.name.equals(serviceName)) {
|
||||||
|
service.run(serviceArgs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void requireEnv(String env, String desc) {
|
||||||
|
if (System.getenv(env) == null) {
|
||||||
|
throw new IllegalArgumentException("Missing environment variable: " + env + " - " + desc);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Found environment variable: " + env + " = " + System.getenv(env));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Set system properties for the address and ports for the service.
|
||||||
|
*
|
||||||
|
* @return true if the configuration was successful
|
||||||
|
* */
|
||||||
|
private static boolean configure(String[] args) {
|
||||||
|
if (args.length < 3)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
final String bindAddress_http_grpc = args[1];
|
||||||
|
final String announceAddress = args[2];
|
||||||
|
|
||||||
|
final String[] bindParts = bindAddress_http_grpc.split(":");
|
||||||
|
if (bindParts.length < 3)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
String bindAddress = bindParts[0];
|
||||||
|
|
||||||
|
int httpPort = Integer.parseInt(bindParts[1]);
|
||||||
|
int grpcPort = Integer.parseInt(bindParts[2]);
|
||||||
|
|
||||||
|
System.out.println(STR."""
|
||||||
|
Configuring service with bind address: \{bindAddress}
|
||||||
|
http port: \{httpPort}
|
||||||
|
grpc port: \{grpcPort}
|
||||||
|
announce address: \{announceAddress}
|
||||||
|
""");
|
||||||
|
|
||||||
|
System.setProperty("service.bind-address", bindAddress);
|
||||||
|
System.setProperty("service.http-port", Integer.toString(httpPort));
|
||||||
|
System.setProperty("service.grpc-port", Integer.toString(grpcPort));
|
||||||
|
System.setProperty("service.host", announceAddress);
|
||||||
|
|
||||||
|
// By default, disable prometheus metrics
|
||||||
|
if (System.getProperty("service.prometheus-port") == null) {
|
||||||
|
System.setProperty("service.prometheus-port", "-1");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (NumberFormatException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Service {
|
||||||
|
IndexService("index", "nu.marginalia.index.IndexMain"),
|
||||||
|
ControlService("control", "nu.marginalia.control.ControlMain"),
|
||||||
|
ExecutorService("executor", "nu.marginalia.executor.ExecutorMain"),
|
||||||
|
QueryService("query", "nu.marginalia.query.QueryMain"),
|
||||||
|
;
|
||||||
|
|
||||||
|
public final String name;
|
||||||
|
public final String className;
|
||||||
|
|
||||||
|
Service(String name, String className) {
|
||||||
|
this.name = name;
|
||||||
|
this.className = className;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Call the main method of the service class */
|
||||||
|
public void run(String[] args) {
|
||||||
|
try {
|
||||||
|
// Use reflection to call the main method of the service class to avoid
|
||||||
|
// loading all classes at startup time, which would invoke a bunch of contradictory
|
||||||
|
// static initializers
|
||||||
|
|
||||||
|
Class<?> clazz = Class.forName(className);
|
||||||
|
clazz.getMethod("main", String[].class).invoke(null, (Object) args);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -3,7 +3,7 @@ plugins {
|
|||||||
|
|
||||||
id 'application'
|
id 'application'
|
||||||
id 'jvm-test-suite'
|
id 'jvm-test-suite'
|
||||||
id 'com.google.cloud.tools.jib' version '3.4.1'
|
id 'com.google.cloud.tools.jib' version '3.4.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
|
@ -5,6 +5,7 @@ include 'code:services-core:assistant-service'
|
|||||||
include 'code:services-core:control-service'
|
include 'code:services-core:control-service'
|
||||||
include 'code:services-core:query-service'
|
include 'code:services-core:query-service'
|
||||||
include 'code:services-core:executor-service'
|
include 'code:services-core:executor-service'
|
||||||
|
include 'code:services-core:single-service-runner'
|
||||||
|
|
||||||
include 'code:services-application:search-service'
|
include 'code:services-application:search-service'
|
||||||
include 'code:services-application:api-service'
|
include 'code:services-application:api-service'
|
||||||
|
Loading…
Reference in New Issue
Block a user