Skip to content

Instantly share code, notes, and snippets.

@FachrulCH
Created August 21, 2020 23:40
Show Gist options
  • Save FachrulCH/73663e3dd9f785d7e1d5124e588295ef to your computer and use it in GitHub Desktop.
Save FachrulCH/73663e3dd9f785d7e1d5124e588295ef to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Script for start Python's simple http server in background
# Usage command:
# - ./gundala-server.sh start
# - ./gundala-server.sh stop
function start() {
# Start server
python3 -m http.server 8000 &> /dev/null &
pid=$!
# Give server time to start up
sleep 1
echo "Server is up at PID=$pid"
export SERVER_RUN_IN_PID=$pid
}
function stop() {
# Stop server
# kill "${pid}"
pid=$(lsof -ti tcp:8000)
if [[ $pid ]]; then
kill -9 $pid
fi
echo "pid $pid is killed"
}
"$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment