Introduce jbin
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 29 May 2023 08:29:14 +0000 (10:29 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 29 May 2023 08:29:14 +0000 (10:29 +0200)
usr/jbin/.classpath [new file with mode: 0644]
usr/jbin/.gitignore [new file with mode: 0644]
usr/jbin/.project [new file with mode: 0644]
usr/jbin/META-INF/MANIFEST.MF [new file with mode: 0644]
usr/jbin/Makefile [new file with mode: 0644]
usr/jbin/build.properties [new file with mode: 0644]
usr/jbin/src/FREEdInit.java [new file with mode: 0644]

diff --git a/usr/jbin/.classpath b/usr/jbin/.classpath
new file mode 100644 (file)
index 0000000..81fe078
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
+       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/usr/jbin/.gitignore b/usr/jbin/.gitignore
new file mode 100644 (file)
index 0000000..411d6c1
--- /dev/null
@@ -0,0 +1,3 @@
+/bin/
+/src/*
+!/src/*.java
\ No newline at end of file
diff --git a/usr/jbin/.project b/usr/jbin/.project
new file mode 100644 (file)
index 0000000..dfb0678
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>freed-jbin</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.ManifestBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.SchemaBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.pde.PluginNature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+       </natures>
+</projectDescription>
diff --git a/usr/jbin/META-INF/MANIFEST.MF b/usr/jbin/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..8b35d9a
--- /dev/null
@@ -0,0 +1,7 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Freed-jbin
+Bundle-SymbolicName: freed-jbin
+Bundle-Version: 1.0.0.qualifier
+Automatic-Module-Name: freed.jbin
+Bundle-RequiredExecutionEnvironment: JavaSE-17
diff --git a/usr/jbin/Makefile b/usr/jbin/Makefile
new file mode 100644 (file)
index 0000000..e748529
--- /dev/null
@@ -0,0 +1,15 @@
+# GNU coding standards
+prefix ?= /usr/local
+exec_prefix ?= $(prefix)
+sbindir ?= $(exec_prefix)/sbin
+
+all:
+       cp src/FREEdInit.java src/freed-init
+       sed -i '1!b;s|//#!|#!|' src/freed-init
+
+clean:
+       $(RM) src/freed-init
+
+install:
+       cp src/freed-init $(DESTDIR)$(sbindir)
+       chmod u+x $(DESTDIR)$(sbindir)/freed-init
diff --git a/usr/jbin/build.properties b/usr/jbin/build.properties
new file mode 100644 (file)
index 0000000..5d082ea
--- /dev/null
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .
+additional.bundles = org.argeo.init
diff --git a/usr/jbin/src/FREEdInit.java b/usr/jbin/src/FREEdInit.java
new file mode 100644 (file)
index 0000000..53e0e61
--- /dev/null
@@ -0,0 +1,53 @@
+//#! /usr/bin/java --source 17 -cp /usr/local/share/a2/osgi/equinox/org.argeo.tp.osgi/org.eclipse.osgi.3.18.jar:/usr/local/share/a2/org.argeo.cms/org.argeo.init.2.3.jar -Dosgi.configuration.cascaded=true -Dosgi.sharedConfiguration.area=/etc/freed -Dosgi.sharedConfiguration.area.readOnly=true -Dosgi.configuration.area=/var/lib/freed/state/ -Dosgi.instance.area=/var/lib/freed/data/ -Dosgi.console=true
+
+import java.lang.management.ManagementFactory;
+
+import org.argeo.init.Service;
+
+import jdk.jshell.tool.JavaShellToolBuilder;
+import sun.misc.Signal;
+
+public class FREEdInit {
+       public static void main(String... args) {
+               final long pid = ProcessHandle.current().pid();
+               System.out.println("FREEd Init daemon starting with pid " + pid + "...");
+               System.out.println(System.getProperty("user.dir"));
+               System.out.println(System.getProperty("user.name"));
+               System.out.println(System.getProperty("user.home"));
+               System.out.flush();
+
+               Signal.handle(new Signal("TERM"), (signal) -> {
+                       System.out.println("SIGTERM caught");
+                       System.exit(0);
+               });
+               Signal.handle(new Signal("INT"), (signal) -> {
+                       System.out.println("SIGINT caught");
+                       System.exit(0);
+               });
+               Signal.handle(new Signal("HUP"), (signal) -> {
+                       System.out.println("SIGHUP caught");
+                       System.exit(0);
+               });
+
+               if (args.length > 0 && ("1".equals(args[0]) //
+                               || "single".equals(args[0]) //
+                               || "emergency".equals(args[0]))) {
+                       // TODO check if we can remove dependency to management
+                       String classpath = ManagementFactory.getRuntimeMXBean().getClassPath();
+                       String feedbackMode = "concise";
+                       // TODO --startup script
+                       JavaShellToolBuilder builder = JavaShellToolBuilder.builder();
+                       try {
+                               builder.start("--execution", "direct", "--class-path", classpath, "--feedback", feedbackMode);
+                       } catch (Exception e) {
+                               e.printStackTrace();
+                               System.err.flush();
+                               System.exit(1);
+                               return;
+                       }
+
+               } else {
+                       Service.main(args);
+               }
+       }
+}