File: redis

package info (click to toggle)
golang-github-ulule-limiter 3.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 240 kB
  • sloc: sh: 114; makefile: 15
file content (65 lines) | stat: -rwxr-xr-x 1,463 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash

set -eo pipefail

DOCKER_REDIS_PORT=${DOCKER_REDIS_PORT:-26379}

CONTAINER_NAME="limiter-redis"
CONTAINER_IMAGE="redis:5.0"

do_start() {

    if [[ -n "$(docker ps -q -f name="${CONTAINER_NAME}" 2> /dev/null)" ]]; then
        echo "[redis] ${CONTAINER_NAME} already started. (use --restart otherwise)"
        return 0
    fi

    if [[ -n "$(docker ps -a -q -f name="${CONTAINER_NAME}" 2> /dev/null)" ]]; then
        echo "[redis] erase previous configuration"
        docker stop "${CONTAINER_NAME}" >/dev/null 2>&1 || true
        docker rm "${CONTAINER_NAME}" >/dev/null 2>&1 || true
    fi

    echo "[redis] update redis images"
    docker pull ${CONTAINER_IMAGE} || true

    echo "[redis] start new ${CONTAINER_NAME} container"
    docker run --name "${CONTAINER_NAME}" \
        -p ${DOCKER_REDIS_PORT}:6379 \
        -d ${CONTAINER_IMAGE} >/dev/null

}

do_stop() {

    echo "[redis] stop ${CONTAINER_NAME} container"
    docker stop "${CONTAINER_NAME}" >/dev/null 2>&1 || true
    docker rm "${CONTAINER_NAME}" >/dev/null 2>&1 || true

}

do_client() {

    echo "[redis] use redis-cli on ${CONTAINER_NAME}"
    docker run --rm -it \
        --link "${CONTAINER_NAME}":redis \
        ${CONTAINER_IMAGE} redis-cli -h redis -p 6379 -n 1

}

case "$1" in
    --stop)
        do_stop
    ;;
    --restart)
        do_stop
        do_start
    ;;
    --client)
        do_client
    ;;
    --start | *)
        do_start
    ;;
esac
exit 0