supervision - discussion about system services, daemon supervision, init, runlevel management, and tools such as s6 and runit
 help / color / mirror / Atom feed
From: s.karrmann@web.de
To: supervision@list.skarnet.org
Cc: ska-supervision@skarnet.org
Subject: stage2 as a service [was: Some suggestions on old-fashioned usage with s6 2.10.x]
Date: Sun, 31 Jan 2021 08:49:44 +0100	[thread overview]
Message-ID: <trinity-fc950f88-8ff6-4274-9e33-5581b5fdb441-1612079384363@3c-app-webde-bs42> (raw)
In-Reply-To: <embce1c8a5-9a23-4d50-9c6f-900385a7f8ca@elzian>

Dear all,

after Laurents explanation about the supervision tree in stage 2 and 3,
I got the idea to put stage2 completely into a normal supervised service:

> 2021-01-29.16:48
> From: "Laurent Bercot" <ska-supervision@skarnet.org>
> To: "Casper Ti. Vector" <caspervector@gmail.com>, supervision@list.skarnet.org
> Subject: Re: Some suggestions on old-fashioned usage with s6 2.10.x
> 
> [...]
> >There is some non-trivial trade-off: in short, the existence of the
> >supervision tree after stage 2 is by itself a kind of "special case"
> >(eg. search for "careful handling" in [1]).
> 
> I feel like you misinterpreted my meaning.
> The *absence* of a supervision tree after stage 2 is precisely what
> requires careful handling, and runit only works because Linux has
> that peculiarity that kill -9 -1 does not kill the emitter!
> Having a supervision tree in stage 3 actually *helps* with the
> late shutdown procedure: shutdownd dies right after the kill (which
> would make it usable even on a system without the Linux specialcase)
> and is restarted by the supervisor for stage 4.
> [...] 

$ cat /etc/s6/services/s6-rc-up/run 
#! /usr/bin/execlineb -P

s6-envdir /etc/s6/init-env
multisubstitute {
  importas SCANDIR SCANDIR
  importas LIVEDIR LIVEDIR      
  importas COMPILED COMPILED     
  importas RCDEFAULT RCDEFAULT                              
  importas PATH PATH                          
  }
export PATH ${PATH}

# optional:  -- Question: Is this necessary?
  redirfd -w 0 ${SCANDIR}/service/s6-svscan-log/fifo
  # now the catch all logger runs
  fdclose 0

foreground { mkdir -p ${LIVEDIR} }
foreground { s6-rc-init -l ${LIVEDIR}/live -c ${COMPILED} ${SCAN} }
foreground { s6-svc -O . } # don't restart me
foreground { s6-rc -l ${LIVEDIR}/live -t 10000 change ${RCDEFAULT} }
# notify s6-supervise:
fdmove 1 3
foreground { echo "s6-rc ready, stage 2 is up." }
fdclose 1  # -- Question: Is this necessary?
# NB: shutdown should create ./down here, to avoid race conditions
# NB: init must ensure that there is no ./down here at startup.
# That is automatically fulfilled, if copied from a repo to /run/...
### THE END #####################################################################

and my init is:

$ cat /etc/s6/init
#! /usr/bin/execlineb -P
   
cd /
s6-setsid -qb                                         
envfile /etc/s6/init-envfile                                                      
multisubstitute {
  importas SCANDIR SCANDIR
  importas LIVEDIR LIVEDIR      
  importas COMPILED COMPILED     
  importas RCDEFAULT RCDEFAULT                              
  importas PATH PATH                          
  }
export PATH ${PATH}                                                  
             
# stage 1 init as PID=1
 
