#!/bin/bash
#
# Stop daemontools services (/service directory)
#

TYPE=service
. `dirname $0`/xsync_functions
xsync_setup $*

# Special target 'ALL': if set, we shutdown everything except those in -on
SERVICES=`echo $DIR/$ME.d/*`
ALL=
if [ "$SERVICES" = "$DIR/$ME.d/ALL" ]; then
  SERVICES=`echo /service/*`
  ALL=1
fi

for i in $SERVICES; do
  i=`basename $i`
  # Test for conflicts (but okay if $ALL is set)
  xsync_conflicts $i
  # Test for a bogus ALL
  xsync_check_all $i
  # Turn off
  if [ -L /service/$i ]; then
    CMD="svc -dx /service/$i; rm -f /service/$i"
    if [ "$ECHO" ]; then
      echo $CMD
    else
      echo "Disabling service $i: $CMD"
      $CMD
    fi
  fi
done
echo

