#!/bin/bash

PATH=/usr/bin:/usr/sbin

. @RCLIBDIR@/functions

stat_busy "Stop services ..." sv force-stop @RUNDIR@/service/*
stat_done
stat_busy "Exit services ..." sv exit @RUNDIR@/service/*
stat_done

if [ -e @RUNDIR@/reboot ]; then
    chmod 100 @RUNDIR@/reboot
fi

run_shutdown

if [ -e @RUNDIR@/reboot ]; then
    [[ -x $(type -P kexec) ]] && kexec -e &>/dev/null
fi

status "Stage 3 completed."
