#!/bin/sh
# copyright (C) 2013 FUJITSU LIMITED All Rights Reserved

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2
# of the License.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
# 02110-1301, USA.

# cgroups path
CPUSET_LXCFMAINTENANCE="/sys/fs/cgroup/cpuset/lxcf-maintenance.slice"
CPU_LXCFMAINTENANCE="/sys/fs/cgroup/cpu/lxcf-maintenance.slice"
MEM_LXCFMAINTENANCE="/sys/fs/cgroup/memory/lxcf-maintenance.slice"

# make cgroup directories
if [ ! -d ${CPU_LXCFMAINTENANCE} ]; then
	mkdir -p ${CPU_LXCFMAINTENANCE};
fi

if [ ! -d ${CPUSET_LXCFMAINTENANCE} ]; then
	mkdir -p ${CPUSET_LXCFMAINTENANCE};
fi

if [ ! -d ${MEM_LXCFMAINTENANCE} ]; then
	mkdir -p ${MEM_LXCFMAINTENANCE};
fi

# set CPU 10%
echo -n 100000 > ${CPU_LXCFMAINTENANCE}/cpu.cfs_period_us;
echo -n  10000 > ${CPU_LXCFMAINTENANCE}/cpu.cfs_quota_us;
# set CPU Number 0
echo -n "0" > ${CPUSET_LXCFMAINTENANCE}/cpuset.cpus;
#set MEMORY 100M
echo -n `expr 100 \* 1024 \* 1024` > ${MEM_LXCFMAINTENANCE}/memory.limit_in_bytes;

# check separate model
/usr/lib/lxcf/lxcf-config

