Running dotnet cli on jobe

Running dotnet cli on jobe

by Tim Rossiter -
Number of replies: 4

hello,

I have a working jobe server and CodeRunner installation. All the default language questions work well in Moodle. I have successfully created and run the c++ via python example question.  I have also created several other "questions" via python templates that work as expected.

My goal is to implement dotnet CLI questions. I have the dotnet core runtime and sdk installed and working. 

I am currently running into timeout issues when I try to execute any dotnet command via a Moodle question. 

Please note I have increased the jobe servers CPU timeout limit to 600 seconds which is far beyond reasonable for production use.

When the moodle question is submitted I can see the process start and run on the server but it seems to be hung. I can run the same python code manually on the server and it runs fine and completes with all the expected output. below is an example of what should be a nearly instant completion returning only the help or usage information for the command.


Running this on the server directly even as the jobe00 user works fine either from the terminal or via a python script identical to the CodeRunner question template.

I'm still investigating what might be special about the dotnet CLI tools but in the meanwhile, I was wondering if the sandbox execution may be limiting access to the dotnet sdk and/or runtime resources.  It may be a simple setting.


Any insight would be appreciated,

Tim R

Idaho State University

P.S.  compiling and running visual basic code on a Linux system makes me giggle.

In reply to Tim Rossiter

Re: Running dotnet cli on jobe

by Richard Lobb -

The most common problem when running other languages via Python is running out of memory. Have you tried setting the memory limit in the question on Moodle to 0? That turns off the memory limit. If that solves the problem you can then explore to find a reasonable limit (e.g. twice the minimum required to get a trivial job to run). There's a screen shot showing how to set the memory limit in this thread.

The next most common resource issue is the number of processes. The above link shows how to increase the number of processes.

If neither of those solves the problem, post back and I'll give more debugging tips.

In reply to Richard Lobb

Re: Running dotnet cli on jobe

by Dominique YOLIN -
Hello Richard

I've been using coderunner with questions in python, java, C and Cpp for a while, but now I would like to be able to use it also with C# since it is now completely cross plateform
But I have been trying to create a coderunner question with C# for the last few days and even though I feel I'm almost there, I'm stuck with an error that I can't find a solution to.
I successfully installed the jobeserver a few years back thanks to your video step-by-step but I have only some basic knowledge of Linux and its commands and I guess that is why I'm having difficulties to find the solution (which I hope will be obvious to you ;) )
To summarize what I've done :

