#!/bin/execlineb -P
fdmove -c 2 1

define envdir "/etc/sysconfig/openvpn"
s6-envdir -I  $envdir

importas -D "/etc/openvpn" ovpndir OPENVPN_DIR
importas -D "/run/openvpn" rundir  OPENVPN_RUNDIR

define conndir  "${ovpndir}/conns"

if { s6-mkdir -p $rundir }
if { s6-rmrf "${rundir}/service" }
if { cp -a "${ovpndir}/run-image/service" $rundir }

foreground {
   pipeline { s6-ls $conndir }
   forstdin -p CONN
      importas -u conn CONN
      /etc/rc.d/rc.openvpn add $conn
}

if { s6-echo "starting openvpn supervisor on ${rundir}/service" }

# Attach a supervise tree to our parent supervise branch
cd ${rundir}/service
s6-svscan -d3 -St0
