-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry_point.sh
53 lines (43 loc) · 1.33 KB
/
entry_point.sh
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
#!/usr/bin/env bash
set -e
export REDIS_PORT="${REDIS_PORT:-6379}"
function isRunning() {
if [ ! -f /tmp/tunnel.pid ]; then
return 1
fi
pid=$(cat "/tmp/tunnel.pid")
if [ ! -d /proc/$pid ]; then
return 1
fi
if [ "$(cat "/proc/$pid/comm")" != "autossh" ]; then
return 1
fi
return 0
}
if [ -n "$REDIS_SSH_HOST" ]; then
REDIS_SSH_PORT="${REDIS_SSH_PORT:-22}"
REDIS_SSH_USER="${REDIS_SSH_USER:-root}"
if ! isRunning; then
# Set up ssh tunneling
AUTOSSH_PIDFILE=/tmp/tunnel.pid AUTOSSH_GATETIME=0 AUTOSSH_PORT=0 autossh -f -N -L "6380:127.0.0.1:${REDIS_PORT}" \
-p "$REDIS_SSH_PORT" \
-o StrictHostKeyChecking=no \
-o ServerAliveInterval=60 \
-o ServerAliveCountMax=3 \
-o ExitOnForwardFailure=yes \
-o ConnectTimeout=10 \
-o TCPKeepAlive=yes \
-i /app/sshkey \
"$REDIS_SSH_USER@$REDIS_SSH_HOST"
else
echo "AutoSSH already running"
fi
export REDIS_PORT=6380
# Wait for tunnel to be established
echo "Waiting for tunnel to be established..."
while ! nc -z localhost $REDIS_PORT; do
sleep 1
done
echo "Tunnel established."
fi
exec node /app/main.js "$@" | node_modules/.bin/pino-pretty -cSt SYS:HH:MM --ignore pid,hostname