Skip to content

Instantly share code, notes, and snippets.

@narma
Forked from marekjelen/gist:3256675
Created September 7, 2012 17:32
Show Gist options
  • Save narma/3667979 to your computer and use it in GitHub Desktop.
Save narma/3667979 to your computer and use it in GitHub Desktop.
New PostgreSQL on OpenShift
POSTGRESQL_VERSION="9.2.1"
# Installing DB (one-time)
cd $OPENSHIFT_DATA_DIR
wget http://ftp.postgresql.org/pub/source/v${POSTGRESQL_VERSION}/postgresql-${POSTGRESQL_VERSION}.tar.gz
tar xf postgresql-${POSTGRESQL_VERSION}.tar.gz
rm postgresql-${POSTGRESQL_VERSION}.tar.gz
cd postgresql-${POSTGRESQL_VERSION}
./configure --prefix=${OPENSHIFT_DATA_DIR}postgres --enable-nls="ru" --with-python --with-openssl --with-libxml
make
make install
cd ..
rm -rf postgresql-${POSTGRESQL_VERSION}
# Setup DB (one-time)
${OPENSHIFT_DATA_DIR}postgres/bin/initdb -D ${OPENSHIFT_DATA_DIR}postgres/data
# Starting DB
if [ -f ${OPENSHIFT_DATA_DIR}postgres/data/postmaster.pid ]; then
kill -0 `head -1 ${OPENSHIFT_DATA_DIR}postgres/data/postmaster.pid`
else
false
fi
PG_BIN=${OPENSHIFT_DATA_DIR}postgres/bin/postgres
PG_ARGS="-D ${OPENSHIFT_DATA_DIR}postgres/data -h ${OPENSHIFT_INTERNAL_IP}"
if [ $? = 0 ]; then
echo "PostgreSQL is running."
else
${PG_BIN} ${PG_ARGS} > ${OPENSHIFT_LOG_DIR}postgres 2>&1 &
fi
# Stopping DB
kill -INT `head -1 ${OPENSHIFT_DATA_DIR}postgres/data/postmaster.pid`
# Foreman to keep PostgreSQL running (setup)
mkdir -p ${OPENSHIFT_DATA_DIR}gems
export GEM_PATH=${OPENSHIFT_DATA_DIR}gems
export GEM_HOME=${OPENSHIFT_DATA_DIR}gems
gem install --no-user-install foreman --no-ri --no-rdoc
cat <<EOF > ${OPENSHIFT_DATA_DIR}postgresql
PG_BIN=\${OPENSHIFT_DATA_DIR}postgres/bin/postgres
PG_ARGS="-D \${OPENSHIFT_DATA_DIR}postgres/data -h \${OPENSHIFT_INTERNAL_IP}"
if [ -f \${OPENSHIFT_DATA_DIR}postgres/data/postmaster.pid ]; then
kill -0 \`head -1 \${OPENSHIFT_DATA_DIR}postgres/data/postmaster.pid\`
else
false
fi
if [ \$? = 0 ]; then
echo "PostgreSQL is running."
else
\${PG_BIN} \${PG_ARGS} > \${OPENSHIFT_LOG_DIR}postgres 2>&1
fi
EOF
chmod +x ${OPENSHIFT_DATA_DIR}postgresql
cat <<EOF > ${OPENSHIFT_DATA_DIR}Procfile
pgsql: \${OPENSHIFT_DATA_DIR}postgresql
EOF
# Foreman to keep PostgreSQL running (start & ensure)
export GEM_PATH=${OPENSHIFT_DATA_DIR}gems
export GEM_HOME=${OPENSHIFT_DATA_DIR}gems
${OPENSHIFT_DATA_DIR}gems/bin/foreman start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment