#!/bin/sh /etc/rc.common
# Copyright (C) 2008 OpenWrt.org

START=1

. /etc/init.d/eapcontroller
cpu_limit=80
boot() {
	factory_mode=`uci get factory_mode.factory_mode.factory_flag`
	if [ $factory_mode == 1 ]; then
		echo "ingnore factory mode, start controller" > /dev/console
		# return 1
	fi
	
	local pid=`pgrep -o local-starter`

	if [ -n "$pid" ]; then
		echo "eapcontroller has already started" > /dev/console
		/usr/sbin/quick_setup_check &
	else
		echo "starting eapcontroller now" > /dev/console
		/etc/init.d/eapcontroller start

		# 非出厂模式下的cpu占用率限制
		local profile_cpu_limit=`uci -c /etc/profile.d get profile.@eapcontroller[0].cpu_limit`
		if [ -n "$profile_cpu_limit" ]; then
			cpu_limit=$profile_cpu_limit
		fi
		echo cpu_limit $cpu_limit > /dev/console
		cgroups_set $cpu_limit &

	fi
	unset crontabs_check
	crontabs_check=`cat /etc/crontabs/root | grep eapcontroller-detect`
	if [ -z "$crontabs_check" ]; then
		echo "*/1 * * * * eapcontroller-detect" >> /etc/crontabs/root
		/etc/init.d/cron restart
	fi
}
