#!/bin/execlineb -S0

##
## init the scandir with our base services
##

if { s6-rmrf /var/run/s6/services }
if { s6-hiercopy /etc/s6/services /var/run/s6/services }
if { s6-rmrf /var/run/s6/services/s6-svscan-log }


##
## ensure our vital fifo exists
##

if { s6-rmrf /var/run/s6/services/s6-fdholderd/supervise }
if { s6-mkdir -m 0700 /var/run/s6/services/s6-fdholderd/supervise }
if { s6-rmrf /var/run/s6/services/s6-fdholderd/supervise/control }
if { s6-mkfifo -m 0600 /var/run/s6/services/s6-fdholderd/supervise/control }


##
## fork the "init-stage2" script
##

background
{
  # block until the supervision tree is running
  redirfd -w 3 /var/run/s6/services/s6-fdholderd/supervise/control
  fdclose 3

  # add some environment
  s6-envdir -- /etc/s6/init/env-stage2

  # run the script
  /etc/s6/init-no-catchall/init-stage2 $@
}
unexport !


##
## run the rest of stage 1 with sanitized descriptors
##

redirfd -r 0 /dev/null


##
## start the supervision tree
##

s6-svscan -t0 /var/run/s6/services
