#!/bin/bash set -e if [ -e /etc/redhat-release ]; then WWW_OWNER=apache:apache else # Assume we're on a Debian-based system for now. WWW_OWNER=www-data:www-data fi NGINX_SERVICE=${NGINX_SERVICE:-$(service --status-all 2>/dev/null \ | grep -Eo '\bnginx[^[:space:]]*' || true)} if [ -z "$NGINX_SERVICE" ]; then cat >&2 <&2 </dev/null; then echo "Starting db:migrate" bundle exec rake db:migrate elif [ 0 -eq ${PIPESTATUS[0]} ]; then # The database exists, but the migrations table doesn't. echo "Setting up database" bundle exec rake db:structure:load db:seed else echo "Error: Database is not ready to set up. Aborting." >&2 exit 1 fi echo "Done." echo "Restarting nginx" service "$NGINX_SERVICE" restart echo "Done."