Created
July 7, 2021 12:57
-
-
Save bouk/954cd89544c091eed4b89a3f0baab639 to your computer and use it in GitHub Desktop.
dev/up
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Exit on fail | |
set -euo pipefail | |
check_or_install() { | |
brew list --versions "$1" &>/dev/null || brew install "$1" | |
} | |
export PGDATA="$PWD/dev/postgres" | |
export PGHOST="$PGDATA" | |
export PGDATABASE=postgres | |
export PGPORT=39999 | |
export PGUSER=postgres | |
ln -sfn ../postgresql.conf "$PGDATA/postgresql.conf" | |
if ! pg_ctl status &>/dev/null; then | |
echo "=> Starting postgres" >&2 | |
check_or_install postgresql | |
pg_ctl -s -l "$PGDATA/postgresql.log" start | |
fi | |
# Check if nginx is running by attempting to send it a reload signal | |
if ! nginx -s reload -c dev/nginx.conf -p "$PWD" &>/dev/null; then | |
echo "=> Setting up nginx" >&2 | |
check_or_install nginx | |
# This spawns an nginx daemon | |
mkdir -p dev/nginx | |
nginx -c dev/nginx.conf -p "$PWD" | |
fi | |
if ! bin/bundle check &>/dev/null; then | |
echo "=> Bundling" >&2 | |
bin/bundle install | |
fi | |
echo "=> Preparing database" >&2 | |
bin/rails db:prepare | |
# Restart Rails if it's running | |
mkdir -p tmp/ | |
touch tmp/restart.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment