2018-10-22 23:38:52 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
dir="$( cd "$( dirname "$0" )" && pwd )"
|
|
|
|
|
2018-11-02 06:21:22 +01:00
|
|
|
touch $dir/lockfile
|
|
|
|
|
2021-01-16 00:53:51 +01:00
|
|
|
if [ -z "$1" ] || [ -z "$2" ]; then
|
2018-10-22 23:38:52 +02:00
|
|
|
echo "invalid args"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2021-01-25 18:24:34 +01:00
|
|
|
language=$1
|
|
|
|
id=$2
|
2018-10-22 23:38:52 +02:00
|
|
|
|
2021-01-25 18:24:34 +01:00
|
|
|
basepath="/var/lib/lxc/piston/rootfs"
|
2018-10-22 23:38:52 +02:00
|
|
|
|
2018-10-24 07:34:33 +02:00
|
|
|
# process incrementor
|
2018-11-02 06:21:22 +01:00
|
|
|
exec 200>$dir/lockfile
|
2021-01-25 18:24:34 +01:00
|
|
|
flock 200
|
2018-10-24 07:34:33 +02:00
|
|
|
|
2021-01-25 18:46:06 +01:00
|
|
|
touch $dir/i
|
2021-01-25 18:24:34 +01:00
|
|
|
runner=$(cat $dir/i)
|
|
|
|
let 'runner = runner % 150 + 1'
|
|
|
|
|
|
|
|
echo $runner > $dir/i
|
2018-11-02 06:21:22 +01:00
|
|
|
exec 200>&-
|
2021-01-23 22:24:23 +01:00
|
|
|
|
|
|
|
# prevent users from spying on each other
|
2021-01-17 22:48:57 +01:00
|
|
|
lxc-attach --clear-env -n piston -- \
|
2021-01-23 22:24:23 +01:00
|
|
|
/bin/bash -l -c "
|
2021-01-25 18:24:34 +01:00
|
|
|
chown runner$runner -R /tmp/$id
|
|
|
|
chmod 700 /tmp/$id
|
2021-01-23 22:24:23 +01:00
|
|
|
" > /dev/null 2>&1
|
|
|
|
|
2018-10-24 07:34:33 +02:00
|
|
|
# runner
|
2021-01-14 06:45:48 +01:00
|
|
|
timeout -s KILL 20 \
|
2020-03-26 19:49:19 +01:00
|
|
|
lxc-attach --clear-env -n piston -- \
|
2021-01-25 18:24:34 +01:00
|
|
|
/bin/bash -l -c "runuser runner$runner /exec/$language runner$runner $id"
|
2018-10-24 07:34:33 +02:00
|
|
|
|
|
|
|
# process janitor
|
2020-03-26 19:49:19 +01:00
|
|
|
lxc-attach --clear-env -n piston -- \
|
2021-01-17 14:50:40 +01:00
|
|
|
/bin/bash -l -c "
|
|
|
|
for i in {1..100}
|
|
|
|
do
|
2021-01-25 18:24:34 +01:00
|
|
|
pkill -u runner$runner --signal SIGKILL
|
2021-01-17 14:50:40 +01:00
|
|
|
done
|
|
|
|
|
2021-01-25 18:24:34 +01:00
|
|
|
find /tmp -user runner$runner -delete
|
|
|
|
find /var/tmp -user runner$runner -delete
|
|
|
|
find /var/lock -user runner$runner -delete
|
|
|
|
find /dev/shm -user runner$runner -delete
|
|
|
|
find /run/lock -user runner$runner -delete
|
2021-01-17 14:50:40 +01:00
|
|
|
" > /dev/null 2>&1 &
|
2018-10-22 23:38:52 +02:00
|
|
|
|
2021-01-25 18:24:34 +01:00
|
|
|
rm -rf $basepath/tmp/$id
|