diff options
author | ankitjavalkar | 2017-11-14 15:46:50 +0530 |
---|---|---|
committer | ankitjavalkar | 2017-11-14 15:46:50 +0530 |
commit | 41e04d656e0045b3132bd3ec7de206c515606875 (patch) | |
tree | f78c8a8693f83dc56647527cf8f825ce0233ca53 | |
parent | 1aeb0997affaf8d6da3cdceee2d3ba8df59c4083 (diff) | |
download | online_test-41e04d656e0045b3132bd3ec7de206c515606875.tar.gz online_test-41e04d656e0045b3132bd3ec7de206c515606875.tar.bz2 online_test-41e04d656e0045b3132bd3ec7de206c515606875.zip |
Multiple minor fixes :
- Fix README instruct to run docker container before running django server
- Add messages after commands execute succesfully
- Touch a new file to denote successful running of code server
-rw-r--r-- | README.md | 18 | ||||
-rw-r--r-- | tasks.py | 17 | ||||
-rw-r--r-- | yaksh/scripts/yaksh_script.sh | 5 |
3 files changed, 28 insertions, 12 deletions
@@ -49,22 +49,15 @@ Quick Start - For Python 2 use: - $ pip install -r ./requirements/requirements-py2.txt + $ pip install -r ./requirements/requirements-py2.txt - For Python 3 (recommended) use: - $ pip install -r ./requirements/requirements-py3.txt + $ pip install -r ./requirements/requirements-py3.txt #### Short instructions -1. To run the application do the following: - - $ invoke serve - - - *Note:* The serve command will run the django application server on the 8000 port - and hence this port will be unavailable to other processes. - -1. On another terminal start up the code server that executes the user code safely: +1. Start up the code server that executes the user code safely: - To run the code server in a sandboxed docker environment, run the command: @@ -82,7 +75,12 @@ Quick Start and is susceptible to malicious code. You will have to install the code server requirements in sudo mode. +1. On another terminal, run the application using the following command: + + $ invoke serve + - *Note:* The serve command will run the django application server on the 8000 port + and hence this port will be unavailable to other processes. 1. Open your browser and open the URL ```http://localhost:8000/exam``` @@ -1,3 +1,4 @@ +from __future__ import print_function import invoke from invoke import task import os @@ -6,11 +7,18 @@ from yaksh.settings import SERVER_POOL_PORT SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) TARGET_CONTAINER_NAME = 'yaksh_code_server' SRC_IMAGE_NAME = 'fossee/yaksh_codeserver' +CHECK_FILE = 'server_running.txt' +CHECK_FILE_PATH = os.path.join(SCRIPT_DIR, 'yaksh_data', CHECK_FILE) + def create_dir(path): if not os.path.exists(path): os.makedirs(path) +def remove_check_file(path): + if os.path.isfile(path): + os.remove(path) + @task def setupdb(ctx): print("** Setting up & migrating database **") @@ -36,6 +44,7 @@ def getimage(ctx, image=SRC_IMAGE_NAME): print("The docker image {0} does not exist locally".format(image)) print("\n** Pulling latest image <{0}> from docker hub **".format(image)) ctx.run("sudo docker pull {0}".format(image)) + print("\n** Done! Successfully pulled latest image <{0}> **".format(image)) @task def start(ctx, ports=SERVER_POOL_PORT, image=SRC_IMAGE_NAME, unsafe=False, @@ -58,6 +67,7 @@ def start(ctx, ports=SERVER_POOL_PORT, image=SRC_IMAGE_NAME, unsafe=False, ) } + remove_check_file(CHECK_FILE_PATH) getimage(ctx, image=SRC_IMAGE_NAME) print("** Preparing code server **") @@ -84,12 +94,19 @@ def start(ctx, ports=SERVER_POOL_PORT, image=SRC_IMAGE_NAME, unsafe=False, {image} {command}".format(**cmd_params) ) + while not os.path.isfile(CHECK_FILE_PATH): + print("** Checking code server status. Press Ctrl-C to exit **\r", end="") + print("** Code server is up and running successfully **") + + @task def stop(ctx, container=TARGET_CONTAINER_NAME, hide=True): result = ctx.run("sudo docker ps -q --filter='name={0}'".format(container)) + remove_check_file(CHECK_FILE_PATH) if result.stdout: print ("** Discarding the docker container <{0}>".format(container)) ctx.run("sudo docker stop {0}".format(container)) ctx.run("sudo docker rm {0}".format(container)) + print ("** Done! Discarded the docker container <{0}>".format(container)) else: print("** Docker container <{0}> not found **".format(container)) diff --git a/yaksh/scripts/yaksh_script.sh b/yaksh/scripts/yaksh_script.sh index f39153e..1401d09 100644 --- a/yaksh/scripts/yaksh_script.sh +++ b/yaksh/scripts/yaksh_script.sh @@ -5,7 +5,8 @@ chown -R nobody output chmod -R a+rwX output chmod -R a+rX data yaksh chmod -R o-w data yaksh -echo "** Installing python dependencies **" +echo "** [CONTAINER] Installing python dependencies **" pip3 install -r ./requirements-codeserver.txt -echo "** Running code server **" +echo "** [CONTAINER] Running code server **" +touch server_running.txt /usr/bin/sudo -su nobody python3 -m yaksh.code_server |