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.
140 lines
4.1 KiB
140 lines
4.1 KiB
6 years ago
|
#!/bin/bash
|
||
|
|
||
|
set -e
|
||
|
set -o pipefail
|
||
|
|
||
6 years ago
|
indent() {
|
||
|
sed -u 's/^/ /'
|
||
|
}
|
||
|
|
||
6 years ago
|
echo "-----> Starting the all-in-one OpenProject setup at $BASH_SOURCE..."
|
||
|
|
||
|
if [ "$PGDATA" == "" ]; then
|
||
6 years ago
|
echo "No PGDATA environment variable defined. Aborting." | indent
|
||
|
exit 2
|
||
|
fi
|
||
|
|
||
4 years ago
|
export PGBIN="$(pg_config --bindir)"
|
||
|
export PGCONF_FILE="/etc/postgresql/9.6/main/postgresql.conf"
|
||
6 years ago
|
PGUSER=${PGUSER:=postgres}
|
||
|
PGPASSWORD=${PGPASSWORD:=postgres}
|
||
|
PG_STARTUP_WAIT_TIME=${PG_STARTUP_WAIT_TIME:=10}
|
||
|
SUPERVISORD_LOG_LEVEL=${SUPERVISORD_LOG_LEVEL:=info}
|
||
|
|
||
|
dbhost=$(ruby -ruri -e 'puts URI(ENV.fetch("DATABASE_URL")).host')
|
||
|
pwfile=$(mktemp)
|
||
|
echo "$PGPASSWORD" > $pwfile
|
||
|
chown postgres $pwfile
|
||
|
|
||
|
PLUGIN_GEMFILE_TMP=$(mktemp)
|
||
|
PLUGIN_GEMFILE=$APP_PATH/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_USER:$APP_USER "$PLUGIN_GEMFILE"
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
install_plugins() {
|
||
|
pushd $APP_PATH >/dev/null
|
||
|
|
||
|
if [ -s "$PLUGIN_GEMFILE" ]; then
|
||
|
echo "Installing plugins..."
|
||
|
bundle install
|
||
|
|
||
|
echo "Installing frontend dependencies..."
|
||
|
pushd $APP_PATH/frontend >/dev/null
|
||
|
if [ "$(id -u)" = '0' ]; then
|
||
|
su - $APP_USER -c "cd $APP_PATH/frontend && npm install"
|
||
|
else
|
||
|
npm install
|
||
|
fi
|
||
|
popd >/dev/null
|
||
|
|
||
|
echo "Precompiling new assets..."
|
||
|
bundle exec rake assets:precompile
|
||
|
|
||
|
echo "Plugins installed"
|
||
|
fi
|
||
|
|
||
|
popd >/dev/null
|
||
|
}
|
||
|
|
||
|
migrate() {
|
||
|
wait_for_postgres
|
||
|
pushd $APP_PATH >/dev/null
|
||
|
/etc/init.d/memcached start
|
||
5 years ago
|
bundle exec rake db:migrate
|
||
5 years ago
|
# run seed as app user so created attachments (and folder) belong to app, not root
|
||
|
su app -c 'bundle exec rake db:seed'
|
||
6 years ago
|
/etc/init.d/memcached stop
|
||
|
popd >/dev/null
|
||
|
}
|
||
|
|
||
4 years ago
|
check_postgres_connection() {
|
||
|
su postgres -c "$PGBIN/psql $DATABASE_URL -c 'select 1;'"
|
||
|
}
|
||
|
|
||
6 years ago
|
wait_for_postgres() {
|
||
|
retries=${PG_STARTUP_WAIT_TIME}
|
||
|
|
||
|
echo "Trying to contact PostgreSQL server instance or waiting for it to come online."
|
||
|
|
||
4 years ago
|
while ! check_postgres_connection &> /dev/null ; do
|
||
|
if [ $retries -eq 0 ]; then
|
||
|
echo "Unable to contact postgres server:"
|
||
|
check_postgres_connection
|
||
|
else
|
||
|
echo "Waiting for postgres server, $((retries--)) remaining attempts..."
|
||
|
sleep 3
|
||
|
fi
|
||
6 years ago
|
done
|
||
|
}
|
||
|
|
||
4 years ago
|
configure_local_postgres() {
|
||
|
mkdir -p "$PGDATA"
|
||
|
chown -R postgres:postgres "$PGDATA"
|
||
|
# remove any dangling pid
|
||
|
rm -f $PGDATA/postmaster.pid
|
||
|
|
||
|
# Set up pg defaults
|
||
|
echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.6/main/pg_hba.conf
|
||
|
echo "listen_addresses='0.0.0.0'" >> "$PGCONF_FILE"
|
||
|
echo "data_directory='$PGDATA'" >> "$PGCONF_FILE"
|
||
|
}
|
||
|
|
||
6 years ago
|
if [ "$dbhost" = "127.0.0.1" ]; then
|
||
4 years ago
|
configure_local_postgres
|
||
|
|
||
6 years ago
|
# initialize cluster if it does not exist yet
|
||
|
if [ -f "$PGDATA/PG_VERSION" ]; then
|
||
|
echo "-----> Database cluster already exists, not modifying."
|
||
4 years ago
|
su - postgres -c "$PGBIN/pg_ctl -w -l /dev/null -o '-c config_file=$PGCONF_FILE' -D '$PGDATA' start" | indent
|
||
6 years ago
|
(install_plugins && migrate) | indent
|
||
4 years ago
|
su - postgres -c "$PGBIN/pg_ctl -D '$PGDATA' stop" | indent
|
||
6 years ago
|
else
|
||
|
echo "-----> Database cluster not found. Creating a new one in $PGDATA..."
|
||
|
su postgres -c "$PGBIN/initdb --pgdata=${PGDATA} --username=${PGUSER} --encoding=unicode --auth=trust --pwfile=$pwfile" | indent
|
||
|
su postgres -c "rm -f $pwfile"
|
||
4 years ago
|
su - postgres -c "$PGBIN/pg_ctl -w -l /dev/null -o '-c config_file=$PGCONF_FILE' -D '$PGDATA' start" | indent
|
||
6 years ago
|
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
|
||
4 years ago
|
su - postgres -c "$PGBIN/pg_ctl -D '$PGDATA' stop" | indent
|
||
6 years ago
|
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..."
|
||
4 years ago
|
exec /usr/bin/supervisord -c $APP_PATH/docker/prod/supervisord.conf -e ${SUPERVISORD_LOG_LEVEL}
|