#!/bin/bash set -e if [ -e /etc/redhat-release ]; then WWW_OWNER=nginx:nginx 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:schema:load db:seed else echo "Error: Database is not ready to set up. Aborting." >&2 exit 1 fi echo "... done." echo "Precompiling assets ..." # precompile assets; thankfully this does not take long bundle exec rake assets:precompile -q -s echo "... done." echo "Restarting nginx ..." service "$NGINX_SERVICE" restart echo "... done."