BrunoMiranda.com

Personal Blog about Software Engineering, Design, Travel & More

RescueTime friendly script/server launch script

Posted on June 26, 2008 at 09:22 PM

For those of us who work on various rails apps during the course a week this script is a lifesaver. I always ran into small issues related to having multiple apps running on development mode on on the same domain.

Most of the apps I deal with on the regular basis require authentication. Each site has a different login/password combination that safari is set to pre-fill. The problem with that is safari, or any other browser, has a hard time spotting the difference between http://0.0.0.0:3000 and http://0.0.0.0:3000. Possibly because they are the same address.

Another issue you may possibly encounter is that if you use some some of automatic time tracking tool like RescueTime (which is awesome) it will not be able to tell the difference between apps either (in case you wanted to tag them differently)

/etc/hosts to the rescue

Step one is to edit you /etc/hosts line:

127.0.0.1 localhost

to

127.0.0.1 localhost myblog clientone yasn

What that step gives you is the ability to browse the to the development version of you app running on any port on localhost at http://myblog:3000.

This will allow the browser to record and auto-fill proper passwords and will also allow RescueTime to properly identify the domains.

This is cool but could become tedious, boot app, open browser, type address (you could bookmark it but still).

#!bin/bash to the rescue

I created a file called go that takes 2 params, the first on is the name of the app that matches the name you gave it on /etc/hosts. Both params are optional the domain will default to 0.0.0.0 and port number to 3000.

Go does a couple of things, it boots the server (webrick or mongrel) on the specified port, opens a safari window and browses to the correct URL supplied as the first param.

#!/bin/bash

if [ -n "$1" ]; then
  SITE=$1
else
  SITE=0.0.0.0
fi

if [ -n "$2" ]; then
  PORT=$2
else
  PORT=0
fi

sleep 3 && open /Applications/Safari.app http://$SITE:300$PORT & script/server -p 300$PORT

Save that anywhere you’d like, preferably a folder included in your path make it executable and you are done.

Now from the prompt inside you app you can run go myblog 1 and that will boot the server on port 3001, open safari and browser to http://myblog:3000.

I am sure this can be massively improved upon. If you have an idea or would like to add to the script please let me know.

Tags: Rails, shell
Hierarchy: previous, next

Comments

There are 0 comments on this post. Post yours →

Post a comment

Required fields in bold.

 

Visit the Archives →