|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | set -e |
3 | | - |
4 | 3 | if [[ -n "$MSYSTEM" ]]; then |
5 | 4 | echo "Seems like you are using an MSYS2-based system (such as Git Bash) which is not supported. Please use WSL instead."; |
6 | 5 | exit 1 |
7 | 6 | fi |
8 | 7 |
|
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 |
0 commit comments