#!/bin/sh -e

. /usr/lib/s6-policy-common/lib/svctl-common.sh

if test -z "$1" ; then
  echo "svctl-stop: usage: svctl-stop service..." 1>&2
  exit 100
fi

timeout="$(svctl_timeout)"
rc=0
s6-rc -t "$timeout" -d change "$@" || rc=$?
if [ "$rc" -ne 0 ]; then
  echo "svctl-stop: fatal: der Zustandswechsel ist fehlgeschlagen oder hat das Limit von" 1>&2
  echo "svctl-stop:        ${timeout} ms gerissen (s6-rc rc=${rc})." 1>&2
  svctl_report_pending down "$@"
  exit "$rc"
fi
