#!/bin/sh

BOOT_LOG=/var/log/boot.log
PID_FILE=/tmp/rc.pid

source /etc/init.d/base

echo
echo "---- shutting down ${OS_NAME} ${OS_VERSION} ----" | tee -a ${BOOT_LOG}

# stop all init scripts in /etc/init.d,
# executing them in reverse numerical order.
(for i in $(ls -r /etc/init.d/S??*); do
    if ! [[ -x "${i}" ]]; then continue; fi
    if [[ -f /data/etc/no_$(basename ${i}) ]]; then continue; fi
    ${i} stop
done& echo $! > ${PID_FILE}) | tee -a ${BOOT_LOG} &

pid=$(cat ${PID_FILE})
while kill -0 ${pid} 2>/dev/null; do
    sleep 1
done
