Bind to specific interface / IP address.

I’m poking around the source, the box archive, and the but I haven’t been able to find where I can force the railo server (tomcat?) to bind to a specific IP address or interface, instead of localhost.

I need to test some things that require network communication across multiple ‘instances’ and I was hoping to do this with just commandbox. Could anyone point me in the right direction?

As a side note, maybe I should create a ticket to add that argument to the ‘server start’? something like ‘server start bind=10.0.0.x’.

Good question. We’re not using Tomcat for the servlet container, but rather Undertow which is very lightweight. The actual HTTP listener is assigned to the server programmatically as part of our RunWAR project:
https://github.com/Ortus-Solutions/runwar/blob/master/src/runwar/Server.java#L333

And that setting is picked up from the system properties set by the command line args when starting the server:
https://github.com/Ortus-Solutions/runwar/blob/master/src/runwar/Server.java#L103

And those properties are set in the serverService when starting the server:
https://github.com/Ortus-Solutions/commandbox/blob/master/src/cfml/system/services/ServerService.cfc#L138

in theory, if we added a host to the server start command:
https://github.com/Ortus-Solutions/commandbox/blob/master/src/cfml/commands/server/start.cfc#L28

and passed it along, it would get picked up as opposed to just defaulting to 127.0.0.1
https://github.com/Ortus-Solutions/runwar/blob/master/src/runwar/options/ServerOptions.java#L10

Disclaimer, I didn’t write the server start piece and I’m guess at how it works based on about 10 minutes of skimming the code just now :slight_smile: I’d put in a ticket for the enhancement, but feel free to play around as well. You may be able to get it working by only modifying the start command and ServerService.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Ah close, but it refuses to bind and fails. I stripped everything down to just the command & args:

““C:\Program Files\Java\jre1.8.0_20\bin\java.exe” -Drailo.web.config.dir=“C:\Users\don/.CommandBox/server//custom/checkup” -Drailo.server.config.dir=“C:\Users\don/.CommandBox/server/” -javaagent:“C:\Users\don/.CommandBox/lib/railo-inst.jar” -jar “C:\Users\don.CommandBox\lib\runwar-2.0.7.jar” -war “C:\Users\don\Desktop\webcrap\checkup” --background=false --port 56000 --host 192.168.1.100 --debug false --stop-port 56001 --processname “checkup” --log-dir “C:\Users\don/.CommandBox/server//custom/checkup/log” --open-browser true --open-url http://192.168.1.100:56000 --libdir “C:\Users\don/.CommandBox/lib” --iconpath “C:\Users\don/.CommandBox/lib/trayicon.png””

You can see the --host argument there, but in the log…


*** starting ‘stop’ listener thread - Host: 127.0.0.1 - Socket: 56001


Server is up - http-port:56000 stop-port:56001 PID:1376
2014-11-19 23:58:47 INFO org.xnio.Xnio XNIO version 3.2.0.Final
2014-11-19 23:58:47 INFO org.xnio.nio.NioXnio XNIO NIO Implementation Version 3.2.0.Final
Waiting upto 35 seconds for 192.168.1.100:56000…
could not open browser to…http://192.168.1.100:56000… timeout…

It fails there.
Also a possible issue (assuming) that the stop process would fail if it came up anyway because: https://github.com/Ortus-Solutions/runwar/blob/master/src/runwar/Stop.java the host is hardcoded there, but I could be wrong.

I’ll create a ticket and reference this discussion.

Yes, I did a similar quick and unsuccessful test. I’d have to stop and trace everything through the Java classes. Hopefully Denny can respond on the ticket since he probably knows off the top of his head.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Thanks for the help Brad, ticket here: [COMMANDBOX-122] Accept host argument for "server start host=x.x.x.x" - Welcome

Wanted to note something from my testing. Using my command & args above, even though it says

Waiting upto 35 seconds for 192.168.1.100:56000…

If you visit http://localhost:56000 it works just like before, somewhere it’s ignoring the host param

Looks like you need to update CommandBox:

"C:\Users\don\.CommandBox\lib\runwar-2.0.7.jar" -war

That's an older one. Should be 2.2.0, so I'm thinking that's the
problem right there.

:Denny

And to be clear, running the “upgrade” command will not update the jars. Right now there is no automated way to do that. What you have to do is remove the .CommandBox folder from your user directory, download the latest binary and re-execute. it will re-extract all the jars, etc fresh.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Yep! Re-installed using the latest download with 2.2.0 and binding to that host works, just need to update the cfc’s to pass the host argument along and it should work

