Search |
||
winsw: Windows service wrapper in less restrictive licensePosted by kohsuke on September 29, 2008 at 6:41 PM PDT
I reported earlier that Hudson can now install itself as a Windows service, and behind this technology is the reusable Windows service wrapper code I wrote, which is separately reusable and available in the "winsw" project. Why?Now, I think the first question that people would ask is, why another, when there's Java Service Wrapper project already available. The main reason for writing my own was the license — Java Service Wrapper project is in GPL (so that they can sell their commercial version in a different license), and that made it difficult for Hudson (which is under the MIT license) to use it. Functionality-wise, there's really not much that's worth noting; the problem of wrapping a process as a Windows service is so well defined that there aren't really any room for substantial innovation. You basically write a configuration file specifying how you'd like your process to be launched, and we provide programmatic means to install/uninstall/start/stop services. Another notable different is that winsw can host any executable, whereas Java Service Wrapper can only host Java apps. Whether you like this or not depends on your taste, so I wouldn't claim mine is better. It's just different. UsageYou write the configuration file that defines your service. This is the one I use for Hudson:
You'll rename winsw.exe into something like hudson.exe, then you put this XML file as hudson.xml. The executable locates the configuration file via this file name convention. You can then install the service like: hudson.exe install ... and you can use the exit code from these processes to determine whether the operation was successful. There are other commands to perform other operations, like uninstall. This project is available on Kenai (which is the new forge Sun is doing), along with a complete documentation, the source code, and the binary. Implementation highlightThe code is implemented in C# (which makes it super-easy to implement something like this, compared to doing so in C++.) I use a java.lang.reflect.Proxy-like technique so that I can perform WMI operations elegantly. It's been a while I've done .NET development, so this was fun. C# got several really nifty language features that make the code terse (which I'd love to see in Java), but OTOH the library still sucks — for example, the Proxy capability is not a part of the core library. On a related note, projects like com4j and JNA make it probably possible to do this entirely in Java. I think this would be an interesting hobby project for someone, so that people can avoid forking processes, which is always awkward. »
Related Topics >>
Java Tools Comments
Comments are listed in date ascending order (oldest first)
Submitted by boerkel on Tue, 2008-09-30 13:39.
Install/uninstall is included in the JNA Win32 service implementation.
Submitted by thomasd on Tue, 2008-09-30 14:04.
Hi,
cool Stuff :)
Btw. .Net offers a Dynamic Proxy Feature in the Standard Library.
System.Runtime.Remoting.Proxies.RealProxy;
Although it is intended for remote Proxies you can also use it to implement regular dynamic proxies - so you don't have to generate IL Code by hand :)
Have a look at this:
http://www.tutorials.de/forum/net-application-und-service-design/249443-...
Best regards,
Tom
Submitted by jan_bar on Wed, 2008-10-01 05:35.
Thanks for winsv. There is one bug in hudson.xml default configuration. Add -Xrs to prevent JVM termination on CTRL_LOGOFF_EVENT. Otherwise winstone will terminate on logoff.
Submitted by kohsuke on Wed, 2008-10-01 10:13.
jan_bar — Thanks for the fix. I incorporated that into 1.255.
thomasd &mash; Aha! Yeah, I guess with a bit more wrapping this would be enough for me. Thanks for the tip.
boerkel &madsh; Thanks. I think what I should start doing maybe is to ask if something already exists before I start implementing...
Submitted by mzehrer on Mon, 2008-09-29 23:45.
Nice project. But I miss the Java specific features for classpath configuration that Java Service Wrapper has.
Submitted by boerkel on Tue, 2008-09-30 00:20.
NIce feature. But why make .NET a requirement for a Java project? BTW, JNA already bundles a Win32 service implementation in Java.
Submitted by kohsuke on Tue, 2008-09-30 10:08.
mzehrer &mash; I think it's relatively easy to make a launcher part pluggable so that you don't have to write a lengthy "-classpath" option. I just didn't need it for Hudson because it doesn't have any classpath :-)
boerkel — Ah, I didn't know that. I guess I'd still have to write the install/uninstall part, no? As for .NET, I think it's available in almost all the modern Windows to the point that it's a non-issue. Besides, it's just so much more productive to do it in .NET than to do this in the plain C++.
|
||
|
|