Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Created October 16, 2012 14:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joyrexus/3899714 to your computer and use it in GitHub Desktop.
Save joyrexus/3899714 to your computer and use it in GitHub Desktop.
Shell function for managing a simple HTTP server
# Manage a simple HTTP server
#
# Usage:
# http start|stop|restart [port]
#
# Notes:
# Add to .bashrc and resource (source ~/.bashrc)
http () {
local port="${2:-8000}"
case $1 in
"start")
echo "starting http server"
nohup python -m SimpleHTTPServer >| /tmp/nohup.out &
open "http://localhost:${port}/"
;;
"stop")
echo "stopping http server"
kill $(ps aux | grep "python -m SimpleHTTPServer" \
| grep -v grep \
| awk '{print $2}') > /dev/null
;;
"restart")
echo "restarting http server"
kill $(ps aux | grep "python -m SimpleHTTPServer" \
| grep -v grep | awk '{print $2}') > /dev/null
nohup python -m SimpleHTTPServer >| /tmp/nohup.out &
;;
*)
echo "need start|stop|restart"
esac
}
@DusanRM
Copy link

DusanRM commented Jul 28, 2016

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment