Skip to content

Commit dca0e06

Browse files
authored
Merge pull request #16613 from Budibase/background-redis-process-idle-fix
fix(singleimage): use pm2 to manage redis-server
2 parents 2e33809 + effb2f7 commit dca0e06

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

hosting/single/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ COPY hosting/single/redis.conf /etc/redis/redis.conf
8383
WORKDIR /
8484
COPY hosting/single/runner.sh .
8585
RUN chmod +x ./runner.sh
86+
COPY hosting/single/redis-runner.sh .
87+
RUN chmod +x ./redis-runner.sh
8688
COPY hosting/single/healthcheck.sh .
8789
RUN chmod +x ./healthcheck.sh
8890

hosting/single/redis-runner.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
REDIS_CONFIG="/etc/redis/redis.conf"
4+
sed -i "s#DATA_DIR#${DATA_DIR}#g" "${REDIS_CONFIG}"
5+
6+
if [[ -n "${USE_DEFAULT_REDIS_CONFIG}" ]]; then
7+
unset REDIS_CONFIG
8+
fi
9+
10+
REDIS_LAUNCH_SCRIPT="/tmp/redis-server-launch.sh"
11+
cat <<EOF > "$REDIS_LAUNCH_SCRIPT"
12+
#!/bin/bash
13+
if [[ -n "\${REDIS_PASSWORD}" ]]; then
14+
if [[ -n "\${REDIS_CONFIG}" ]]; then
15+
exec redis-server "\${REDIS_CONFIG}" --requirepass "\$REDIS_PASSWORD"
16+
else
17+
exec redis-server --requirepass "\$REDIS_PASSWORD"
18+
fi
19+
else
20+
if [[ -n "\${REDIS_CONFIG}" ]]; then
21+
exec redis-server "\${REDIS_CONFIG}"
22+
else
23+
exec redis-server
24+
fi
25+
fi
26+
EOF
27+
28+
chmod +x "$REDIS_LAUNCH_SCRIPT"
29+
30+
echo "Starting redis-server with pm2..."
31+
pm2 start "$REDIS_LAUNCH_SCRIPT" --name redis-server --interpreter bash

hosting/single/runner.sh

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,8 @@ mkdir -p ${DATA_DIR}/redis
8888
mkdir -p ${DATA_DIR}/couch
8989
chown -R couchdb:couchdb ${DATA_DIR}/couch
9090

91-
REDIS_CONFIG="/etc/redis/redis.conf"
92-
sed -i "s#DATA_DIR#${DATA_DIR}#g" "${REDIS_CONFIG}"
93-
94-
if [[ -n "${USE_DEFAULT_REDIS_CONFIG}" ]]; then
95-
REDIS_CONFIG=""
96-
fi
97-
98-
if [[ -n "${REDIS_PASSWORD}" ]]; then
99-
redis-server "${REDIS_CONFIG}" --requirepass $REDIS_PASSWORD >/dev/stdout 2>&1 &
100-
else
101-
redis-server "${REDIS_CONFIG}" >/dev/stdout 2>&1 &
102-
fi
91+
echo "Starting Redis runner..."
92+
./redis-runner.sh &
10393

10494
echo "Starting callback CouchDB runner..."
10595
./bbcouch-runner.sh &

0 commit comments

Comments
 (0)