Created
April 19, 2018 09:43
-
-
Save themasch/e711698274477e75f4cefc6c4b0d3227 to your computer and use it in GitHub Desktop.
start & stop a local dynamodb for fun and profit
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
#!/usr/bin/env bash | |
set -e | |
function install_dynamodb_local { | |
if [ ! -e "db/DynamoDBLocal.jar" ]; then | |
echo "Downloading DynamoDBLocal" | |
mkdir -p db && cd db | |
curl "https://s3.eu-central-1.amazonaws.com/dynamodb-local-frankfurt/dynamodb_local_latest.tar.gz" -s | tar -xz | |
cd .. | |
fi; | |
} | |
function goto_workdir { | |
mkdir -p build | |
cd build | |
} | |
function start_server { | |
java -jar db/DynamoDBLocal.jar >> db.log 2>> db.error.log & | |
echo $! > db.pid | |
} | |
function stop_old_server { | |
if [ -e db.pid ]; then | |
PID=$(cat db.pid) | |
if [ "${PID}" -ne 0 ]; then | |
echo "sending TERM to ${PID} to stop old db" | |
kill "${PID}" | |
rm db.pid | |
else | |
echo "PID is 0, thats not good" | |
fi | |
fi | |
} | |
goto_workdir | |
case $1 in | |
"stop") | |
stop_old_server | |
;; | |
"start"|*) | |
install_dynamodb_local | |
stop_old_server | |
start_server | |
;; | |
esac; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment