From 3f1c4859dee0548a40e7f900b1f41b1bc0af6c49 Mon Sep 17 00:00:00 2001 From: Paul Scarrone Date: Sat, 1 Jun 2013 18:49:05 -0400 Subject: [PATCH 1/2] Updated setup_mac to run puma instead of thin and to handle some of the conditions of starting puma Puma takes a few seconds to launch and will be started in the background. So we curl until it is accepting requests. Also we are caging(kill -9) old pumas if they are running when the script is started. Side effect is that the script restarts puma. --- script/setup_mac | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/script/setup_mac b/script/setup_mac index 1bf96be1..34d81592 100755 --- a/script/setup_mac +++ b/script/setup_mac @@ -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 "Setting 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 + 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 \ No newline at end of file From 69487500029b47d4c292aa14e9a90a2f6313776c Mon Sep 17 00:00:00 2001 From: Paul Scarrone Date: Sat, 1 Jun 2013 19:02:30 -0400 Subject: [PATCH 2/2] A little bit of echo formatting to make things neater --- script/setup_mac | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/script/setup_mac b/script/setup_mac index 34d81592..39e988d1 100755 --- a/script/setup_mac +++ b/script/setup_mac @@ -75,8 +75,8 @@ if [ -n "$RUNNING_PID" ]; then else echo "Puma is in its cage ready to be released" fi - -echo "Setting Puma free" +echo +echo "Setting a new Puma free" echo #start puma in the background bundle exec puma & @@ -88,7 +88,7 @@ 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 - echo -n "*" #put a tick mark to let us know it is still working + 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'})