Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated setup_mac to run puma instead of thin and to handle some of the ... #760

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions script/setup_mac
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,43 @@ echo
# Start the server and open the site
echo "### Setup complete, starting the sever and opening localhost ###"
echo
thin start -d
open http://localhost:3000

PID=$(ps aux | grep "thin server" | grep -v grep | awk '{print $2}')
echo "### To stop the server, run kill -9 $PID ###"
echo "Is Puma already running?"
RUNNING_PID=$(ps aux | grep "puma" | grep -v grep | awk '{print $2}')

# If puma is already running it will throw and error so just kill puma and let it start over
if [ -n "$RUNNING_PID" ]; then
echo "Puma is running on PID $RUNNING_PID"
echo "Putting puma back in its cage"
kill -9 "$RUNNING_PID"
echo "Puma has been caged"
else
echo "Puma is in its cage ready to be released"
fi
echo
echo "Setting a new Puma free"
echo
#start puma in the background
bundle exec puma &
PID=$! #capture the job PID

#See if puma is accepting requests
REQUEST=$(curl -I http://localhost:9292 2> /dev/null | grep HTTP/1.1 | awk {'$2'})

#hang out until puma is accepting request so we do not redirect to an error
echo "Puma is being a little sluggish please wait"
while [ "$REQUEST" != "200" ]; do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda feel like there should be some kind of timeout here, like 20 seconds or something. shrug

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bootup seems to take between 5 and 7 seconds

echo -n "* " #put a tick mark to let us know it is still working
sleep 1s
# check again
REQUEST=$(curl -I http://localhost:9292 2> /dev/null | grep HTTP/1.1 | awk {'print $2'})
done

echo
echo "Puma is running redirecting to browser"

open http://localhost:9292

echo "### Run script again to restart server or ###"
echo "### To stop the server, run kill -9 $PID ###"
echo