I'm developer of a website where programmers can submit bots that compete against each other in a game. I'm trying to add Scala to our list of supported languages, but I'm having trouble here.
The problem is that every bot runs from it's own jail and I can't get scala to run from the jail (Linux system btw) because I get an error saying the executable is not found. Outside of the jail, everything works perfectly. So I'm missing some stuff to put in to the jail. I have all the Java dependency libraries, the whole jvm folder and the whole scala folder.. but there's some other stuff still missing and I'm clueless what it could be.
Here are the important lines of the compile script (which works as it should I think)
#compile
scalac -sourcepath src/ -d bin/ `find src/ -name '*.scala'`
#create runscript
echo "#!/bin/sh" > bin/run_ai
echo "cd / && ./scala -Djava.security.manager -cp bin/ -J-Xss8m -J-Xmx450m '$MAIN'" >> bin/run_ai
run_ai is the script that is called when running the bot from the jail, $MAIN is the main scala file to be ran. As I said, this all works fine outside of the jail.
Here's the script that creates everything that's needed inside of the jail. Here I'm missing some important stuff obviously.
mkdir -p lib64 bin lib/x86_64-linux-gnu usr/lib/x86_64-linux-gnu scala jvm proc
cp /lib64/ld-linux-x86-64.so.2 lib64/
cp /bin/sh bin/
#These dependency libraries are actually copied from the Java mkjail script.
#Using 'ldd /usr/bin/scala' returns "not a dynamic executable" in the shell.
#For other languages, it gives a nice list of dependencies, scala not :(
cp /lib/x86_64-linux-gnu/libgcc_s.so.1 lib/x86_64-linux-gnu/
cp /lib/x86_64-linux-gnu/libdl.so.2 lib/x86_64-linux-gnu/
cp /lib/x86_64-linux-gnu/libz.so.1 lib/x86_64-linux-gnu/
cp /lib/x86_64-linux-gnu/libc.so.6 lib/x86_64-linux-gnu/
cp /lib/x86_64-linux-gnu/libpthread.so.0 lib/x86_64-linux-gnu/
cp /lib/x86_64-linux-gnu/libm.so.6 lib/x86_64-linux-gnu/
cp /usr/lib/x86_64-linux-gnu/libstdc++.so.6 lib/x86_64-linux-gnu/
mount -o bind /proc proc
echo "bound /proc"
mount -o remount,ro proc
echo "remounted /proc"
#adding jvm to jail
mount -o bind /usr/lib/jvm jvm
mount -o remount,ro jvm
#adding scala to jail
mount -o bind /usr/share/scala scala
mount -o remount,ro scala
#some extra stuff to run Java from the jail, not actually needed here I think
if [ -f jvm/java-7-openjdk-amd64/jre/bin/java ]
then
cp jvm/java-7-openjdk-amd64/jre/lib/amd64/jli/libjli.so lib/x86_64-linux-gnu/
ln -s jvm/java-7-openjdk-amd64/jre/bin/java .
else
cp jvm/java-6-openjdk-amd64/jre/lib/amd64/jli/libjli.so lib/x86_64-linux-gnu/
ln -s jvm/java-6-openjdk-amd64/jre/bin/java .
fi
#creating a soft link to run scala. trying to run the bots without the soft link gives the same error, so this is not the problem.
ln -s scala/bin/scala ./scala
So in short: running scala from the jail results in an error: "./scala not found", if I try other stuff like: /scala/bin/scalac, I get the same error. (running the Java that is added in the jail works fine). So I'm missing some stuff to run Scala.
My question is: What is exactly needed to run Scala?
The 'scala' executable references /usr/bin/env, which resides outside the jail.
This might work:
java -cp /absolute/path/to/scala-library.jar:path/to/scala/classfiles/ MyMainClass