krallin / tini

A tiny but valid `init` for containers
MIT License
9.82k stars 507 forks source link

Using tini with java process #134

Closed namedgraph closed 5 years ago

namedgraph commented 5 years ago

Hi,

I made my entrypoint such:

ENTRYPOINT ["/tini", "-vvv", "--", "/usr/src/.../entrypoint.sh"]

Now the entrypoint invokes a Java process:

java -jar xxx.jar

java process cannot be killed by killing the container using Ctrl+C, and adding tini to ENTRYPOINT does not make any difference. Can tini help in this situation or do I need another solution?

Help is appreciated.

krallin commented 5 years ago

Can you share your entrypoint code?

You probably want something like this instead to make sure the bash process doesn't stick around to receive (and essentially blackhole) the signals Tini forwards:

exec java -jar xxx.jar
namedgraph commented 5 years ago

Smth like this:

java -jar $@" > "$json_xml" # can't use exec because the container will quit after script is done
xmllint --schema ./xsd/json2xml.xsd --noout "$json_xml" >&2
rm "$json_xml"

I tried exec, the problem is that I have some cleanup code after the Java process, but exec exits the whole script no matter success or error, and that code never gets executed.

krallin commented 5 years ago

Thanks. That's not going to work right now with Tini, but there is a fork that allows for post-processing commands, have a look at that: https://github.com/krallin/tini/pull/129

I haven't had time to figure out whether this makes sense to incorporate in Tini and to do so, so you'll have to build this yourself, but I think that's what you need here.

krallin commented 5 years ago

Alternatively, you might want to try passing -g to Tini to signal the entire process group (i.e. bash + java) :smile:.

namedgraph commented 5 years ago

I went with this kind of solution: https://stackoverflow.com/a/29890106/1003113