#!/bin/bash

# The pre_start_cartridge and pre_stop_cartridge hooks are *SOURCED*
# immediately before (re)starting or stopping the specified cartridge.
# They are able to make any desired environment variable changes as
# well as other adjustments to the application environment.

# The post_start_cartridge and post_stop_cartridge hooks are executed
# immediately after (re)starting or stopping the specified cartridge.

# Exercise caution when adding commands to these hooks.  They can
# prevent your application from stopping cleanly or starting at all.
# Application start and stop is subject to different timeouts
# throughout the system.

# If there is no support for user-defined environment variables
# set the RAILS_DB using export.
#
if ! [ "$(type -t set_env_var)" == "function" ]; then
  if [ ! -z "$OPENSHIFT_POSTGRESQL_DB_HOST" ]; then
    export RAILS_DB="postgresql"
  fi

  if [ ! -z "$OPENSHIFT_MYSQL_DB_HOST" ]; then
    export RAILS_DB="mysql"
  fi
fi
