#!/bin/sh
exec 2>&1

PATH=/sbin:/usr/sbin:/bin:/usr/bin

[ -r /etc/default/runit-antix ] && . /etc/default/runit-antix

LAST=0

# While test -x is more natural, it does not consider file with
# executable bit set on 'noexec' filesystem as executable, and /run
# often is mounted as 'noexec'.
[ $(stat -c %a /run/runit.stopit) = 0 ] && LAST=6

echo 'Unmounting network shares...'
umount -a -r -t nfs,nfs4,cifs

echo 'Waiting for services to stop...'
sv force-stop /etc/service/*
sv exit /etc/service/*

# Stop all runit-core sysv scripts
/lib/runit/stop_sysv_scripts '/etc/runit-core'

# Stop final sysv scripts (if fast shutdown not enabled)
if [ "$FAST_SHUTDOWN" -ne 1 ]; then
	echo "Stopping services in /etc/rc$LAST.d ..."
    /lib/runit/stop_sysv_scripts "/etc/rc$LAST.d"
fi
echo 'Shutdown...'
