Coder Social home page Coder Social logo

Comments (11)

glerchundi avatar glerchundi commented on August 22, 2024

Hei @smebberson, great explanation! i think -n and -eq can be rewritten into just -ne:

#!/usr/bin/execlineb -S0
if { s6-test ${1} -ne 0 }
if { s6-test ${1} -ne 256 }

s6-svscanctl -t /var/run/s6/services

WDYT?

from s6-overlay.

smebberson avatar smebberson commented on August 22, 2024

@glerchundi, yeah, that works too.

Can you confirm the logic is correct though, in moving away from checking $# to checking ${1} on the first line?

from s6-overlay.

glerchundi avatar glerchundi commented on August 22, 2024

hi @smebberson,

if { s6-test $# -ne 0 } doesn't hurt, is just a sanity check and as far as I know it does nothing because finish always will be run with parameters.

if { s6-test ${1} -ne 0 } means two things, your process died abnormally or it was signaled by the supervisor. So in this moment you cannot assure why was ./finish run.

if { s6-test ${1} -ne 256 } means that ./finish was run because process exited.

So in this case, s6-svscanctl will be called if your process exited abnormally but was not called by the supervisor. That means that your container will be kept running even if you call it with docker stop. Is that what you really want?

from s6-overlay.

smebberson avatar smebberson commented on August 22, 2024

@glerchundi, if s6 was signalled (i.e. docker stop, or CTRL+C) wouldn't s6 bring down the container anyway (i.e. after the ./finish script has run - it won't restart the service)? I didn't think it was the ./finish scripts responsibility to bring down the container under normal circumstances.

That is why I had if -n { s6-test ${1} -eq 256 }, so that if the container was signalled, the ./finish script would exit without actually firing s6-svscanctl command (think s6 would continue bringing down all containers).

from s6-overlay.

smebberson avatar smebberson commented on August 22, 2024

@glerchundi, I should clarify the purpose of the script is to bring down the container if the process non-zero exited (as opposed to restart the service which is normal s6 operation).

If the container was signalled to stop, or CTRL+C, then I assumed s6 would bring down the container regardless of any services particular ./finish script. Which is why the check for 256 takes place in the script in question - so that it doesn't try to bring down the container twice...

from s6-overlay.

glerchundi avatar glerchundi commented on August 22, 2024

That means that your container will be kept running even if you call it with docker stop. Is that what you really want?

Yep, forget this, you're right.

Just to conclude this, the script would look like this:

#!/usr/bin/execlineb -S1
if { s6-test ${1} -ne 0 }
if { s6-test ${1} -ne 256 }

s6-svscanctl -t /var/run/s6/services

Can you test it for me? I'm going to modify the README accordingly.

from s6-overlay.

smebberson avatar smebberson commented on August 22, 2024

@glerchundi, yep, I can confirm that works! Great.

from s6-overlay.

jprjr avatar jprjr commented on August 22, 2024

Hi @smebberson @glerchundi - I've updated the readme. Go ahead and close this, or let me know if I'm ok to close it. Thanks!

from s6-overlay.

glerchundi avatar glerchundi commented on August 22, 2024

as @smebberson opened it, the ball is in your court

from s6-overlay.

smebberson avatar smebberson commented on August 22, 2024

Sorry guys. This all looks great! Thank you.

from s6-overlay.

agners avatar agners commented on August 22, 2024

This exits the finish script (and thus restarts the service) when the process experience a segmentation fault (e.g. gets terminated by the SIGSEGV signal). This seems to contradict what the title of the issue is saying: The goal is to bring down the container if the supervised processes crashes... For that particular case, a more involved script is necessary.

It seems the goal of if { s6-test ${1} -ne 256 } is to avoid the finish script taking down the service which is in the process of being taken down by the supervisor. The default signal to take down a service is SIGTERM.

So I came up with the following extension which excludes SIGTERM (15) but makes sure the container exits if the main process exited by any other signal (such as SIGSEGV, SIGILL etc.). The second argument passed to the finish script is the signal received by the process.

#!/usr/bin/execlineb -S1
if { s6-test ${1} -ne 0 }
ifelse { s6-test ${1} -ne 256 }
  if { s6-test ${2} -ne 15 }
  s6-svscanctl -t /var/run/s6/services
}

s6-svscanctl -t /var/run/s6/services

Inspiration from #320 (comment)

from s6-overlay.

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.