forked from metabase/metabase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart
executable file
·107 lines (91 loc) · 4.53 KB
/
start
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env bash
set -e
# NOTE: The canonical source for this file is in the metabase/metabase repository.
# Please update it there then copy to the metabase/metabase-deploy repository.
# Translate various Heroku environment variables to Metabase equivalents
if [ "$PORT" ]; then
export MB_JETTY_PORT="$PORT"
fi
# Heroku Postgres
if [ "$DATABASE_URL" ]; then
if [[ $string == *"?"* ]]; then
# if DATABASE_URL already has a query string don't mess with it
export MB_DB_CONNECTION_URI="$DATABASE_URL"
else
# otherwise add the SSL parameters to ensure upgraded databases work on Heroku
export MB_DB_CONNECTION_URI="$DATABASE_URL?ssl=true&sslmode=require&sslfactory=org.postgresql.ssl.NonValidatingFactory"
fi
fi
# Mailgun (Heroku)
if [ "$MAILGUN_SMTP_LOGIN" ]; then
export MB_EMAIL_SMTP_HOST="$MAILGUN_SMTP_SERVER"
export MB_EMAIL_SMTP_PORT="$MAILGUN_SMTP_PORT"
export MB_EMAIL_SMTP_USERNAME="$MAILGUN_SMTP_LOGIN"
export MB_EMAIL_SMTP_PASSWORD="$MAILGUN_SMTP_PASSWORD"
fi
# SendGrid (Heroku)
if [ "$SENDGRID_USERNAME" ]; then
export MB_EMAIL_SMTP_HOST="smtp.sendgrid.net"
export MB_EMAIL_SMTP_PORT="587"
export MB_EMAIL_SMTP_USERNAME="$SENDGRID_USERNAME"
export MB_EMAIL_SMTP_PASSWORD="$SENDGRID_PASSWORD"
export MB_EMAIL_SMTP_SECURITY="tls"
fi
# Mandrill (Heroku)
if [ "$MANDRILL_USERNAME" ]; then
export MB_EMAIL_SMTP_HOST="smtp.mandrillapp.com"
export MB_EMAIL_SMTP_PORT="587"
export MB_EMAIL_SMTP_USERNAME="$MANDRILL_USERNAME"
export MB_EMAIL_SMTP_PASSWORD="$MANDRILL_APIKEY"
fi
# Postmark (Heroku)
# NOTE: requires configuring sender signature for "from" address
if [ "$POSTMARK_API_TOKEN" ]; then
export MB_EMAIL_SMTP_HOST="$POSTMARK_SMTP_SERVER"
export MB_EMAIL_SMTP_PORT="25"
export MB_EMAIL_SMTP_USERNAME="$POSTMARK_API_TOKEN"
export MB_EMAIL_SMTP_PASSWORD="$POSTMARK_API_TOKEN"
export MB_EMAIL_SMTP_SECURITY="tls"
fi
# SparkPost (Heroku)
# NOTE: requires additional configuration
if [ "$SPARKPOST_SMTP_USERNAME" ]; then
export MB_EMAIL_SMTP_HOST="$SPARKPOST_SMTP_HOST"
export MB_EMAIL_SMTP_PORT="$SPARKPOST_SMTP_PORT"
export MB_EMAIL_SMTP_USERNAME="$SPARKPOST_SMTP_USERNAME"
export MB_EMAIL_SMTP_PASSWORD="$SPARKPOST_SMTP_PASSWORD"
fi
# Determine whether we're on Heroku on a free, hobby, 1x dyno or 2x dyno
#
# We set $HEROKU in the Procfile, so we know we're on Heroku when started from the
# Procfile.
#
# We need to override the $JAVA_OPTS and give it a slightly lower memory limit
# because Heroku tends to think we can use more memory than we actually can.
if [ -n "$HEROKU" ]; then
echo " -> Heroku detected"
if [ `ulimit -u` = 256 ]; then
# free, hobby or 1x dyno, it defaults to giving us 300m but that still ends
# up going over the 512MB limit for the dyno.
echo " => 1x dyno"
JAVA_OPTS="$JAVA_OPTS -Xmx248m" # This seems to be the right amount that prevents the dyno from going over the quota
fi
if [ `ulimit -u` = 512 ]; then
# 2x dyno, it defaults to giving us 800m but that still ends
# up going over the 1024MB limit for the dyno.
echo " => 2x dyno"
JAVA_OPTS="$JAVA_OPTS -Xmx496m" # This seems to be the right amount that prevents the dyno from going over the quota
fi
# Set a few other additional options to minimize memory usage as well.
JAVA_OPTS="$JAVA_OPTS -XX:-UseGCOverheadLimit" # Disable limit to amount of time spent in GC. Better slow than not working at all
JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC" # ConcMarkSweepGC seems to cause less OOM issues in my testing on low-mem Heroku envs
JAVA_OPTS="$JAVA_OPTS -XX:+CMSClassUnloadingEnabled" # Not 100% sure this does anything in Java 8 but if it does, we want to enable it
JAVA_OPTS="$JAVA_OPTS -XX:+UseCompressedOops" # Use 32-bit pointers. Reduces memory usage and GC events
JAVA_OPTS="$JAVA_OPTS -XX:+UseCompressedClassPointers" # Same as above. See also http://blog.leneghan.com/2012/03/reducing-java-memory-usage-and-garbage.html
fi
# Other Java options
JAVA_OPTS="$JAVA_OPTS -XX:+IgnoreUnrecognizedVMOptions" # Don't barf if we see an option we don't understand (e.g. Java 9 option on Java 7/8)
JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true" # don't try to start AWT. Not sure this does anything but better safe than wasting memory
JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF-8" # Use UTF-8
echo "Using these JAVA_OPTS: ${JAVA_OPTS}"
exec java $JAVA_OPTS -jar ./target/uberjar/metabase.jar