Created
August 21, 2020 23:40
-
-
Save FachrulCH/73663e3dd9f785d7e1d5124e588295ef to your computer and use it in GitHub Desktop.
This file contains 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
#!/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