Two disparate servers need to communicate
February 26, 2009 6:48 AM   Subscribe

A Windows server needs to tell a Linux Web server to change the contents of a Web page. I don't know how the first can communicate this to the second, or how the second can then make the change.

We have two servers:
[A] runs Windows Server 2003 (no http server).
[B] runs Linux, and Tomcat is its http server.

The home page on [B] is login.jsp and normally displays "Welcome".

When a particular C# program begins running on [A], login.jsp needs to display "[B] is not available".

When the program on [A] finishes, login.jsp needs to again display "Welcome".

BTW I'm more comfortable with Windows than with Linux. Thanks for any input.
posted by davcoo to Computers & Internet (7 answers total)
 
I make no claim to understand any of this completely. However, can the two servers share a database or a common location where a flag can be set? The C# program will set the flag to 1 when it begins running and set it to 0 when it is done.

login.jps will check the flag before it displays it's message - and if the flag is 1 it says "[B] is not available." or if it is 0 it says "Welcome".

It may be one of those things that is easier said that done - but this seems like it would be easily implemented as long as you had access to the code on both machines.
posted by Brettus at 6:56 AM on February 26, 2009


Looking at this as a question of two servers communicating makes it seem more complex than it is. Fundamentally what you're looking for is some way for your JSP code to detect whether a remote Windows process is running.

If you install the Windows SNMP agent, you can easily query that for a list of all processes running. Introducing an SNMP library to your Java code might be a little heavy, but you could also do it by calling a command-line snmp tool like "snmpwalk".

Alternatively, if you have some way of sharing state (a database or even a shared directory) you could create a flag there. The simplest possible way would be to have the Windows program create an empty file on a network drive and remove it when it's done. JSP just has to check for its existence. This is less reliable because the Windows program crashing would leave a stale file there and you'd have to clean it up by hand, but it's easy to implement.
posted by pocams at 7:13 AM on February 26, 2009


It all depends what you have running on the Linux server-- if you have a SSH server running, you could just have a little script that logins from the windows machine and creates, or deletes a file (or flag within a file), which the linux machine checks with a cron job.

As Brettus mentioned, if there's a database running, the window's machine could login and update a table, Python might be a good starting point for that, as it has numerous libraries that will likely tie up with the database you're using.

Perhaps you've only got port 80 open, you could simply send a http command to make it happen.

http://www.yourserver.com/flag.jsp?active=1

The linux server, on the flag.jsp see's if it's passed a 1 or 0 for the active variable and does the file/database update itself. Using something like Curl, you could actually pass a username, password etc to make it slightly more secure, or make the flag.jsp page reject everything not from IP address a.b.c.d.
posted by Static Vagabond at 7:21 AM on February 26, 2009


Seconding static vagabond's comment as the fastest, simplest, and probably most reliable way to do it. Curl on the windows box accesses a password protected URL on the linux box to pass the flag; Apache can check the client IP to verify the source. That sets the flag, and then another access turns it off. You can add a timeout on the linux side such that if the flag has been set and turned off within, say, 1 hour, it does it automatically. You could even have Curl on the Windows boxes 'ping' the Linux box this way every minute, say, and simply stop when it's done; then set the timeout to 2 minutes.

If the linux box has multiple NICs, you can configure it so that one NIC is external access (i.e., web) and the other internal, and then only flag requests on the internal NIC in Apache. You could also generate your own certificates and secure the flag URL with SSL, requiring authentication by client certificate, if you really want to lock it down.
posted by fatbird at 7:55 AM on February 26, 2009 [1 favorite]


I think all these solutions above would work well..

Another thing might be run Samba on the Linux server and have the Windows box mount the Linux server as a drive. When the processes run on the Linux box it can create a lock file on the Linux server. Also you can the the Linux box mount the Windows box as a file system too.
posted by cowmix at 8:42 AM on February 26, 2009


Response by poster: Thanks for all your suggestions and ideas. I was unaware of most of the software solutions you mentioned and I think we can come up with a good solution from this.
posted by davcoo at 10:58 AM on February 26, 2009


You can embed a command within the authorized_keys file on one host (to tighten security even further). Oh, and Cygwin can provide a Bash shell & SSH on the Windows server. That way you can go in either direction, with the specified command being somethign as lame as `cat ~/status_file.txt` or something.
posted by wenestvedt at 11:21 AM on February 26, 2009


« Older What to do in the 'Noog?   |   Can I turn a family loan into a loan that... Newer »
This thread is closed to new comments.