-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathredis
executable file
·68 lines (65 loc) · 1.79 KB
/
redis
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
66
67
68
#!/usr/bin/env bash
# $1 = command to run, commands:
# - start: start Redis container
# - status: get status of container, outputs "running" if Redis server is running,
# "stopped" if the Redis container is stopped but still exists, and
# "not found" if the Redis container does not exist.
# - stop: Stops and removes the Redis container.
# - logs: View logs from Redis container.
# - cli: Open a Redis CLI whic is connected to the container.
if [ -z "$CONTAINER_CLI" ]; then
CONTAINER_CLI="sudo podman"
fi
if [ -z "$CONTAINER_NAME" ]; then
CONTAINER_NAME=dev-valorant-discord-bot
fi
container_tag="redis:latest"
function die() {
echo "redis: $@" >&2
exit 1
}
case "$1" in
start)
case $($0 status) in
running) die "already running" ;;
stopped) $CONTAINER_CLI start "$CONTAINER_NAME" ;;
"not found") $CONTAINER_CLI run -d --net host --name "$CONTAINER_NAME" "$container_tag" ;;
esac
;;
status)
if $CONTAINER_CLI ps | grep "$CONTAINER_NAME" &> /dev/null; then
echo "running"
elif $CONTAINER_CLI ps -a | grep "$CONTAINER_NAME" &> /dev/null; then
echo "stopped"
else
echo "not found"
fi
;;
stop)
case $($0 status) in
running)
$CONTAINER_CLI stop "$CONTAINER_NAME"
$CONTAINER_CLI rm "$CONTAINER_NAME"
;;
stopped)
$CONTAINER_CLI rm "$CONTAINER_NAME"
;;
*) die "Cannot stop and remove redis if not running" ;;
esac
;;
logs)
case $($0 status) in
running)
$CONTAINER_CLI logs -f "$CONTAINER_NAME"
;;
*) die "Cannot get logs if Redis is not running" ;;
esac
;;
cli)
shift
$CONTAINER_CLI run -it --rm --net host "$container_tag" redis-cli $@
;;
*)
die "first argument must be \"start\", \"status\", \"stop\", \"logs\", \"cli\""
;;
esac