#!/command/execlineb

# This is my svstopsync script, written in execlineb syntax.
# It shows an example of complex block management.
# execlineb makes it easy.

import PATH
export PATH /package/host/skarnet.org/skaembutils/command:${PATH}

forbacktick -pd "" i { dollarat -d "" }
{
  backtick -n name { basename $i }
  if { test \\\\${name} != svlog } # substitutes and leaves 1 backslash
  cd /service/${name}
  foreground { minrmrf /service/${name} }
  foreground { if { svok . } svc -xd . }
  ifthenelse { if { test -d log } svok log }
  {
    foreground
    {
      if -n { npt-svwaitexit 30 . }
      foreground { svc -k . }
      npt-svwaitexit 5 .
    }
    foreground { svc -xd log }
    if -n { npt-svwaitexit 30 log }
    foreground { svc -k log }
    npt-svwaitexit 5 log
  }
  {
    if -n { npt-svwaitexit 30 . }
    foreground { svc -k . }
    npt-svwaitexit 5 .
  }
}
wait { }
