Systemd deployment
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 21 Feb 2022 10:31:13 +0000 (11:31 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 21 Feb 2022 10:31:13 +0000 (11:31 +0100)
org.argeo.init/src/org/argeo/init/Service.java
org.argeo.init/src/org/argeo/init/a2/FsA2Source.java
org.argeo.init/src/org/argeo/init/logging/ThinLogging.java
org.argeo.init/src/org/argeo/init/osgi/OsgiRuntimeContext.java
sdk/deploy/argeo-init/usr/share/argeo/jvm.args

index 9a01cffed555f88eaf081cd7bcb3d86245f61f68..ef65d02cf14f46b35c805dc5ca5a8574c8136d63 100644 (file)
@@ -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<String, String> 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<String, String>) 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<String, String>) config)) {
                                        staticRuntimeContext.run();
                                        Service.runtimeContext = staticRuntimeContext;
                                        Service.runtimeContext.waitForStop(0);
index 949dbdf81dec07b0753b2009c753a2fc02c2564f..067537d5911d24bddd7fe8fa2bec73688bcc85de 100644 (file)
@@ -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())
index cdcabcb03060902a54a7698d08cc3ec49d51596a..e02dae0b4af53282017ef368844b78884db7db01 100644 (file)
@@ -274,6 +274,8 @@ class ThinLogging implements Consumer<Map<String, Object>> {
 
                        // 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<Map<String, Object>> {
                        logEntry.put(KEY_THREAD, thread.getName());
 
                        // should be unmodifiable for security reasons
-                       submit(Collections.unmodifiableMap(logEntry));
+                       if (!isClosed())
+                               submit(Collections.unmodifiableMap(logEntry));
                }
 
        }
index 7f44f6b2746dccc914312180b493d56e7328ce3c..6c3e40ce57eadf8189f9aa8c8687c4c3d2c1c27e 100644 (file)
@@ -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();
        }
index 1159f4c90c8ebfa70039b92c8f9104e141a5dac2..27561e3a27716b4f3fbe5e155d5b3548a69908b6 100644 (file)
@@ -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