Skip to content

Instantly share code, notes, and snippets.

@plopp
Created April 23, 2018 16:37
Show Gist options
  • Save plopp/2ff27b3c7116eacd0f8c9bb674742656 to your computer and use it in GitHub Desktop.
Save plopp/2ff27b3c7116eacd0f8c9bb674742656 to your computer and use it in GitHub Desktop.
RED='\033[1;31m'
GREEN='\033[1;32m'
CYAN='\033[1;36m'
WHITE='\033[1;37m'
NC='\033[0m' # No Color
DIR="$HOME/db/rethinkdb"
echo ""
echo "${CYAN}Preparing for creation of a RethinkDB container...${NC}"
if [ ! -e $DIR ]; then
echo ""
echo "${CYAN}Creating RethinkDB data directory in "$DIR/data"${NC}"
echo ""
mkdir -p $DIR/data
echo "${CYAN}Data is stored here: ${WHITE}${DIR}/data${NC}"
echo ""
else
echo ""
echo "${CYAN}Data directory exists: ${WHITE}${DIR}/data${NC}"
echo ""
fi
echo "${CYAN}Checking for existing RethinkDB container.${NC}"
echo ""
if [ "$(docker ps -q -f name=rethinkdb)" ]; then
if [ "$(docker ps -aq -f status=exited -f name=rethinkdb)" ]; then
echo ""
echo "${RED}A RethinkDB container already exists, it is not running. Starting it...${NC}"
echo ""
docker start rethinkdb
else
# already running, do nothing
echo "${CYAN}A container is already running (If you want to create a new container. Remove the old one first using: docker stop rethinkdb && docker rm rethinkdb).${NC}"
fi
else
echo "${CYAN}Found none. Starting a new one...${NC}"
echo "${GREEN}binding to ${WHITE}localhost:29015${NC} for intracluster communication."
echo "${GREEN}binding to ${WHITE}localhost:28015${NC} for client driver communication."
echo "${GREEN}binding to ${WHITE}localhost:8080${NC} for web-interface."
echo ""
docker run -d \
-p 127.0.0.1:29015:29015 \
-p 127.0.0.1:28015:28015 \
-p 127.0.0.1:8080:8080 \
--name rethinkdb \
--restart unless-stopped \
-v $DIR/data:/data \
rethinkdb
echo "${CYAN}Let's see if it started...${NC}"
sleep 3
if [ "$(docker inspect -f {{.State.Running}} rethinkdb)" == "true" ]; then
echo "${GREEN}it is running OK.${NC}"
else
echo "${RED}it is not running. ERROR.${NC}"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment