Skip to content

Commit a0a86e4

Browse files
authored
Finish the refactor (#908)
1 parent 7e7401a commit a0a86e4

12 files changed

+184
-183
lines changed

install.sh

Lines changed: 21 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -1,162 +1,28 @@
11
#!/usr/bin/env bash
22
set -e
3-
43
if [[ -n "$MSYSTEM" ]]; then
54
echo "Seems like you are using an MSYS2-based system (such as Git Bash) which is not supported. Please use WSL instead.";
65
exit 1
76
fi
87

9-
# Thanks to https://unix.stackexchange.com/a/145654/108960
10-
log_file="sentry_install_log-`date +'%Y-%m-%d_%H-%M-%S'`.txt"
11-
exec &> >(tee -a "$log_file")
12-
13-
source "$(dirname $0)/install/_lib.sh"
14-
15-
echo "${_group}Defining variables and helpers ..."
16-
MIN_DOCKER_VERSION='19.03.6'
17-
MIN_COMPOSE_VERSION='1.24.1'
18-
MIN_RAM_HARD=3800 # MB
19-
MIN_RAM_SOFT=7800 # MB
20-
MIN_CPU_HARD=2
21-
MIN_CPU_SOFT=4
22-
echo $_endgroup
23-
24-
echo "${_group}Parsing command line ..."
25-
show_help() {
26-
cat <<EOF
27-
Usage: $0 [options]
28-
29-
Install Sentry with docker-compose.
30-
31-
Options:
32-
-h, --help Show this message and exit.
33-
--no-user-prompt Skips the initial user creation prompt (ideal for non-interactive installs).
34-
--minimize-downtime EXPERIMENTAL: try to keep accepting events for as long as possible while upgrading.
35-
This will disable cleanup on error, and might leave your installation in partially upgraded state.
36-
This option might not reload all configuration, and is only meant for in-place upgrades.
37-
EOF
38-
}
39-
40-
SKIP_USER_PROMPT="${SKIP_USER_PROMPT:-}"
41-
MINIMIZE_DOWNTIME="${MINIMIZE_DOWNTIME:-}"
42-
43-
while (( $# )); do
44-
case "$1" in
45-
-h | --help) show_help; exit;;
46-
--no-user-prompt) SKIP_USER_PROMPT=1;;
47-
--minimize-downtime) MINIMIZE_DOWNTIME=1;;
48-
--) ;;
49-
*) echo "Unexpected argument: $1. Use --help for usage information."; exit 1;;
50-
esac
51-
shift
52-
done
53-
echo "${_endgroup}"
54-
55-
echo "${_group}Setting up error handling ..."
56-
# Courtesy of https://stackoverflow.com/a/2183063/90297
57-
trap_with_arg() {
58-
func="$1" ; shift
59-
for sig ; do
60-
trap "$func $sig "'$LINENO' "$sig"
61-
done
62-
}
63-
64-
DID_CLEAN_UP=0
65-
# the cleanup function will be the exit point
66-
cleanup () {
67-
if [[ "$DID_CLEAN_UP" -eq 1 ]]; then
68-
return 0;
69-
fi
70-
DID_CLEAN_UP=1
71-
72-
if [[ "$1" != "EXIT" ]]; then
73-
echo "An error occurred, caught SIG$1 on line $2";
74-
75-
if [[ -n "$MINIMIZE_DOWNTIME" ]]; then
76-
echo "*NOT* cleaning up, to clean your environment run \"docker-compose stop\"."
77-
else
78-
echo "Cleaning up..."
79-
fi
80-
fi
81-
82-
if [[ -z "$MINIMIZE_DOWNTIME" ]]; then
83-
$dc stop -t $STOP_TIMEOUT &> /dev/null
84-
fi
85-
}
86-
trap_with_arg cleanup ERR INT TERM EXIT
87-
echo "${_endgroup}"
88-
89-
echo "${_group}Checking minimum requirements ..."
90-
DOCKER_VERSION=$(docker version --format '{{.Server.Version}}')
91-
COMPOSE_VERSION=$($dc --version | sed 's/docker-compose version \(.\{1,\}\),.*/\1/')
92-
RAM_AVAILABLE_IN_DOCKER=$(docker run --rm busybox free -m 2>/dev/null | awk '/Mem/ {print $2}');
93-
CPU_AVAILABLE_IN_DOCKER=$(docker run --rm busybox nproc --all);
94-
95-
# Compare dot-separated strings - function below is inspired by https://stackoverflow.com/a/37939589/808368
96-
function ver () { echo "$@" | awk -F. '{ printf("%d%03d%03d", $1,$2,$3); }'; }
97-
98-
if [[ "$(ver $DOCKER_VERSION)" -lt "$(ver $MIN_DOCKER_VERSION)" ]]; then
99-
echo "FAIL: Expected minimum Docker version to be $MIN_DOCKER_VERSION but found $DOCKER_VERSION"
100-
exit 1
101-
fi
102-
103-
if [[ "$(ver $COMPOSE_VERSION)" -lt "$(ver $MIN_COMPOSE_VERSION)" ]]; then
104-
echo "FAIL: Expected minimum docker-compose version to be $MIN_COMPOSE_VERSION but found $COMPOSE_VERSION"
105-
exit 1
106-
fi
107-
108-
if [[ "$CPU_AVAILABLE_IN_DOCKER" -lt "$MIN_CPU_HARD" ]]; then
109-
echo "FAIL: Required minimum CPU cores available to Docker is $MIN_CPU_HARD, found $CPU_AVAILABLE_IN_DOCKER"
110-
exit 1
111-
elif [[ "$CPU_AVAILABLE_IN_DOCKER" -lt "$MIN_CPU_SOFT" ]]; then
112-
echo "WARN: Recommended minimum CPU cores available to Docker is $MIN_CPU_SOFT, found $CPU_AVAILABLE_IN_DOCKER"
113-
fi
114-
115-
if [[ "$RAM_AVAILABLE_IN_DOCKER" -lt "$MIN_RAM_HARD" ]]; then
116-
echo "FAIL: Required minimum RAM available to Docker is $MIN_RAM_HARD MB, found $RAM_AVAILABLE_IN_DOCKER MB"
117-
exit 1
118-
elif [[ "$RAM_AVAILABLE_IN_DOCKER" -lt "$MIN_RAM_SOFT" ]]; then
119-
echo "WARN: Recommended minimum RAM available to Docker is $MIN_RAM_SOFT MB, found $RAM_AVAILABLE_IN_DOCKER MB"
120-
fi
121-
122-
#SSE4.2 required by Clickhouse (https://clickhouse.yandex/docs/en/operations/requirements/)
123-
# On KVM, cpuinfo could falsely not report SSE 4.2 support, so skip the check. https://github.com/ClickHouse/ClickHouse/issues/20#issuecomment-226849297
124-
IS_KVM=$(docker run --rm busybox grep -c 'Common KVM processor' /proc/cpuinfo || :)
125-
if [[ "$IS_KVM" -eq 0 ]]; then
126-
SUPPORTS_SSE42=$(docker run --rm busybox grep -c sse4_2 /proc/cpuinfo || :)
127-
if [[ "$SUPPORTS_SSE42" -eq 0 ]]; then
128-
echo "FAIL: The CPU your machine is running on does not support the SSE 4.2 instruction set, which is required for one of the services Sentry uses (Clickhouse). See https://git.io/JvLDt for more info."
129-
exit 1
130-
fi
131-
fi
132-
echo "${_endgroup}"
133-
134-
source ./install/create-docker-volumes.sh
135-
source ./install/ensure-files-from-examples.sh
136-
source ./install/generate-secret-key.sh
137-
source ./install/replace-tsdb.sh
138-
source ./install/update-docker-images.sh
139-
source ./install/build-docker-images.sh
140-
source ./install/turn-things-off.sh
141-
source ./install/set-up-zookeeper.sh
142-
source ./install/bootstrap-snuba.sh
143-
source ./install/create-kafka-topics.sh
144-
source ./install/upgrade-postgres.sh
145-
source ./install/set-up-and-migrate-database.sh
146-
source ./install/migrate-file-storage.sh
147-
source ./install/relay-credentials.sh
148-
source ./install/geoip.sh
149-
150-
if [[ "$MINIMIZE_DOWNTIME" ]]; then
151-
source ./install/restart-carefully.sh
152-
else
153-
echo ""
154-
echo "-----------------------------------------------------------------"
155-
echo ""
156-
echo "You're all done! Run the following command to get Sentry running:"
157-
echo ""
158-
echo " docker-compose up -d"
159-
echo ""
160-
echo "-----------------------------------------------------------------"
161-
echo ""
162-
fi
8+
source "$(dirname $0)/install/_lib.sh" # does a `cd .../install/`, among other things
9+
10+
source parse-cli.sh
11+
source error-handling.sh
12+
source check-minimum-requirements.sh
13+
source create-docker-volumes.sh
14+
source ensure-files-from-examples.sh
15+
source generate-secret-key.sh
16+
source replace-tsdb.sh
17+
source update-docker-images.sh
18+
source build-docker-images.sh
19+
source turn-things-off.sh
20+
source set-up-zookeeper.sh
21+
source bootstrap-snuba.sh
22+
source create-kafka-topics.sh
23+
source upgrade-postgres.sh
24+
source set-up-and-migrate-database.sh
25+
source migrate-file-storage.sh
26+
source relay-credentials.sh
27+
source geoip.sh
28+
source wrap-up.sh

install/_lib.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
set -euo pipefail
22
test "${DEBUG:-}" && set -x
33

4+
# Thanks to https://unix.stackexchange.com/a/145654/108960
5+
log_file="sentry_install_log-`date +'%Y-%m-%d_%H-%M-%S'`.txt"
6+
exec &> >(tee -a "$log_file")
7+
48
# Work from the onpremise root, no matter which script is called from where.
59
if [[ "$(basename $0)" = "install.sh" ]]; then
6-
cd "$(dirname $0)"
10+
cd "$(dirname $0)/install/"
711
else
8-
cd "$(dirname $0)/.."
12+
cd "$(dirname $0)" # assume we're a *-test.sh script
913
fi
10-
if [[ ! -d 'install' ]]; then echo 'Where are you?'; exit 1; fi
1114

12-
_ENV="$(realpath .env)"
15+
_ENV="$(realpath ../.env)"
1316

1417
# Read .env for default values with a tip o' the hat to https://stackoverflow.com/a/59831605/90297
1518
t=$(mktemp) && export -p > "$t" && set -a && . $_ENV && set +a && . "$t" && rm "$t" && unset t
@@ -36,8 +39,8 @@ function ensure_file_from_example {
3639
# sed from https://stackoverflow.com/a/25123013/90297
3740
fi
3841
}
39-
SENTRY_CONFIG_PY='sentry/sentry.conf.py'
40-
SENTRY_CONFIG_YML='sentry/config.yml'
42+
SENTRY_CONFIG_PY='../sentry/sentry.conf.py'
43+
SENTRY_CONFIG_YML='../sentry/config.yml'
4144

