This repository has been archived by the owner on Jun 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
/
entrypoint-all-in-one.sh
executable file
·90 lines (74 loc) · 2.49 KB
/
entrypoint-all-in-one.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
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
#!/bin/bash
set -e
set -o pipefail
PGDATA=${PGDATA:=/var/lib/postgresql/9.6/main}
PGUSER=${PGUSER:=postgres}
PGPASSWORD=${PGPASSWORD:=postgres}
PGBIN="/usr/lib/postgresql/9.6/bin"
if [ ! -z "$ATTACHMENTS_STORAGE_PATH" ]; then
mkdir -p "$ATTACHMENTS_STORAGE_PATH"
chown -R app:app "$ATTACHMENTS_STORAGE_PATH"
fi
dbhost=$(ruby -ruri -e 'puts URI(ENV.fetch("DATABASE_URL")).host')
pwfile=$(mktemp)
chown postgres $pwfile
echo "$PGPASSWORD" > $pwfile
PLUGIN_GEMFILE_TMP=$(mktemp)
PLUGIN_GEMFILE=/usr/src/app/Gemfile.local
if [ "$PLUGIN_GEMFILE_URL" != "" ]; then
echo "Fetching custom gemfile from ${PLUGIN_GEMFILE_URL}..."
curl -L -o "$PLUGIN_GEMFILE_TMP" "$PLUGIN_GEMFILE_URL"
# set custom plugin gemfile if file is readable and non-empty
if [ -s "$PLUGIN_GEMFILE_TMP" ]; then
mv "$PLUGIN_GEMFILE_TMP" "$PLUGIN_GEMFILE"
chown app.app "$PLUGIN_GEMFILE"
fi
fi
indent() {
sed -u 's/^/ /'
}
install_plugins() {
pushd /usr/src/app
if [ -s "$PLUGIN_GEMFILE" ]; then
echo "Installing plugins..."
bundle install
echo "Precompiling new assets..."
bundle exec rake assets:precompile
echo "Plugins installed"
fi
popd
}
migrate() {
pushd /usr/src/app
/etc/init.d/memcached start
bundle exec rake db:migrate db:seed db:structure:dump
/etc/init.d/memcached stop
chown app:app db/structure.sql
popd
}
if [ "$dbhost" = "127.0.0.1" ]; then
# initialize cluster if it does not exist yet
if [ -f "$PGDATA/PG_VERSION" ]; then
echo "-----> Database cluster already exists, not modifying."
/etc/init.d/postgresql start | indent
(install_plugins && migrate) | indent
/etc/init.d/postgresql stop | indent
else
echo "-----> Database cluster not found. Creating a new one in $PGDATA..."
chown -R postgres:postgres $PGDATA
su postgres -c "$PGBIN/initdb --pgdata=${PGDATA} --username=${PGUSER} --encoding=unicode --auth=trust --pwfile=$pwfile" | indent
rm -f $pwfile
/etc/init.d/postgresql start | indent
su postgres -c "$PGBIN/psql --command \"CREATE USER openproject WITH SUPERUSER PASSWORD 'openproject';\"" | indent
su postgres -c "$PGBIN/createdb -O openproject openproject" | indent
(install_plugins && migrate) | indent
/etc/init.d/postgresql stop | indent
fi
else
echo "-----> You're using an external database. Not initializing a local database cluster."
migrate | indent
fi
echo "-----> Database setup finished."
echo " On first installation, the default admin credentials are login: admin, password: admin"
echo "-----> Launching supervisord..."
exec /usr/bin/supervisord