#!/bin/sh

[ -z $SV_RETRYTIME ] && SV_RETRYTIME=1
[ -z $SV_WAITTIME ] && SV_WAITTIME=1

# Check if this service is already up; avoids useless recursion
svisup $1 && exit 0

if [ -d $1/updeps ]; then
  # We have dependencies to check
  
  for DEPENDENCY in $1/updeps/*; do
    # start svup in background so they will run in parallel
    svup $DEPENDENCY &
  done
  
  # Wait for all services to be up
  svwaitup -r $SV_RETRYTIME -s $SV_WAITTIME $1/updeps/* || exit 111
fi

# Ensure that a supervisor is running for this service
# this is postponed to here in order to get more parallelism on boot =)
until svok $1; do sleep $SV_RETRYTIME; done
	
# actually start the service
svc -u $1 || exit 111

exit 0

