github.com/ulule/limiter/v3@v3.11.3-0.20230613131926-4cb9c1da4633/scripts/redis (about) 1 #!/bin/bash 2 3 set -eo pipefail 4 5 DOCKER_REDIS_PORT=${DOCKER_REDIS_PORT:-26379} 6 7 CONTAINER_NAME="limiter-redis" 8 CONTAINER_IMAGE="redis:6.0" 9 10 do_start() { 11 12 if [[ -n "$(docker ps -q -f name="${CONTAINER_NAME}" 2> /dev/null)" ]]; then 13 echo "[redis] ${CONTAINER_NAME} already started. (use --restart otherwise)" 14 return 0 15 fi 16 17 if [[ -n "$(docker ps -a -q -f name="${CONTAINER_NAME}" 2> /dev/null)" ]]; then 18 echo "[redis] erase previous configuration" 19 docker stop "${CONTAINER_NAME}" >/dev/null 2>&1 || true 20 docker rm "${CONTAINER_NAME}" >/dev/null 2>&1 || true 21 fi 22 23 echo "[redis] update redis images" 24 docker pull ${CONTAINER_IMAGE} || true 25 26 echo "[redis] start new ${CONTAINER_NAME} container" 27 docker run --name "${CONTAINER_NAME}" \ 28 -p ${DOCKER_REDIS_PORT}:6379 \ 29 -d ${CONTAINER_IMAGE} >/dev/null 30 31 } 32 33 do_stop() { 34 35 echo "[redis] stop ${CONTAINER_NAME} container" 36 docker stop "${CONTAINER_NAME}" >/dev/null 2>&1 || true 37 docker rm "${CONTAINER_NAME}" >/dev/null 2>&1 || true 38 39 } 40 41 do_client() { 42 43 echo "[redis] use redis-cli on ${CONTAINER_NAME}" 44 docker run --rm -it \ 45 --link "${CONTAINER_NAME}":redis \ 46 ${CONTAINER_IMAGE} redis-cli -h redis -p 6379 -n 1 47 48 } 49 50 case "$1" in 51 --stop) 52 do_stop 53 ;; 54 --restart) 55 do_stop 56 do_start 57 ;; 58 --client) 59 do_client 60 ;; 61 --start | *) 62 do_start 63 ;; 64 esac 65 exit 0