So I would like my Rails app instances to register themselves on a "I'm up" kind of thing I'm playing with, and I'd like it to be able to mention what local port it's running on. I can't seem to find how to do it - in fact just finding out its IP is tricky and needs a bit of a hack.
But no problem, I have the IP - but how can I find what port my mongrel/thin/webrick server is running on?
To be super explicit, if I start a rails app using script/server -p 3001, what can I do to pull that 3001 inside the app.
Now whenever the default port of 3000 is in use, it should automatically generate a new default server by incrementing the default port by 1 until there's an open port.
One way to shut down a rogue server is with the kill command. For the PID output above, you could kill the corresponding stuck server using kill 42612 . And if that didn't work, you could try kill -9 42612 .
$ rails --help Usage: rails COMMAND [ARGS] The most common rails commands are: generate Generate new code (short-cut alias: "g") console Start the Rails console (short-cut alias: "c") server Start the Rails server (short-cut alias: "s") ... All commands can be run with -h (or --help) for more information.
You can call Rails::Server.new.options[:Port]
to get the port that your Rails server is running on. This will parse the -p 3001
args from your rails server
command, or default to port 3000
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With