Skip to content

Instantly share code, notes, and snippets.

@themasch
Created April 19, 2018 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save themasch/e711698274477e75f4cefc6c4b0d3227 to your computer and use it in GitHub Desktop.
Save themasch/e711698274477e75f4cefc6c4b0d3227 to your computer and use it in GitHub Desktop.
start & stop a local dynamodb for fun and profit
#!/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