Repository navigation
Expand file tree
/
Copy pathstart-servers.sh
More file actions
131 lines (120 loc) · 4.45 KB
/
Copy pathstart-servers.sh
File metadata and controls
131 lines (120 loc) · 4.45 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env bash
set -Eeuo pipefail
backend=${1:?Expected redis, valkey or dragonfly}
server="$backend-server"
cli="$backend-cli"
if [[ $backend == dragonfly ]]; then
server=redis-server
cli=redis-cli
fi
state="${RUNNER_TEMP:?}/phpredis-servers"
acl="$PWD/tests/users.acl"
mkdir -p "$state" tests/nodes
trap 'status=$?
echo "::error::Server setup failed at line $LINENO (exit $status): $BASH_COMMAND" >&2
tail -n 40 "$state"/*/server.log >&2 || true
exit "$status"
' ERR
start_server() {
local name=$1
shift
mkdir -p "$state/$name"
if [[ $backend == dragonfly ]]; then
# The SETBIT boundary test allocates 256 MiB for one key.
dragonfly --bind=127.0.0.1 --dir="$state/$name" --aclfile="$acl" \
--proactor_threads=1 --maxmemory=1gb --maxclients=1000 \
--version_check=false "$@" >"$state/$name/server.log" 2>&1 &
return
fi
"$server" --bind 127.0.0.1 --daemonize yes --save '' \
--dir "$state/$name" --pidfile "$state/$name/server.pid" \
--logfile "$state/$name/server.log" \
--aclfile "$acl" --acl-pubsub-default allchannels "$@"
}
wait_for() {
local start=$SECONDS response
# A failed AUTH can still be followed by PONG from an unauthenticated server.
until response=$("$cli" "$@" 2>&1) &&
{ [[ $response == PONG ]] || [[ $response =~ ^cluster_state:ok($|[[:space:]]) ]]; }; do
if (( SECONDS - start >= 30 )); then
echo "Timed out waiting for $cli $*" >&2
printf '%s\n' "$response" >&2
return 1
fi
sleep .5
done
}
socket_port=0
if [[ $backend == dragonfly ]]; then
# shortcut: port=0 ignores ACLs; remove the TCP listener when Dragonfly fixes this.
socket_port=6383
fi
for port in {6379..6382}; do
start_server "$port" --port "$port"
done
start_server socket --port "$socket_port" --unixsocket /tmp/redis.sock
# testHighPorts probes with an unauthenticated PING before testing AUTH.
sed '/^user default /s/>phpredis/nopass/' "$acl" > "$state/highports.acl"
for port in {32767..32770}; do
start_server "$port" --port "$port" --aclfile "$state/highports.acl"
done
openssl req -x509 -newkey rsa:2048 -nodes -days 1 -subj /CN=localhost \
-addext 'subjectAltName=DNS:localhost,IP:127.0.0.1' \
-keyout "$state/server.key" -out "$state/server.crt"
if [[ $backend == dragonfly ]]; then
# Dragonfly's TLS startup check does not recognize passwords in the ACL file.
start_server tls --port 6378 --tls --requirepass=phpredis \
--tls_cert_file "$state/server.crt" --tls_key_file "$state/server.key"
else
start_server tls --port 0 --tls-port 6378 --tls-auth-clients no \
--tls-cert-file "$state/server.crt" --tls-key-file "$state/server.key" \
--tls-ca-cert-file "$state/server.crt"
fi
cluster_args=()
REDISCLI_AUTH=phpredis wait_for --user phpredis PING
if REDISCLI_AUTH=phpredis "$cli" --user phpredis CONFIG GET cluster-bus-port-protected-mode |
grep -q '^cluster-bus-port-protected-mode$'; then
# The test cluster's plaintext bus is bound to loopback only.
cluster_args+=(--cluster-bus-port-protected-mode no)
fi
: > tests/nodes/nodemap
cluster_ports=({7000..7005})
if [[ $backend == dragonfly ]]; then
cluster_ports=(7000)
start_server 7000 --port 7000 --cluster_mode=emulated
fi
for port in "${cluster_ports[@]}"; do
if [[ $backend != dragonfly ]]; then
start_server "$port" --port "$port" --cluster-enabled yes \
--cluster-config-file nodes.conf "${cluster_args[@]}"
fi
echo "127.0.0.1:$port" >> tests/nodes/nodemap
done
for port in {26379..26380}; do
mkdir -p "$state/$port"
cat > "$state/$port/sentinel.conf" <<EOF
port $port
bind 127.0.0.1
daemonize yes
dir $state/$port
pidfile $state/$port/server.pid
logfile $state/$port/server.log
sentinel monitor mymaster 127.0.0.1 6379 1
sentinel auth-pass mymaster phpredis
EOF
"$server" "$state/$port/sentinel.conf" --sentinel
wait_for -p "$port" PING
done
export REDISCLI_AUTH=phpredis
for port in {6379..6382} "${cluster_ports[@]}" {32767..32770}; do
wait_for --user phpredis -p "$port" PING
done
wait_for --user phpredis -s /tmp/redis.sock PING
wait_for --user phpredis --tls --cacert "$state/server.crt" -p 6378 PING
if [[ $backend != dragonfly ]]; then
"$cli" --user phpredis --cluster create 127.0.0.1:{7000..7005} \
--cluster-replicas 1 --cluster-yes
fi
for port in "${cluster_ports[@]}"; do
wait_for --user phpredis -p "$port" CLUSTER INFO
done