Skip to content

Instantly share code, notes, and snippets.

@danielnegri
Created July 19, 2013 21:04
Show Gist options
  • Select an option

  • Save danielnegri/6042324 to your computer and use it in GitHub Desktop.

Select an option

Save danielnegri/6042324 to your computer and use it in GitHub Desktop.
Run Khan Academy Exercises with SimpleHTTPServer
#!/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