#!/bin/bash

QUOTA=15000
PERIOD=50000

# initialize cgroups
for n in {0..8}
do
  cgcreate -a mystic -t mystic -g cpu:node$n
  if [ $? -ne 0 ]
  then
    echo "=================================================================="
    echo "Failed to create cgroup."
    echo "------------------------------------------------------------------"
    echo "Does container have the priviledges it needs to run?"
    echo "HINT: Use -v /sys/fs/cgroup:/sys/fs/cgroup:rw"
    echo "=================================================================="
    exit 1
  fi
  /bin/echo $QUOTA > /sys/fs/cgroup/cpu/node$n/cpu.cfs_quota_us
  /bin/echo $PERIOD > /sys/fs/cgroup/cpu/node$n/cpu.cfs_period_us
done

# Call original startup script as mystic user
cd /home/mystic/mystic/bbs

# I can't get this to work, this script is still pid 1.  
exec sudo -u mystic ./startup.sh

