-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#117 Reworked Stop.bat (used java instead of telnet and cscript) #127
base: master
Are you sure you want to change the base?
Conversation
Sorry for the delay in responding to this. I have actually been looking at it now and again over the past few days, and finally decided to write some comments last night. But before doing so, I thought I should just test it to make sure the STOP entry point actually works, and immediately I realised the problem with this whole approach that blows it out of the water. The computer I do my IBC development on is not the same one that I run TWS/Gateway on (except at weekends when my live and paper TWS/Gateway are not in use). So when I decided to use your revised STOP.bat, it was obviously untenable because it depends on being on the same machine as TWS - either that or at least having IBC installed and the the same config.ini (and a suitable Java). Since I would imagine that by far the most common use of the STOP command is to shut down a remote instance of IBC, it is clearly unacceptable to have to duplicate the IBC configuration on the machine where STOP is to be used. So this is not going to fly. What we actually need is a free-standing program that has address and port number as arguments (defaulting address to 127.0.0.1 and port to 7462), and doesn't have any dependencies on IBC itself. There would then actually be no need for a STOP.bat, though one could still be provided for those who want a one-liner using non-default parameters but who really don't want to learn how to do .bat files. I suggest that the sensible approach to this is to write a small .Net command line program (C# preferred), As for your Java version, it would only be a few lines long. Now that .Net is included in all (supported) Windows versions there would be no need to install anything else. The STOP program could simply be copied to any machine, or downloaded direct from GitHub onto any machine. If this program were targeted on .Net Standard 2, it would also be theoretically useable cross-platform, though this would require the .Net runtime (and the SDK to allow building) to be installed on Linux and is of little real value since telnet already does the job properly. By the way, you seem to have misunderstood the meaning of the |
Ok. Let me explain my intention. Most likely BindAddress is not specified, this means that the command server accept connections from any network adapters. In this case we can connect to the command server using "localhost" (or 127.0.0.1). In some cases BindAddress is set to 127.0.0.1 in order to avoid connection from other hosts. In this case connection to "localhost" will also work. In some very rare cases BindAddress can be set to something different, let's say 192.168.10.20 (assuming that 192.168.10.20 is a valid IP address of one of network adapters of the host). In this case an attempt to connect to the command server using conventional "localhost" will NOT work. So I was trying to cover such cases as well using BindAddress as a hint which IP address we can use in order to reach the command server. Perhaps I should have explained this in comments. Also I was trying to improve existing Stop.bat, provided along with StartXXX.bat scripts and assumed as "official" way to stop IBC. We use Start/Stop scripts from Task Scheduler and therefore they are executed on the same host. In this case it looks unnecessary to configure Stop.bat independently from the other part of IBC. Why we should specify CommandServerPort and ServerAddress in Stop.bat if we can take them from config.ini? Please note that this also means that we should remember to update these parameters in both places, if we have to do this. However I agree with you that for use case when Stop.bat is executed from the other host, it would be very undesirable to duplicate whole IBC and config.ini. And small standalone program would be more sensible. |
Ok, I understand where you're coming from, and why your PR works in the limited context of localhost. But please explain to me why you use Stop.bat at all if you're only running it from Task Scheduler on the same machine? Why don't you just set the auto-logoff time in TWS/Gateway? Or even use the It's not correct to say that Stop.bat is the "official" way to stop IBC. That's not really a meaningful term anyway, but the natural way to stop IBC is by the user simply exiting from TWS/Gateway. The fact is that the STOP command (ie to the command server) was originally provided as a way to shut down TWS/Gateway tidily when it is under the management of another program, and indeed there is a sample C# program (that's not currently in the IBC repository) that runs IBC as a service, enabling it to be started and stopped using the Services MMC. The STOP command also happens to be a convenient way to shut down IBC when it's running on a remote server and you can't get to the UI without a bit of hassle: and of course a prime example of that is if you start IBC from a scheduled task configured to run even if the user is not logged on, because then you can't get to the UI at all (but of course setting the auto-logoff time or Sorry, I'm out of time - there is more to say here, but I'll have to continue later... |
Continuing with this... The fact that your PR is limited to local usage doesn't mean it's of no value. It would still be helpful to provide an easy way to use the STOP command in a local context, especially since a frequent usage might be the not-logged-in task scheduler scenario where the current STOP.bat doesn't work at all. So here are some detailed comments on your proposal, in no particular order:
so all the other settings and corresponding notes can be removed.
. |
Stop.bat
now calls new java classibcalpha.ibc.IbcStop
the same way asibcalpha.ibc.IbcTws
andibcalpha.ibc.IbcGateway
are called byStartTWS.bat
andStartGateway.bat
.ibcalpha.ibc.IbcStop
in turn reads parametersCommandServerPort
andBindAddress
fromconfig.ini
.Besides reworking
Stop.bat
there are some slight improvements (I believe):HOMEDRIVE
andHOMEPATH
env vars where they mentioned;IBC_PATH
is deduced from the path of the current script. It can be handy whenIBC
is installed in non-standard directory (i.e not inC:\IBC
);PRESS_ANY_KEY_ON_ERROR
, which controls whether or notPress any key to close this window
is necessary. Waiting for user input is not desiable in non-interactive mode.