-
Notifications
You must be signed in to change notification settings - Fork 28
/
docker-entrypoint
executable file
·56 lines (40 loc) · 1.1 KB
/
docker-entrypoint
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
#!/usr/bin/env bash
# Exit build script on first failure.
set -e
# Exit on unset variable.
set -u
is_litestream_enabled() {
set +ux
local IS_ENABLED='false'
if [[ -n "${DB_REPLICA_URL}" ]]; then
IS_ENABLED='true';
fi
set -ux
echo "${IS_ENABLED}"
}
IS_LITESTREAM_ENABLED="$(is_litestream_enabled)"
readonly IS_LITESTREAM_ENABLED
# Echo commands to stdout.
set -x
LP_LAUNCH_CMD="/app/logpaste $*"
if [[ "${IS_LITESTREAM_ENABLED}" == 'true' ]]; then
/app/litestream version
echo "DB_REPLICA_URL=${DB_REPLICA_URL}"
readonly DB_PATH='/app/data/store.db'
# We need to export DB_PATH because litestream.yml references it.
export DB_PATH
if [[ -f "$DB_PATH" ]]; then
echo "Existing database is $(stat -c %s "${DB_PATH}") bytes"
else
echo "No existing database found"
# Restore database from remote storage.
/app/litestream restore -if-replica-exists -v "${DB_PATH}"
fi
# Let Litestream start LogPaste as a child process
/app/litestream replicate \
-exec "${LP_LAUNCH_CMD}"
else
echo "Starting without litestream"
# Start server.
eval "exec ${LP_LAUNCH_CMD}"
fi