4245
# Increase the default 10 second SIGTERM timeout
4346
# to ensure celery queues are properly drained

install/avoid-git-bash.sh

Whitespace-only changes.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
echo "${_group}Checking minimum requirements ..."
2+
3+
MIN_DOCKER_VERSION='19.03.6'
4+
MIN_COMPOSE_VERSION='1.24.1'
5+
MIN_RAM_HARD=3800 # MB
6+
MIN_RAM_SOFT=7800 # MB
7+
MIN_CPU_HARD=2
8+
MIN_CPU_SOFT=4
9+
10+
DOCKER_VERSION=$(docker version --format '{{.Server.Version}}')
11+
COMPOSE_VERSION=$($dc --version | sed 's/docker-compose version \(.\{1,\}\),.*/\1/')
12+
RAM_AVAILABLE_IN_DOCKER=$(docker run --rm busybox free -m 2>/dev/null | awk '/Mem/ {print $2}');
13+
CPU_AVAILABLE_IN_DOCKER=$(docker run --rm busybox nproc --all);
14+
15+
# Compare dot-separated strings - function below is inspired by https://stackoverflow.com/a/37939589/808368
16+
function ver () { echo "$@" | awk -F. '{ printf("%d%03d%03d", $1,$2,$3); }'; }
17+
18+
if [[ "$(ver $DOCKER_VERSION)" -lt "$(ver $MIN_DOCKER_VERSION)" ]]; then
19+
echo "FAIL: Expected minimum Docker version to be $MIN_DOCKER_VERSION but found $DOCKER_VERSION"
20+
exit 1
21+
fi
22+
23+
if [[ "$(ver $COMPOSE_VERSION)" -lt "$(ver $MIN_COMPOSE_VERSION)" ]]; then
24+
echo "FAIL: Expected minimum docker-compose version to be $MIN_COMPOSE_VERSION but found $COMPOSE_VERSION"
25+
exit 1
26+
fi
27+
28+
if [[ "$CPU_AVAILABLE_IN_DOCKER" -lt "$MIN_CPU_HARD" ]]; then
29+
echo "FAIL: Required minimum CPU cores available to Docker is $MIN_CPU_HARD, found $CPU_AVAILABLE_IN_DOCKER"
30+
exit 1
31+
elif [[ "$CPU_AVAILABLE_IN_DOCKER" -lt "$MIN_CPU_SOFT" ]]; then
32+
echo "WARN: Recommended minimum CPU cores available to Docker is $MIN_CPU_SOFT, found $CPU_AVAILABLE_IN_DOCKER"
33+
fi
34+
35+
if [[ "$RAM_AVAILABLE_IN_DOCKER" -lt "$MIN_RAM_HARD" ]]; then
36+
echo "FAIL: Required minimum RAM available to Docker is $MIN_RAM_HARD MB, found $RAM_AVAILABLE_IN_DOCKER MB"
37+
exit 1
38+
elif [[ "$RAM_AVAILABLE_IN_DOCKER" -lt "$MIN_RAM_SOFT" ]]; then
39+
echo "WARN: Recommended minimum RAM available to Docker is $MIN_RAM_SOFT MB, found $RAM_AVAILABLE_IN_DOCKER MB"
40+
fi
41+
42+
#SSE4.2 required by Clickhouse (https://clickhouse.yandex/docs/en/operations/requirements/)
43+
# On KVM, cpuinfo could falsely not report SSE 4.2 support, so skip the check. https://github.com/ClickHouse/ClickHouse/issues/20#issuecomment-226849297
44+
IS_KVM=$(docker run --rm busybox grep -c 'Common KVM processor' /proc/cpuinfo || :)
45+
if [[ "$IS_KVM" -eq 0 ]]; then
46+
SUPPORTS_SSE42=$(docker run --rm busybox grep -c sse4_2 /proc/cpuinfo || :)
47+
if [[ "$SUPPORTS_SSE42" -eq 0 ]]; then
48+
echo "FAIL: The CPU your machine is running on does not support the SSE 4.2 instruction set, which is required for one of the services Sentry uses (Clickhouse). See https://git.io/JvLDt for more info."
49+
exit 1
50+
fi
51+
fi
52+
53+
echo "${_endgroup}"

