diff --git a/.gitignore b/.gitignore index b14852c..2686a19 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ api/api +lxc/i diff --git a/lxc/execute b/lxc/execute index 0fe3ee9..83f9378 100755 --- a/lxc/execute +++ b/lxc/execute @@ -24,6 +24,17 @@ chmod 777 $basepath/tmp/$epoch cat $2 > $basepath$filepath echo "${@:3}" > $basepath$argpath +# process incrementor +oldinc=$(cat $dir/i | awk '{$1=$1};1') +newinc=$(expr $oldinc + 1) + +if (( newinc >= 151 )); then + newinc=1 + echo 1 > $dir/i +else + echo $newinc > $dir/i +fi + bin= case "$lang" in "python2") @@ -67,7 +78,14 @@ case "$lang" in exit esac +# runner lxc-attach -n piston -- \ - /bin/bash -c "PATH=/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin bash /exec/$bin $epoch 2>&1 | head -c 65536" + /bin/bash -c "\ + PATH=/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin \ + bash /exec/$bin $newinc $epoch 2>&1 | head -c 65536" + +# process janitor +lxc-attach -n piston -- \ + /bin/bash -c "for i in {1..2000}; do pkill -u runner$newinc --signal SIGKILL; done" > /dev/null 2>&1 & rm -rf $basepath/tmp/$epoch diff --git a/lxc/executors/c b/lxc/executors/c index 10a96be..0cd5424 100755 --- a/lxc/executors/c +++ b/lxc/executors/c @@ -1,3 +1,3 @@ -cd /tmp/$1 +cd /tmp/$2 timeout -s KILL 10 gcc -o binary -x c code.code -timeout -s KILL 3 runuser ubuntu -c "cat args.args | xargs -d '\n' ./binary" +runuser -l runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary" diff --git a/lxc/executors/cpp b/lxc/executors/cpp index cbe90ab..64a5157 100755 --- a/lxc/executors/cpp +++ b/lxc/executors/cpp @@ -1,3 +1,3 @@ -cd /tmp/$1 +cd /tmp/$2 timeout -s KILL 10 g++ -o binary -x c++ code.code -timeout -s KILL 3 runuser ubuntu -c "cat args.args | xargs -d '\n' ./binary" +runuser -l runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary" diff --git a/lxc/executors/csharp b/lxc/executors/csharp index 20691be..ec47c4a 100755 --- a/lxc/executors/csharp +++ b/lxc/executors/csharp @@ -1,3 +1,3 @@ -cd /tmp/$1 +cd /tmp/$2 timeout -s KILL 10 mcs $(echo code.code | sed 's/\///') -out:binary -timeout -s KILL 3 runuser ubuntu -c "cat args.args | xargs -d '\n' mono binary" +runuser -l runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 mono binary" diff --git a/lxc/executors/go b/lxc/executors/go index 0963669..5084a30 100755 --- a/lxc/executors/go +++ b/lxc/executors/go @@ -1,6 +1,6 @@ -cd /tmp/$1 +cd /tmp/$2 cp code.code interim.go file="interim.go" GOROOT=/usr/lib/go timeout -s KILL 10 go build $file file=${file%%.*} -timeout -s KILL 3 runuser ubuntu -c "cat args.args | xargs -d '\n' ./$file" +runuser -l runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ./$file" diff --git a/lxc/executors/java b/lxc/executors/java index 11b500a..7c8d1ff 100755 --- a/lxc/executors/java +++ b/lxc/executors/java @@ -1,6 +1,6 @@ -cd /tmp/$1 +cd /tmp/$2 cp code.code interim.java name=$(cat interim.java | grep -Eo 'public\s+class\s+([A-Za-z0-9]+)' | sed -n 's/ */ /gp' | cut -d' ' -f3) mv interim.java $name.java timeout -s KILL 10 javac $name.java -timeout -s KILL 3 runuser ubuntu -c "cat args.args | xargs -d '\n' java $name" +runuser -l runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 java $name" diff --git a/lxc/executors/nasm b/lxc/executors/nasm index ebacda1..661db6c 100755 --- a/lxc/executors/nasm +++ b/lxc/executors/nasm @@ -1,4 +1,4 @@ -cd /tmp/$1 +cd /tmp/$2 timeout -s KILL 10 nasm -f elf64 -o binary.o code.code timeout -s KILL 10 ld binary.o -o binary -timeout -s KILL 3 runuser ubuntu -c "cat args.args | xargs -d '\n' ./binary" +runuser -l runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary" diff --git a/lxc/executors/node b/lxc/executors/node index 8f88431..73c2f80 100755 --- a/lxc/executors/node +++ b/lxc/executors/node @@ -1,2 +1,2 @@ -cd /tmp/$1 -timeout -s KILL 3 runuser ubuntu -c "cat args.args | xargs -d '\n' nodejs code.code" +cd /tmp/$2 +runuser -l runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 nodejs code.code" diff --git a/lxc/executors/php b/lxc/executors/php index dc26d43..5731b85 100755 --- a/lxc/executors/php +++ b/lxc/executors/php @@ -1,2 +1,2 @@ -cd /tmp/$1 -timeout -s KILL 3 runuser ubuntu -c "cat args.args | xargs -d '\n' php code.code" +cd /tmp/$2 +runuser -l runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 php code.code" diff --git a/lxc/executors/python2 b/lxc/executors/python2 index 38f4cf6..8ccb484 100755 --- a/lxc/executors/python2 +++ b/lxc/executors/python2 @@ -1,2 +1,2 @@ -cd /tmp/$1 -timeout -s KILL 3 runuser ubuntu -c "cat args.args | xargs -d '\n' python2 code.code" +cd /tmp/$2 +runuser -l runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 python2 code.code" diff --git a/lxc/executors/python3 b/lxc/executors/python3 index e71d7fc..ef5b036 100755 --- a/lxc/executors/python3 +++ b/lxc/executors/python3 @@ -1,2 +1,2 @@ -cd /tmp/$1 -timeout -s KILL 3 runuser ubuntu -c "cat args.args | xargs -d '\n' python3.6 code.code" +cd /tmp/$2 +runuser -l runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 python3.6 code.code" diff --git a/lxc/executors/r b/lxc/executors/r index 39810fd..b12ee07 100755 --- a/lxc/executors/r +++ b/lxc/executors/r @@ -1,2 +1,2 @@ -cd /tmp/$1 -timeout -s KILL 3 runuser ubuntu -c "cat args.args | xargs -d '\n' Rscript code.code" +cd /tmp/$2 +runuser -l runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 Rscript code.code" diff --git a/lxc/executors/ruby b/lxc/executors/ruby index f9bd9dd..11b12b2 100755 --- a/lxc/executors/ruby +++ b/lxc/executors/ruby @@ -1,2 +1,2 @@ -cd /tmp/$1 -timeout -s KILL 3 runuser ubuntu -c "cat args.args | xargs -d '\n' ruby code.code" +cd /tmp/$2 +runuser -l runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ruby code.code" diff --git a/lxc/notes.txt b/lxc/notes.txt index 947db35..685c40b 100644 --- a/lxc/notes.txt +++ b/lxc/notes.txt @@ -15,11 +15,16 @@ sed -i 's/http:\/\/archive.ubuntu.com\/ubuntu/http:\/\/mirror.math.princeton.edu apt-get update apt-get -y install tzdata nano dpkg-dev build-essential python python3 ruby nodejs golang php7.2 r-base mono-complete nasm openjdk-8-jdk -# apply limits -echo 'ubuntu soft nproc 16' >> /etc/security/limits.conf -echo 'ubuntu hard nproc 16' >> /etc/security/limits.conf -echo 'ubuntu soft nofile 1024' >> /etc/security/limits.conf -echo 'ubuntu hard nofile 1024' >> /etc/security/limits.conf +# create users and apply limits +for i in {1..150}; do + #userdel runner$i + useradd -M runner$i + usermod -d /tmp runner$i + echo "runner$i soft nproc 64" >> /etc/security/limits.conf + echo "runner$i hard nproc 64" >> /etc/security/limits.conf + echo "runner$i soft nofile 2048" >> /etc/security/limits.conf + echo "runner$i hard nofile 2048" >> /etc/security/limits.conf +done # remove home dir rm -rf /home/ubuntu