- I have dowloaded and installed the dotnet sdk,
- I have given jobe00 enough rights to use it (I have not found yet how to make the dotnet usable by any user on the server)
- I wrote a python script that creates a csproj file and a simple cs file and compiles the program
- I logged to the server, I did "su jobe00" and was able to run the script successfully (it compiles the program and runs it)
- I created a cs_program question prototype (I added the following at the end of builtin_PROTOTYPES.xml in coderunner/db and I uploaded this xml throuh moodle), and I used the content of the script (I just modified the variable "student_answer" to get the content of the moodle answer box)
(I also added a CS_Task.php in jobehome/application, but I'm not sure if I did it right and even less that it is being used (since I have my sandbox in python3))
BUILT_IN_PROTOTYPE_cs_programBuilt-in prototypes are documented in the language strings.1.00000000.00000000cs_program10000181001<br /> """ The template for a question type that compiles and runs a student-submitted mono C# program. """<br /> <br /> import subprocess, sys, os<br /> <br /> # Write the student code to a file prog.cs please<br /> student_answer = """{{ STUDENT_ANSWER | e('py') }}"""<br /> <br /> with open("test.csproj","w") as projsrc:<br /> print("""<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><OutputType>Exe</OutputType><TargetFramework>net7.0</TargetFramework><ImplicitUsings>enable</ImplicitUsings><Nullable>enable</Nullable></PropertyGroup></Project>""", file=projsrc)<br /> <br /> <br /> with open("prog.cs","w") as src:<br /> print(student_answer, file=src)<br /> <br /> # Compile <br /> return_code = subprocess.run("dotnet build", shell=True)<br /> <br /> try:<br /> subprocess.run(["./bin/Debug/net7.0/test"], universal_newlines=True, shell=True)<br /> except subprocess.CalledProcessError as e:<br /> if e.returncode > 0:<br /> # Ignore non-zero positive return codes<br /> if e.output:<br /> print(e.output)<br /> else:<br /> # But negative return codes are signals - abort<br /> if e.output:<br /> print(e.output, file=sys.stderr)<br /> if e.returncode < 0:<br /> print("Task failed with signal", -e.returncode, file=sys.stderr)<br /> print("** Further testing aborted **", file=sys.stderr)<br /> """<br /> 000pyton3csEqualityGrader{"linkargs": ["-lm"]}00ace




- When I click "Save Changes and continue editing", I see that it creates the csproj and cs files as intended (I just added "os.chdir('/home/jobe00/cs2')" at the beginning of my script to verify that the files were indeed created and were problem free)
- When I use the script manually, thoses files can be used to generate an executable that can be run without problem in the console (also through the script)
- But in moodle, through CodeRunner, neither the compilation command nor the run command work : both give me "File size limit exceeded (core dumped)"

I have tried to modify the MemLimit in the Sandbox Advance Customisation (because I also have encountered the memory limit error, but it does not seem to be problematic anymore), but the problem persist





I also changed the LanguageTask.php fil to increase some limits :


// Global default parameter values. Can be overridden by subclasses,
// and then further overridden by the individual run requests.
public $default_params = array(
'disklimit' => 200, // MB (for normal files)
'streamsize' => 20, // MB (for stdout/stderr)
'cputime' => 50, // secs
'memorylimit' => 2000, // MB
'numprocs' => 200,
'compileargs' => array(),
'linkargs' => array(),
'interpreterargs' => array(),
'runargs' => array()
);


// Global minima settings for runguard sandbox when compiling.
// These override the default and task specific settings when a task
// is compiling in the sense that the parameter value used cannot be
// less than the one specified here.
public $min_params_compile = array(
'disklimit' => 200, // MB
'cputime' => 20, // secs
'memorylimit' => 2000, // MB
'numprocs' => 50 // processes
);


[...........]

public function run_in_sandbox($wrappedCmd, $iscompile=true, $stdin=null) {
$filesize = 10000 * $this->getParam('disklimit', $iscompile); // MB -> kB
$streamsize = 10000 * $this->getParam('streamsize', $iscompile); // MB -> kB
$memsize = 10000 * $this->getParam('memorylimit', $iscompile);
$cputime = $this->getParam('cputime', $iscompile);
$killtime = 20 * $cputime; // Kill the job after twice the allowed cpu time



Since jobe00 has no issue (without the need of sudo (but for that I have added jobe00 to the liste of sudoer)) to run the dotnet build as well as the generated executable, whether it is manually or through a script, I am certain the solution is near, but I don't know what to do about this size issue. I've looked at your forum but I did not find the solution, this thread being the closest to my needs

I hope you will be able to help me, because coderunner is really a great tool and I really wish I could use it with C# :)
Thank you for your time and your help

Dominique
In reply to Dominique YOLIN

Re: Running dotnet cli on jobe

by Richard Lobb -
You certainly seem to have tried lots of things! Hoiwever, you shouldn't need to alter the Jobe codebase in any way, so I'd recommend you first delete CS_Task.php (which won't be used if you're submitting a Python question) and restore LanguageTask.php to its original state so we have a known starting point. I'd also recommend that you don't add question types by editing the file builtin_PROTOTYPES.xml, which is intended just to define the built-in question types that are installed by CodeRunner itself. Apart from the difficulties in getting the XML right, if you define new prototypes in the system context in the CR_PROTOTYPES category with the name PROTOTYPE in them, they will all vanish the next time you update CodeRunner, as it re-installs a new set of prototypes each time.

The recommended way to implement new languages by writing new prototypes is documented here. However, I may be able to short circuit the process a bit for you.

A member of the CodeRunner community recently submitted an upgraded multilanguage question type, which now includes C#. I attach an export of this prototype, but with the question type changed from multilanguage to multilanguage2. If you import this and open it in the editor, you'll be able to see the relevant lines of code that handle C#. Specifically they are:
elif language == 'c#':
    cs_env = {}
    completedProc = subprocess.run([ "mcs",  "-out:tester.exe", filename ],env=cs_env  )
    if completedProc.returncode != 0:
        raise Exception("** C# Compilation failed. Testing aborted **")
    exec_command = ["./tester.exe"]

I'm not C# expert, but when I've run C# jobs on CodeRunner in the past I have just used the mcs program to compile the code. You appear to be using a more elaborate compilation and test environment so I'm wondering if that results in bringing in too much extra .NET infrastructure? I think all I did to install in on Jobe was the single command

sudo apt-get install mono-mcs

There shouldn't be a need to change access rights for the jobe users if you install it that way.

Perhaps you could try out the new multilanguage question type and if that works we can look into how to give you a C#-specific question type rather than a multilanguage version?

In reply to Richard Lobb

Re: Running dotnet cli on jobe

by Dominique YOLIN -
Hello Richard,

thank you so much for your quick response I really appreciate it.
I saw earlier post about mono, but since dotnet was release afterward, I did not even think about trying to install and use it, I was under the wrong assumption it was deprecated.

I installed it and run the test with a single file and it worked well

Then I tried to build a csproj since I want to be able to build a program with several source file, but I did not find a way to do it with mono (it seem msbuild and xbuild are both deprecated and mcs does not handle .csproj). But when I give all the cs file to the command line everything work fine and I'm able to create a test with multiple file for a single program

I just changed the cmd to
command_files = [ "mcs", "-out:tester.exe"]
for root, dirs, files in os.walk(os.getcwd()):
for file in files:
if file.endswith(".cs"):
command_files.append(os.path.join(root, file))

completedProc = subprocess.run(command_files,env=cs_env )

Thank you again for your help and great work on code runner :)

Dominique