just-containers / s6-overlay

s6 overlay for containers (includes execline, s6-linux-utils & a custom init)
Other
3.73k stars 212 forks source link

Recommended way to exit after oneshot? #581

Closed abatilo closed 4 months ago

abatilo commented 4 months ago

Let's say that I have a oneshot that depends on several longrun services.

I can define all the longrun services and then add the dependencies.d for the oneshot, and once the oneshot is done, I'd like the container to halt and return the exitcode of the oneshot.

I tried having a oneshot like so:

COPY --chmod=700 <<EOF /etc/s6-overlay/s6-rc.d/training/up
#!/command/execlineb -S0
foreground {
  redirfd -w 1 /run/s6-linux-init-container-results/exitcode /bin/sh -c "
echo 'Sleeping...'
sleep 2
echo 'Hello, world!'
"
}
/run/s6/basedir/bin/halt
EOF

But it seems that this always exits with exit code 100 and I'm not sure why?

abatilo commented 4 months ago

Never mind. I never looked up what redirfd does and totally misunderstood what it was doing.