ifelse -nX                                   
  { # basic initialization
      foreground { # a hooks
        elglob -s locals /etc/s6/init.d/stage1a.d/*
          forx -E local { ${locals} }
            ${local}
      }

      foreground {
        # cf. https://code.dogmap.org./fs/
        elglob fss /fs/*
        forx -E -p fs { ${fss} }
          if { test -e ${fs}/mount-at-boot }
          mount ${fs}/mount # todo fsmount ${fs}
      }

      foreground { # b hooks
        elglob -s locals /etc/s6/init.d/stage1b.d/*
          forx -E local { ${locals} }
            ${local}
      }

    foreground { ln -s /fs/run-s6/mount/${SCANDIR} /run/s6 }
    foreground { mkdir -p /fs/run-s6/mount/${SCANDIR} }
    cp -a ${REPO} ${SCANDIR}
  }
  { # fallback login
    sulogin --force -t 600 # timeout 600 seconds, i.e. 10 minutes.
    # kernel panic
  }

# now the /dev must contain some files, i.e. /dev/null
redirfd -r 0 /dev/null  # useful for testing from a tty, i.e. don't consume input

execline-cd ${SCAN}
# catch all log also for stage 2
# s6-log duplicates it to console
redirfd -wnb 1 ./s6-svscan-log/fifo  # open fifo nonblocking
fdmove -c 2 1                        # copy it
emptyenv -P
exec -c
s6-svscan                         # start service scanner, i.e. PID=1 in stage 2
### THE END #####################################################################

I have three basic services:
- s6-linux-init-early-getty
- s6-rc-up
- s6-svscan-log

Everything else is up to s6-rc. Well, it will be. I'm still moving my Debian from systemd ("black box") to s6...
Also I may switch to s6-linux-init finally.

Kind regards,
Stefan

  reply	other threads:[~2021-01-31  7:49 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-28 10:08 Some suggestions on old-fashioned usage with s6 2.10.x Casper Ti. Vector
2021-01-28 11:09 ` Casper Ti. Vector
2021-01-28 14:05   ` Casper Ti. Vector
2021-01-29  1:41 ` Guillermo
2021-01-29  3:06   ` Casper Ti. Vector
2021-01-29 17:27     ` Guillermo
2021-01-29 17:39       ` Guillermo
     [not found]   ` <YBN7zfp/MmbcHOCF@caspervector>
2021-01-29  9:57     ` Laurent Bercot
2021-01-29 14:33       ` Casper Ti. Vector
     [not found]       ` <YBQcwHN1L/N2dedx@caspervector>
2021-01-29 15:48         ` Laurent Bercot
2021-01-31  7:49           ` s.karrmann [this message]
2021-01-31 10:25             ` stage2 as a service [was: Some suggestions on old-fashioned usage with s6 2.10.x] Laurent Bercot
2021-01-31 20:51               ` stage2 as a service Stefan Karrmann
2021-02-01 10:35                 ` Laurent Bercot
2021-02-15  8:36           ` Some suggestions on old-fashioned usage with s6 2.10.x Casper Ti. Vector
     [not found]           ` <YCoykUYGXVt+BAT9@caspervector>
     [not found]             ` <em949fd937-c7bc-43db-9b49-3cc235b8f2ad@elzian>
2021-02-16  8:53               ` Casper Ti. Vector
     [not found] <YBKNJEuGeYag91Q1@caspervector>
2021-01-28 17:21 ` Laurent Bercot
2021-01-28 19:08   ` Roy Lanek
2021-01-28 19:55   ` Casper Ti. Vector
     [not found]   ` <YBMWuUCUTVjUNinQ@caspervector>
2021-01-29  0:07     ` Laurent Bercot
2021-01-29  2:44       ` Casper Ti. Vector
     [not found]       ` <YBN2p2UkIiP8lMQy@caspervector>
2021-01-29  9:36         ` Laurent Bercot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=trinity-fc950f88-8ff6-4274-9e33-5581b5fdb441-1612079384363@3c-app-webde-bs42 \
    --to=s.karrmann@web.de \
    --cc=ska-supervision@skarnet.org \
    --cc=supervision@list.skarnet.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).