Skip to content

Instantly share code, notes, and snippets.

@fumin
Created November 22, 2015 19:59
Show Gist options
  • Save fumin/c00a1391282bc682ef2a to your computer and use it in GitHub Desktop.
Save fumin/c00a1391282bc682ef2a to your computer and use it in GitHub Desktop.
script to restart all background processes including dynamodb, sqs, redis, and elasticsearch
#!/bin/sh
function killport {
while true; do
PID=$(lsof -i TCP:$1 | grep LISTEN | awk '{print $2}')
exec 3>&2 # 3 is now a copy of 2
exec 2> /dev/null # 2 now points to /dev/null
kill $PID
kill -0 $PID
RES=$?
exec 2>&3 # restore stderr to saved
exec 3>&- # close saved version
if [ $RES -ne 0 ]; then
break
fi
sleep 1
done
}
killport 6379
redis-server /usr/local/etc/redis.conf 2>&1 > /dev/null &
killport 9200
elasticsearch --network.port=9200 2>&1 > /dev/null &
killport 9201
elasticsearch --network.port=9201 2>&1 > /dev/null &
DYNAMODB_DIR=/usr/local/dynamodb_local_2015-07-16_1.0
killport 8000
java -Djava.library.path=${DYNAMODB_DIR}/DynamoDBLocal_lib -jar ${DYNAMODB_DIR}/DynamoDBLocal.jar -dbPath $DYNAMODB_DIR -port 8000 2>&1 > /dev/null &
killport 4568
fake_sqs --bind=127.0.0.1 --port=4568 2>&1 > /dev/null &
killport 4569
fake_sqs --bind=127.0.0.1 --port=4569 2>&1 > /dev/null &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment