supervision - discussion about system services, daemon supervision, init, runlevel management, and tools such as s6 and runit
 help / color / mirror / Atom feed
* s6-svscan shutdown notification
@ 2022-02-24  1:27 Jan-willem De Bleser
  2022-02-24  5:04 ` Laurent Bercot
  0 siblings, 1 reply; 5+ messages in thread
From: Jan-willem De Bleser @ 2022-02-24  1:27 UTC (permalink / raw)
  To: supervision

[-- Attachment #1: Type: text/plain, Size: 1361 bytes --]

Hi,

What's the cleanest way to wait on s6-svscan to shut down after issuing of
a SIGTERM (say s6 via-svscanctl -t)?

I'm using s6 to manage daemons in FreeBSD jails, and am trying to work out
the cleanest way to shut things down. I want to use the built-in 'jail'
command for this since it takes care of host operations like unmounting the
jail filesystems and recovering/freeing network interfaces, but in and of
itself it just issues a SIGKILL inside the jail. It can optionally run a
shutdown script, say one that calls "s6-svscanctl -t", but I need some way
to delay the ending of that script until the supervision tree has actually
shut down: some of the managed processes will need to flush data to disk.

Looking at the documentation, my only option appears to be to check if the
return code of s6-svscanctl is 100, or maybe to monitor for the existence
of .s6-svscan/control (not sure if it's removed on exit). Are there any
other ways to monitor s6-svscan?

Is the communication protocol between s6-svscanctl and s6-svscan via
.s6-svscan/control documented anywhere? These jails are service jails with
no shells installed, so if I have to check for a return code of exactly 100
then I'll have to write a specific tool for that, at which point it may be
better for me to write a 'scanwait' tool of some sort that just checks for
existence.

Cheers,
Jw

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: s6-svscan shutdown notification
  2022-02-24  1:27 s6-svscan shutdown notification Jan-willem De Bleser
@ 2022-02-24  5:04 ` Laurent Bercot
  2022-02-24  5:16   ` Jan-willem De Bleser
  0 siblings, 1 reply; 5+ messages in thread
From: Laurent Bercot @ 2022-02-24  5:04 UTC (permalink / raw)
  To: supervision


>What's the cleanest way to wait on s6-svscan to shut down after issuing of
>a SIGTERM (say s6 via-svscanctl -t)?

  Be its parent, and wait for it. :)
  On SIGTERM, s6-svscan will not exit until the supervision tree is
entirely down, so that will work.
  If you're not the parent, then you'll have to wait for a notification
somehow, but that's easy:

  When s6-svscan wants to exit, it doesn't exit right away, but
tries to exec into the .s6-svscan/finish script. So you have a clear
indicator here: when .s6-svscan/finish runs, it means the supervision
tree is down.
  So, for instance, make a finish script that writes a byte in a fifo,
and have your jail shutdown script read on that fifo. Something like:

.s6-svscan/finish:
#!/bin/sh
exec echo > /run/blah/fifo

shutdown script:
#!/bin/sh
...
rm -f /run/blah/fifo
mkfifo /run/blah/fifo
read < /run/blah/fifo &
s6-svscanctl -t /run/service
wait
...

(read on the fifo before running s6-svscanctl, to avoid the small
race condition.)


>Looking at the documentation, my only option appears to be to check if the
>return code of s6-svscanctl is 100, or maybe to monitor for the existence
>of .s6-svscan/control (not sure if it's removed on exit). Are there any
>other ways to monitor s6-svscan?

  Ew. Don't poll.
  Use .s6-svscan/finish to do anything you want to do at s6-svscan
death time.

--
  Laurent


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: s6-svscan shutdown notification
  2022-02-24  5:04 ` Laurent Bercot
@ 2022-02-24  5:16   ` Jan-willem De Bleser
  2022-02-25 16:52     ` Jan Bramkamp
  0 siblings, 1 reply; 5+ messages in thread
From: Jan-willem De Bleser @ 2022-02-24  5:16 UTC (permalink / raw)
  To: supervision

