#!/bin/sh

MANAGER_START_D=/etc/manager.d/start.d

# Runlevel 3 - Multi-user Mode with Networking
manager_start () {
    manager_lock_create || return 1

    /etc/init.d/S00devices start
    /etc/init.d/S01logging start
    /etc/init.d/S02tmp start
    /etc/init.d/S03databases start
    /etc/init.d/S50crond start
    /etc/init.d/S50lighttpd start

    [ -x /etc/init.d/S50dropbear ] && /etc/init.d/S50dropbear start

    if [ "${ENABLE_MINIDLNA}" == "1" ]; then
        busybox rm -f /tmp/minidlna/*
        /etc/init.d/S80minidlna start
        sleep 2
        /sbin/minidlna-internal
    fi
    # TODO: add some network monitor start like for ReadyNAS R6

    /etc/init.d/S90identity start
    /etc/init.d/S95kwilt-index start
    /etc/init.d/S97access-patrol start

    # Execute target-specific scripts in /etc/manager.d/start.d/
    if [ "`ls -A ${MANAGER_START_D}/* 2>/dev/null`" != "" ]; then
        for each in ${MANAGER_START_D}/* ; do
            sh ${each}
        done
    fi

    return 0
}