Excellent news. I checked my lib folder and I also had an outdated jar which is probably why my test didn’t work either.

We’ll need to figure out an update mechanism to handler updates outside of the CFML directory. One of my ideas was to code the upgrade command to only work on dot releases, and bump a major version any time the libs got updated. Then, enhance the binary to auto-extract itself when it’s newer.

My previous assumption was correct: Trying to stop the server fails because of the hardcoded 127.0.0.1 here: https://github.com/Ortus-Solutions/runwar/blob/master/src/runwar/Stop.java#L12
because https://github.com/Ortus-Solutions/runwar/blob/master/src/runwar/options/CommandLineHandler.java#L284 doesn’t pass the host argument, just the port. But it’s the same in the parent project from cfmlprojects

(Limited java experience, take my findings with a grain of salt.)

Good catch. Can you add a note for that on the ticket? Thanks for taking the time to work on this. Also please feel free to submit a pull request for the parts you get working.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Actually the stop socket is different than the httpport, so that should be 127. What happens when you try to stop? Can you try runwar alone and see if it works there? You should be able to basically use the same args displayed from commandbox.

:Denny

Below is the out log, running runwar directly for starting & stopping. Trying to stop fails with an error message. Also when passing -stop, the help message it spits out specifies you can pass a -host argument.
Something to note is: the server can be stopped via the tray icon.

I think that’s a typo, it needs the stop-socket argument. See if runwar -? lists the correct parameters to use.

:Denny

Pretty sure -stop-socket is an alias for --stop-port: " -stopsocket,–stop-port stop listener port number. (8779)"

I went through the systray section to see why that works: https://github.com/Ortus-Solutions/runwar/blob/master/src/runwar/LaunchUtil.java#L389

as you can see, it opens up a socket using a host param from argument, which https://github.com/Ortus-Solutions/runwar/blob/master/src/runwar/Stop.java#L12 does not (the 127.0.0.1 is hardcoded here)

Again, I’m not a java developer so can someone please verify these changes? Pretty sure I got it correct, I built the classes and everything seemed to compile fine, but I couldn’t find how to create the .jar from the included built scripts in runwar…

Nevermind, I found the build target. Tested my compiled runwar-2.2.0.jar - stopping the server works as expected if you pass the -host param:
“C:\Program Files\Java\jre1.8.0_20\bin\java.exe” -jar “C:\Users\don.CommandBox\lib\runwar-2.2.0.jar” -stop --stop-port 56001 --background false --debug true -host x.x.x.x

Please accept the pull request.

Alright, I applied your changes Don, they're in runwar 2.2.1 if you want
to give it a spin and check.

The pull request was against a fork, so I had to grab the commit vs.
using that pull (which can be closed now if it's working).

Oh darn. Now I remember why it was supposed to be locked to localhost--
without a password as well, anyone can shut down the server by hitting
that port. The other thing I did remember, but wasn't too concerned
about, was that interfaces besides localhost can get into states that
won't let you "talk" to them, potentially starting servers without being
able to stop them. I think time would tell if that would be much of a
problem, but having the server stop when someone portscans it is. For
now we'll leave it be, but we need a password, the channel should be
over ssl probably, etc.. Thanks for your contribution, and do you have
any input on the password deal? I'm open so suggestions.

:Denny

Alright, I applied your changes Don, they’re in runwar 2.2.1 if you want
to give it a spin and check.

I also updated CommandBox on it as well.

The pull request was against a fork, so I had to grab the commit vs.
using that pull (which can be closed now if it’s working).

Oh darn. Now I remember why it was supposed to be locked to localhost–
without a password as well, anyone can shut down the server by hitting
that port. The other thing I did remember, but wasn’t too concerned
about, was that interfaces besides localhost can get into states that
won’t let you “talk” to them, potentially starting servers without being
able to stop them. I think time would tell if that would be much of a
problem, but having the server stop when someone portscans it is. For
now we’ll leave it be, but we need a password, the channel should be
over ssl probably, etc… Thanks for your contribution, and do you have
any input on the password deal? I’m open so suggestions.

I don’t know if am very concerned with it, but maybe setting a default password is good. And maybe a way to change it on a per server level is also good.

With that in mind, I have a question, (As I have not had time to digest runwar just yet). Does undertow support SSL? This is a key component sometimes for local development.