[-- Attachment #1: Type: text/plain, Size: 1722 bytes --]

Not an option to be its parent since there's no persistent supervisor of a
jail's root process, but that script using .s6-svscan/finish should do
nicely. Thanks for the suggestion!

- Jw


On Wed, Feb 23, 2022 at 9:04 PM Laurent Bercot <ska-supervision@skarnet.org>
wrote:

>
> >What's the cleanest way to wait on s6-svscan to shut down after issuing of
> >a SIGTERM (say s6 via-svscanctl -t)?
>
>   Be its parent, and wait for it. :)
>   On SIGTERM, s6-svscan will not exit until the supervision tree is
> entirely down, so that will work.
>   If you're not the parent, then you'll have to wait for a notification
> somehow, but that's easy:
>
>   When s6-svscan wants to exit, it doesn't exit right away, but
> tries to exec into the .s6-svscan/finish script. So you have a clear
> indicator here: when .s6-svscan/finish runs, it means the supervision
> tree is down.
>   So, for instance, make a finish script that writes a byte in a fifo,
> and have your jail shutdown script read on that fifo. Something like:
>
> .s6-svscan/finish:
> #!/bin/sh
> exec echo > /run/blah/fifo
>
> shutdown script:
> #!/bin/sh
> ...
> rm -f /run/blah/fifo
> mkfifo /run/blah/fifo
> read < /run/blah/fifo &
> s6-svscanctl -t /run/service
> wait
> ...
>
> (read on the fifo before running s6-svscanctl, to avoid the small
> race condition.)
>
>
> >Looking at the documentation, my only option appears to be to check if the
> >return code of s6-svscanctl is 100, or maybe to monitor for the existence
> >of .s6-svscan/control (not sure if it's removed on exit). Are there any
> >other ways to monitor s6-svscan?
>
>   Ew. Don't poll.
>   Use .s6-svscan/finish to do anything you want to do at s6-svscan
> death time.
>
> --
>   Laurent
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: s6-svscan shutdown notification
  2022-02-24  5:16   ` Jan-willem De Bleser
@ 2022-02-25 16:52     ` Jan Bramkamp
  2022-02-26 16:12       ` Jan-willem De Bleser
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Bramkamp @ 2022-02-25 16:52 UTC (permalink / raw)
  To: supervision

On 24.02.22 06:16, Jan-willem De Bleser wrote:

> Not an option to be its parent since there's no persistent supervisor of a
> jail's root process, but that script using .s6-svscan/finish should do
> nicely. Thanks for the suggestion!
I use s6-rc on the FreeBSD jail host as well to manage jails with their 
own supervision trees as long running services making the jail 
supervision tree a subtree of the host supervision tree. I prefer to let 
s6-rc handle state transitions instead of using the more limited state 
management support in the jail utility. I use one service bundle per 
jail containing a oneshot to create/destroy a persistent jail and a long 
run depending on the oneshot using jexec to start the supervision 
subtree inside the jail.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: s6-svscan shutdown notification
  2022-02-25 16:52     ` Jan Bramkamp
@ 2022-02-26 16:12       ` Jan-willem De Bleser
  0 siblings, 0 replies; 5+ messages in thread
From: Jan-willem De Bleser @ 2022-02-26 16:12 UTC (permalink / raw)
  To: supervision

[-- Attachment #1: Type: text/plain, Size: 1003 bytes --]

On Fri, Feb 25, 2022 at 8:52 AM Jan Bramkamp <crest@rlwinm.de> wrote:

> I use s6-rc on the FreeBSD jail host as well to manage jails with their
> own supervision trees as long running services making the jail
> supervision tree a subtree of the host supervision tree. I prefer to let
> s6-rc handle state transitions instead of using the more limited state
> management support in the jail utility. I use one service bundle per
> jail containing a oneshot to create/destroy a persistent jail and a long
> run depending on the oneshot using jexec to start the supervision
> subtree inside the jail.
>

I can see the appeal of that, using one-shots to set up the network,
mounts, etc. I don't use s6-rc, but I'll keep it in mind.

However, I realized I've framed the issue incorrectly: I don't care if s6
receives a SIGKILL as long as the supervised processes (including loggers)
have shut down cleanly. I can use elglob/forx/s6-svc -wD to shut everything
down, and just not worry about s6-svscan.

- Jw

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-02-26 16:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-24  1:27 s6-svscan shutdown notification Jan-willem De Bleser
2022-02-24  5:04 ` Laurent Bercot
2022-02-24  5:16   ` Jan-willem De Bleser
2022-02-25 16:52     ` Jan Bramkamp
2022-02-26 16:12       ` Jan-willem De Bleser

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).