Saturday, July 23, 2011

Got my remote process server working.

So I made a few changes, and now my client can pick up the stdout of a remote process, disconnect from it, and  reattach if need be.  The first problem I ran into was properly passing in the Channel object that got generated when a connection between the client and server was made.  This also had the added effect that the process on the remote machine does not actually start until the connection was made.

The thing that really threw me though was why once I made the above change, the client wasn't receiving anything over the channel.  At first I thought maybe I had to make a netty ChannelFuture object, due to the asynchronous nature of netty itself.

It is however working now, including the ability to send a few commands (that go over the channel from the client to the server) to the remote process's standard input.  I can now edit the command string, show the command, kill the process, or restart it.  I still need to work on changing the environment variables or working directory however.  The other big limitation, and one that I don't think I can or will workaround is the ability to log in as a different user.

This is where SSH shines.  With SSH you can log in as a specific user and get all the permissions that user has.  My server will run with the same user ID and permissions as whomever launched the initial TaskServer process. This has its cons of course, but still, I think this is ok.

The next thing I'll do is add the ability to run multiple processes per TaskServer.  The trick here will be encoding the output from the different processes in such a way that the client can piece together what output came from what process.  The most obvious thought that comes to mind is to simply append some key to the line of output (since I am using netty's line delimiter encoder/decoder).  This would require the ability to filter the incoming line to the client, and I think that could be a speed issue.  A second option could be to not use line delimiter, and roll my own encoder/decoder, but that will be quite a bit more work.

Still, I think the little server is kinda cool.  I still need to officially give it a license, and I've been leaning towards the Eclipse Public License.  I'm also considering switching to using Git, and having it hosted on github or some other service.  I'm starting to learn git for a couple of reasons:

1.  It appears to be more popular than mercurial
2.  Using jgit, it is easy to provide as a client
3.  I want to use gerrit for code reviews

Many projects appear to be moving towards git.  Eclipse now uses egit/jgit as the default Team provider now (instead of SVN).  And although Sun seemed fond of mercurial, many java projects, are using git.  Clojure and Android are two popular ones that are of interest to me using git now.  Git does seem more complicated than mercurial, not that I'm an advanced user of mercurial by any means.  But having this project using git will help me learn git as well.