install/create-docker-volumes-test.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ count() {
1111
before=$(count)
1212
test $before -eq 0 || test $before -eq $expected
1313

14-
source ./install/create-docker-volumes.sh
15-
source ./install/create-docker-volumes.sh
16-
source ./install/create-docker-volumes.sh
14+
source create-docker-volumes.sh
15+
source create-docker-volumes.sh
16+
source create-docker-volumes.sh
1717

1818
test $(count) -eq $expected
1919

install/ensure-files-from-examples.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ echo "${_group}Ensuring files from examples ..."
22

33
ensure_file_from_example $SENTRY_CONFIG_PY
44
ensure_file_from_example $SENTRY_CONFIG_YML
5-
ensure_file_from_example 'symbolicator/config.yml'
6-
ensure_file_from_example 'sentry/requirements.txt'
5+
ensure_file_from_example '../symbolicator/config.yml'
6+
ensure_file_from_example '../sentry/requirements.txt'
77

88
echo "${_endgroup}"

install/error-handling.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
echo "${_group}Setting up error handling ..."
2+
3+
# Courtesy of https://stackoverflow.com/a/2183063/90297
4+
trap_with_arg() {
5+
func="$1" ; shift
6+
for sig ; do
7+
trap "$func $sig "'$LINENO' "$sig"
8+
done
9+
}
10+
11+
DID_CLEAN_UP=0
12+
# the cleanup function will be the exit point
13+
cleanup () {
14+
if [[ "$DID_CLEAN_UP" -eq 1 ]]; then
15+
return 0;
16+
fi
17+
DID_CLEAN_UP=1
18+
19+
if [[ "$1" != "EXIT" ]]; then
20+
echo "An error occurred, caught SIG$1 on line $2";
21+
22+
if [[ -n "$MINIMIZE_DOWNTIME" ]]; then
23+
echo "*NOT* cleaning up, to clean your environment run \"docker-compose stop\"."
24+
else
25+
echo "Cleaning up..."
26+
fi
27+
fi
28+
29+
if [[ -z "$MINIMIZE_DOWNTIME" ]]; then
30+
$dc stop -t $STOP_TIMEOUT &> /dev/null
31+
fi
32+
}
33+
trap_with_arg cleanup ERR INT TERM EXIT
34+
35+
echo "${_endgroup}"

install/geoip-test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ mmdb="geoip/GeoLite2-City.mmdb"
55

66
# Starts with no mmdb, ends up with empty.
77
test ! -f $mmdb
8-
source ./install/geoip.sh
8+
source geoip.sh
99
diff -rub $mmdb $mmdb.empty
1010

1111
# Doesn't clobber existing, though.
1212
echo GARBAGE > $mmdb
13-
source ./install/geoip.sh
13+
source geoip.sh
1414
test "$(cat $mmdb)" = "GARBAGE"
1515

1616
report_success

install/parse-cli.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
echo "${_group}Parsing command line ..."
2+
3+
show_help() {
4+
cat <<EOF
5+
Usage: $0 [options]
6+
7+
Install Sentry with docker-compose.
8+
9+
Options:
10+
-h, --help Show this message and exit.
11+
--no-user-prompt Skips the initial user creation prompt (ideal for non-interactive installs).
12+
--minimize-downtime EXPERIMENTAL: try to keep accepting events for as long as possible while upgrading.
13+
This will disable cleanup on error, and might leave your installation in partially upgraded state.
14+
This option might not reload all configuration, and is only meant for in-place upgrades.
15+
EOF
16+
}
17+
18+
SKIP_USER_PROMPT="${SKIP_USER_PROMPT:-}"
19+
MINIMIZE_DOWNTIME="${MINIMIZE_DOWNTIME:-}"
20+
21+
while (( $# )); do
22+
case "$1" in
23+
-h | --help) show_help; exit;;
24+
--no-user-prompt) SKIP_USER_PROMPT=1;;
25+
--minimize-downtime) MINIMIZE_DOWNTIME=1;;
26+
--) ;;
27+
*) echo "Unexpected argument: $1. Use --help for usage information."; exit 1;;
28+
esac
29+
shift
30+
done
31+
32+
echo "${_endgroup}"

install/relay-credentials-test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ test ! -f $cfg
99
test ! -f $creds
1010

1111
# Running the install script adds them.
12-
source ./install/relay-credentials.sh
12+
source relay-credentials.sh
1313
test -f $cfg
1414
test -f $creds
1515
test "$(jq -r 'keys[2]' $creds)" = "secret_key"
1616

1717
# If the files exist we don't touch it.
1818
echo GARBAGE > $cfg
1919
echo MOAR GARBAGE > $creds
20-
source ./install/relay-credentials.sh
20+
source relay-credentials.sh
2121
test "$(cat $cfg)" = "GARBAGE"
2222
test "$(cat $creds)" = "MOAR GARBAGE"
2323

0 commit comments

Comments
 (0)