Giter VIP home page Giter VIP logo

Comments (9)

tianon avatar tianon commented on August 19, 2024

Couldn't this be implemented easily with the "timeout" tool without having tini implement this itself?

ie,

$ docker run -it --rm debian:jessie timeout 5s sleep 10
$ echo $?
124
$ docker run -it --rm debian:jessie timeout 10s sleep 5
$ echo $?
0

from tini.

danilobuerger avatar danilobuerger commented on August 19, 2024

Counter example (busybox implementation of timeout):

/ # timeout -t 1 sh -c 'sleep 2 && echo foo &'
/ # foo

Point being: if the child forks & exits, timeout will exit with status 0.

from tini.

yosifkit avatar yosifkit commented on August 19, 2024

Correct, I get that same problem when using timeout -t 1 sh -c 'sleep 2 && echo foo &' on debian. Your example would not run in tini in docker anyway since the process that tini would be tracking would have exited, making tini exit, and thus the container would be destroyed (ie, docker run -it --rm busybox sh -c 'sleep 10 && echo foo &' dies immediately, whether or not I use any combination of tini and timeout).

from tini.

danilobuerger avatar danilobuerger commented on August 19, 2024

Yeah, i have chosen a bad example there. I will think of another one if necessary.

from tini.

krallin avatar krallin commented on August 19, 2024

Hey @danilobuerger , thanks for your suggestion!

So, this feels a bit more involved that I'd intuitively envision Tini supporting (though that doesn't necessarily mean much... intuition can be wrong!)

But, for what it's worth, I'm working on having pre / post commands in #28 that run (as the name implies) before Tini starts your child and after it exits.

I think this feature would let you solve this problem without any additional work in Tini. Just point --pre to an executable file containing the following script (e.g. pre.sh):

#!/bin/sh
sh -c 'sleep 10 && echo "TIMEOUT" && kill -s TERM 1' &

Then, run:

tini --pre pre.sh -- your program goes here

And that should actually work (I've just tested it locally)

(you could use KILL as well, which would kill Tini immediately and not your child, but yield a non-zero exit code just the same — and of course with a little more shell work you can send KILL directly to the child)

What do you think? If you want to try it out, the feature's already coded, so you can re-compile Tini and try it now.

Cheers,

from tini.

krallin avatar krallin commented on August 19, 2024

Now that I think about it, you probably don't even need --pre to do this. Just use this as your ENTRYPOINT instead of using Tini directly:

#!/bin/sh
sh -c 'sleep 10 && echo "TIMEOUT" && kill -s TERM 1' &
exec tini -- sh -c 'sleep 20'

Cheers,

from tini.

danilobuerger avatar danilobuerger commented on August 19, 2024

Actually, never mind. I had an error in my thinking. Everyone else was correct :-).

from tini.

krallin avatar krallin commented on August 19, 2024

Glad you sorted this out then : )

from tini.

danilobuerger avatar danilobuerger commented on August 19, 2024

Just for future reference: @tianon was correct, the timeout will work fine.

from tini.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.