From: Mathieu Baudier Date: Mon, 21 Feb 2022 10:31:13 +0000 (+0100) Subject: Systemd deployment X-Git-Tag: argeo-commons-2.3.5~8 X-Git-Url: https://git.argeo.org/?p=lgpl%2Fargeo-commons.git;a=commitdiff_plain;h=dea32138f55d1c80f75515793ed15be0e89e6d61 Systemd deployment --- diff --git a/org.argeo.init/src/org/argeo/init/Service.java b/org.argeo.init/src/org/argeo/init/Service.java index 9a01cffed..ef65d02cf 100644 --- a/org.argeo.init/src/org/argeo/init/Service.java +++ b/org.argeo.init/src/org/argeo/init/Service.java @@ -6,6 +6,7 @@ import java.util.Map; import org.argeo.init.osgi.OsgiRuntimeContext; +/** Configure and launch an Argeo service. */ public class Service implements Runnable, AutoCloseable { private final static Logger log = System.getLogger(Service.class.getName()); @@ -29,8 +30,10 @@ public class Service implements Runnable, AutoCloseable { // shutdown on exit Runtime.getRuntime().addShutdownHook(new Thread(() -> { try { - if (Service.runtimeContext != null) + if (Service.runtimeContext != null) { Service.runtimeContext.close(); + //Service.runtimeContext.waitForStop(0); + } } catch (Exception e) { e.printStackTrace(); System.exit(1); @@ -38,13 +41,18 @@ public class Service implements Runnable, AutoCloseable { }, "Runtime shutdown")); Map config = new HashMap<>(); + config.put("osgi.framework.useSystemProperties", "true"); +// for (Object key : System.getProperties().keySet()) { +// config.put(key.toString(), System.getProperty(key.toString())); +// log.log(Logger.Level.DEBUG, key + "=" + System.getProperty(key.toString())); +// } try { - try (OsgiRuntimeContext osgiRuntimeContext = new OsgiRuntimeContext(config)) { + try (OsgiRuntimeContext osgiRuntimeContext = new OsgiRuntimeContext((Map) config)) { osgiRuntimeContext.run(); Service.runtimeContext = osgiRuntimeContext; Service.runtimeContext.waitForStop(0); } catch (NoClassDefFoundError e) { - try (StaticRuntimeContext staticRuntimeContext = new StaticRuntimeContext(config)) { + try (StaticRuntimeContext staticRuntimeContext = new StaticRuntimeContext((Map) config)) { staticRuntimeContext.run(); Service.runtimeContext = staticRuntimeContext; Service.runtimeContext.waitForStop(0); diff --git a/org.argeo.init/src/org/argeo/init/a2/FsA2Source.java b/org.argeo.init/src/org/argeo/init/a2/FsA2Source.java index 949dbdf81..067537d59 100644 --- a/org.argeo.init/src/org/argeo/init/a2/FsA2Source.java +++ b/org.argeo.init/src/org/argeo/init/a2/FsA2Source.java @@ -43,27 +43,28 @@ public class FsA2Source extends AbstractProvisioningSource implements A2Source { String ext = moduleFileName.substring(lastDot + 1); if (!"jar".equals(ext)) continue modules; - String moduleName = moduleFileName.substring(0, lastDot); - if (moduleName.endsWith("-SNAPSHOT")) - moduleName = moduleName.substring(0, moduleName.length() - "-SNAPSHOT".length()); - int lastDash = moduleName.lastIndexOf('-'); - String versionStr = moduleName.substring(lastDash + 1); - String componentName = moduleName.substring(0, lastDash); +// String moduleName = moduleFileName.substring(0, lastDot); +// if (moduleName.endsWith("-SNAPSHOT")) +// moduleName = moduleName.substring(0, moduleName.length() - "-SNAPSHOT".length()); +// int lastDash = moduleName.lastIndexOf('-'); +// String versionStr = moduleName.substring(lastDash + 1); +// String componentName = moduleName.substring(0, lastDash); // if(versionStr.endsWith("-SNAPSHOT")) { // versionStr = readVersionFromModule(modulePath); // } Version version; - try { +// try { +// version = new Version(versionStr); +// } catch (Exception e) { + String versionStr = readVersionFromModule(modulePath); + String componentName = readSymbolicNameFromModule(modulePath); + if (versionStr != null) { version = new Version(versionStr); - } catch (Exception e) { - versionStr = readVersionFromModule(modulePath); - if (versionStr != null) { - version = new Version(versionStr); - } else { - OsgiBootUtils.debug("Ignore " + modulePath + " (" + e.getMessage() + ")"); - continue modules; - } + } else { + OsgiBootUtils.debug("Ignore " + modulePath + " since version cannot be found"); + continue modules; } +// } A2Component component = contribution.getOrAddComponent(componentName); A2Module module = component.getOrAddModule(version, modulePath); if (OsgiBootUtils.isDebug()) diff --git a/org.argeo.init/src/org/argeo/init/logging/ThinLogging.java b/org.argeo.init/src/org/argeo/init/logging/ThinLogging.java index cdcabcb03..e02dae0b4 100644 --- a/org.argeo.init/src/org/argeo/init/logging/ThinLogging.java +++ b/org.argeo.init/src/org/argeo/init/logging/ThinLogging.java @@ -274,6 +274,8 @@ class ThinLogging implements Consumer> { // NOTE: this is the method called when logging a plain message without // exception, so it should be considered as a format only when args are not null + if (format.contains("{}"))// workaround for weird Jetty formatting + params = null; String msg = params == null ? format : MessageFormat.format(format, params); publisher.log(this, level, bundle, msg, now, thread, (Throwable) null, findCallLocation(level, thread)); } @@ -358,7 +360,8 @@ class ThinLogging implements Consumer> { logEntry.put(KEY_THREAD, thread.getName()); // should be unmodifiable for security reasons - submit(Collections.unmodifiableMap(logEntry)); + if (!isClosed()) + submit(Collections.unmodifiableMap(logEntry)); } } diff --git a/org.argeo.init/src/org/argeo/init/osgi/OsgiRuntimeContext.java b/org.argeo.init/src/org/argeo/init/osgi/OsgiRuntimeContext.java index 7f44f6b27..6c3e40ce5 100644 --- a/org.argeo.init/src/org/argeo/init/osgi/OsgiRuntimeContext.java +++ b/org.argeo.init/src/org/argeo/init/osgi/OsgiRuntimeContext.java @@ -73,23 +73,30 @@ public class OsgiRuntimeContext implements RuntimeContext { } public void stop(BundleContext bundleContext) { - if (loggingConfigurationSr != null) - loggingConfigurationSr.unregister(); - if (logEntryPublisherSr != null) - logEntryPublisherSr.unregister(); - +// if (loggingConfigurationSr != null) +// try { +// loggingConfigurationSr.unregister(); +// } catch (Exception e) { +// // silent +// } +// if (logEntryPublisherSr != null) +// try { +// logEntryPublisherSr.unregister(); +// } catch (Exception e) { +// // silent +// } } @Override public void waitForStop(long timeout) throws InterruptedException { if (framework == null) throw new IllegalStateException("Framework is not initialised"); - stop(framework.getBundleContext()); framework.waitForStop(timeout); } @Override public void close() throws Exception { + stop(framework.getBundleContext()); if (framework != null) framework.stop(); } diff --git a/sdk/deploy/argeo-init/usr/share/argeo/jvm.args b/sdk/deploy/argeo-init/usr/share/argeo/jvm.args index 1159f4c90..27561e3a2 100644 --- a/sdk/deploy/argeo-init/usr/share/argeo/jvm.args +++ b/sdk/deploy/argeo-init/usr/share/argeo/jvm.args @@ -1 +1 @@ --cp /usr/share/a2/org.argeo.tp.eclipse.equinox/org.eclipse.osgi.3.17.jar -jar /usr/share/a2/org.argeo.cms/org.argeo.init.2.3.jar \ No newline at end of file +-cp /usr/share/a2/org.argeo.tp.eclipse.equinox/org.eclipse.osgi.3.17.jar:/usr/share/a2/org.argeo.cms/org.argeo.init.2.3.jar org.argeo.init.Service \ No newline at end of file