Skip to content

Instantly share code, notes, and snippets.

@mileszs
Created December 6, 2012 12:51
Show Gist options
  • Select an option

  • Save mileszs/4224224 to your computer and use it in GitHub Desktop.

Select an option

Save mileszs/4224224 to your computer and use it in GitHub Desktop.
Find the next available port when starting the Rails server
function rserv()
{
rport=3000
port_taken=`lsof -i tcp:${rport}`
while [ $port_taken ]
do
echo "Port ${rport} taken..."
(( rport++ ))
port_taken=`lsof -n -i tcp:${rport}`
done
echo "Port ${rport} free, starting server..."
rails s -p ${rport}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment