Created
July 19, 2013 21:04
-
-
Save danielnegri/6042324 to your computer and use it in GitHub Desktop.
Run Khan Academy Exercises with SimpleHTTPServer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| NAME=khan-exercises | |
| PID_FILE=khan-exercises.pid | |
| COMMAND="python -m SimpleHTTPServer" | |
| # | |
| # Functions | |
| # | |
| do_run() { | |
| echo "Running Simple HttpServer for Khan Exercises" | |
| cd ./$NAME | |
| $COMMAND & | |
| echo $! > ../$PID_FILE | |
| } | |
| do_stop() { | |
| echo "Stoping Simple HTTPServer" | |
| cat $PID_FILE | xargs kill -TERM | |
| # ps auxw | grep '#{name}' | grep -v grep | awk '{print $2}' | |
| # [ -f ./$PID_FILE ] && rm ./$PID_FILE || do_force_kill | |
| rm ./$PID_FILE | |
| } | |
| do_kill() { | |
| echo "Destroying Simple HTTPServer" | |
| if [ -f ./$PID_FILE ]; | |
| then | |
| cat $PID_FILE | xargs kill -9 | |
| rm ./$PID_FILE | |
| else | |
| echo "Procces file does not exists, applying alternative method" | |
| do_force_kill | |
| fi | |
| } | |
| do_force_kill() { | |
| ps aux | grep $COMMAND | grep -v grep | awk '{print $2}' | xargs kill | |
| } | |
| case "$1" in | |
| run) | |
| do_run | |
| ;; | |
| stop) | |
| do_stop | |
| ;; | |
| kill) | |
| do_kill | |
| ;; | |
| *) | |
| echo "Usage: $SCRIPT_NAME {run|stop|kill}" | |
| exit 3 | |
| ;; | |
| esac | |
| : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment