kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.8 KiB
62 lines
1.8 KiB
7 years ago
|
#!/bin/bash
|
||
|
|
||
|
set -e
|
||
|
set -o pipefail
|
||
|
|
||
7 years ago
|
PGDATA=${PGDATA:=/var/lib/postgresql/9.6/main}
|
||
7 years ago
|
PGUSER=${PGUSER:=postgres}
|
||
|
PGPASSWORD=${PGPASSWORD:=postgres}
|
||
7 years ago
|
PGBIN="/usr/lib/postgresql/9.6/bin"
|
||
7 years ago
|
|
||
|
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
|
||
|
|
||
|
indent() {
|
||
|
sed -u 's/^/ /'
|
||
|
}
|
||
|
|
||
|
migrate() {
|
||
|
pushd /usr/src/app
|
||
|
/etc/init.d/memcached start
|
||
|
rake db:migrate db:seed
|
||
|
/etc/init.d/memcached stop
|
||
7 years ago
|
chown app:app db/structure.sql
|
||
7 years ago
|
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
|
||
|
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
|
||
|
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
|