chrisdchristo / capsule-maven-plugin

Capsule Maven Plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Prepend `execheader.sh` / `trampoline-execheader.sh` to really executables / trampoline capsules resp.

circlespainter opened this issue · comments

Capsule actually builds special "really executable capsules" but the plugin just prints the single-process command line (as documented). Shouldn't it work like Capsule?

Sample project: https://github.com/circlespainter/capsule-1.0-sample

ok will have a look

Away at the moment, will aim to fix on oct5.

As far as I understand, the plugin does what Capsule specifies. See here. We have the <chmod>true</chmod> flag which will create a bash executable which can be run like ./my-capsule-fat.x. We also have the <trampoline>true</trampoline> which will create an executable that does as you say; print out the command (this is so it can be run as a single process).

This follows the (Capsule documentation)[http://www.capsule.io/user-guide/#really-executable-capsules]. It follows the capsule/execheader.sh and the capsule/trampoline-execheader.sh that Capsule has.

I'll have another try but my (possibly wrong) understanding is that execheader.sh is the script to be prepended to the JAR for it to be a "really executable" one and tampoline-execheader.sh has to be used in the same way and is the basically same, so it will actually start the capsule (not just print the command) but will replace the parent process (so that only one process is running for any given capsule). Is that correct?

Yes, essentially the 'really executable jar' is made by prepending the execheader.sh to the jar thus turning the file into a script (with the jar embedded in binary format). When executed, the script will launch a separate process to run the jar. So this means there will be two processes running (one for when you executed the script and one for the execution of the jar). And they are linked - so if you kill one, it also kills the other. For most cases this isn't a problem.

The idea of the 'trampoline' is to avoid having the two processes and just have one. But the only way to do this is to execute the jar command directly. And the only way to execute the jar command directly, is to know it (and this is long, what with all the parameters etc)! So what we do is, create a script that will output the full command to run the jar (we prepend the trampoline-execheader.sh). We then copy the full outputted command and run it, and thus will be run in one process.

This is explained here by @pron.

Right, so this is what the Maven plugin does as well? Because it looks to me (from the docs and from a test I did, even if it was quite some time ago) like the capsule built by the plugin just prints the command to stdout, while trampoline-execheader.sh also executes it (from Ron's explanation and from its code).

Yes for the trampoline concept, the plugin will just print out the command. As explained before this is as far as I understood was the only way to do the whole single process launch. I was going by what @pron explained on the google group. I'm unaware that the trampoline-execheader.sh or any code within Capsule can execute directly. Please show me otherwise, or perhaps we can ping @pron about this.

See the Capsule code here which seems to just output the command if the trampoline flag has been passed to Capsule.

I think trampoline-execheader.sh should be prepended to the capsule JAR during the build (so ideally the plugin would do it). Then the following code in it:

exec `java -Dcapsule.trampoline -jar $0` "$@"

would execute the capsule JAR through java with the special flag -Dcapsule.trampoline. This flag will indeed tell Capsule to setup everything but not to launch the application process and instead to just print its full command line and exit.
Since Capsule is run by the script through backticks, its output will be inlined and the shell will then exec the application command line directly.

The original issue I created is probably misleading and it should rephrased as a feature request (hence the title change). Capsule doesn't build capsules, the build tool does that, and the "really executable" / "trampoline" scripts are meant to be prepended to the JAR, so I think it would be nice for the build plugins to it directly.

"I think trampoline-execheader.sh should be prepended to the capsule JAR during the build (so ideally the plugin would do it). Then the following code exec java -Dcapsule.trampoline -jar $0 "$@" would execute the capsule JAR through java with the special flag -Dcapsule.trampoline. This flag will indeed tell Capsule to setup everything but not to launch the application process and instead to just print its full command line and exit."

^ YES that's exactly what the plugin does right now when you have the <trampoline>true</trampoline> flag set. The plugin produces the above in the form of a .tx file (for trampoline executable).

So to summarise:

(1) Set the <chmod>true</chmod> flag.

The plugin will build the capsule jar first. Then it will create an executable bash script by concatenating the execheader.sh and the capsule jar into a single file. The plugin will output this file as a .x file (for executable). This can then be executed as a normal bash script. This is essentially a 'really executable jar'. Note that this will spawn two processes (as described in my previous comment).

(2) Set the <trampoline>true</trampoline> flag.

The plugin will build the capsule jar first. Then it will create an executable bash script by concatenating the trampoline-execheader.sh and the capsule jar into a single file. The plugin will output this file as a .tx file (for trampoline executable). This can then be executed as a normal bash script. This trampoline-execheader.sh part of the file contains the following code:

exec java -Dcapsule.trampoline -jar $0 "$@"

which will execute the capsule JAR through java with the special flag -Dcapsule.trampoline. This flag will indeed tell Capsule to setup everything but not to launch the application process and instead to just print its full command line and exit.

So once the full command has been output, the idea is you're supposed to copy it and run it.

The plugin does exactly all of the above already.

Alright, so the .tx executable should indeed trampoline the capsule. I'll have another look as I opened this issue long time ago and possibly I did some mistakes myself while trying. You can close it in the meanwhile, thanks for support.