TopShelf patch - specifying a custom command line during service install

87 views
Skip to first unread message

Matt Burton

unread,
Oct 18, 2009, 1:44:34 AM10/18/09
to masstrans...@googlegroups.com
Some of the recurring themes that have come up for us as users have
started to consume the new NServiceBus generic host that's built on
TopShelf are a) how do I specify user credentials during service
installs and b) how do I install a service that takes command line
parameters? While I was able to solve the former within the
NServiceBus host directly (a combination of the TopShelf arg parser
and the "RunAs(username, password)" feature) the latter required a
TopShelf patch, which you'll find attached. It should be relatively
self explanatory, basically when configuring a service you can now do:

x.SetServiceName(EndpointId);
x.SetDescription("NServiceBus Message Endpoint Host Service");

x.SetServiceCommandLine(arguments.CustomArguments.AsCommandLine());

I also took the liberty of enhancing the args support as that last
line shows - added a "CustomArguments" which represents a collection
of IArgument instances which do not map to those core parameters
understood by TopShelf - install, uninstall, service, etc... The
"AsCommandLine" extension method is basically a way to convert an
IEnumerable<IArgument> into a properly formatted command line string
that in this case is then being appended to the ImagePath when
installing the service.

Let me know if you have any questions or comments - thanks,
Matt

ServiceCommandLineSupport.patch

Matt Burton

unread,
Oct 24, 2009, 8:19:45 PM10/24/09
to masstrans...@googlegroups.com
Just wanted to check in - have you guys had a chance to review this
patch? We're looking to put another NServiceBus release out and right
now we're using a custom build of TopShelf, so it would be nice to use
an official build instead.

Thanks for all the hard work on TopShelf - it's been a pleasure to work with!
Matt

Dru Sellers

unread,
Oct 24, 2009, 8:51:55 PM10/24/09
to masstrans...@googlegroups.com
Hi Matt,

Yes I checked it out this morning, I am in the middle of a Topshelf reorg trying to clear things up a bit and was hoping to get that done and then add this, but I may need a bit more time to get the reorg done. I didn't see anything that set off an alarm, so I will plan to commit it tomorrow after one more pass through the code.

-d

Matt Burton

unread,
Oct 25, 2009, 10:23:13 AM10/25/09
to masstrans...@googlegroups.com
Excellent - thanks Dru!

Dru Sellers

unread,
Oct 27, 2009, 5:11:32 AM10/27/09
to masstrans...@googlegroups.com
rev 94.
If you get a chance take a look at the reorg branch, may need some help applying it there too.

-d

Matt Burton

unread,
Oct 28, 2009, 5:50:05 PM10/28/09
to masstrans...@googlegroups.com
Dru -

Excellent - thanks - most appreciated! I'll take a look into patching
the reorg branch with these changes hopefully this weekend - wrapping
up a nasty project right now so no promises :)

Thanks,
Matt

Dru Sellers

unread,
Oct 28, 2009, 6:34:32 PM10/28/09
to masstrans...@googlegroups.com
No prob

-d

Matt Burton

unread,
Nov 6, 2009, 2:24:17 PM11/6/09
to masstrans...@googlegroups.com
Finally had some free cycles to do this but unfortunately hit a snag
on part of it. In the re-org branch it looks like you're in the middle
of converting over to the Magnum command line parser, so this bit
doesn't have a home yet:

===================================================================
--- src/Topshelf/Internal/Parser.cs (revision 89)
+++ src/Topshelf/Internal/Parser.cs (working copy)
@@ -41,7 +41,7 @@
IArgumentParser _argumentParser = new ArgumentParser();
IEnumerable<IArgument> arguments = _argumentParser.Parse(args);
IArgumentMap mapper = _argumentMapFactory.CreateMap(result);
- IEnumerable<IArgument> remaining = mapper.ApplyTo(result,
arguments);
+ result.CustomArguments = mapper.ApplyTo(result, arguments);

return result;
}
@@ -73,6 +73,7 @@
[Argument(Key="instance")]
public string InstanceName { get; set; }

+ public IEnumerable<IArgument> CustomArguments { get; set; }

public NamedAction GetActionKey()
{

I'm attaching a partial patch for the rest of it, but unfortunately
until the new command line parsing is done I don't know what to do
with this part.

Thanks,
Matt
PartialServiceCommandLineSupport.patch

Dru Sellers

unread,
Nov 26, 2009, 6:39:16 AM11/26/09
to masstrans...@googlegroups.com
might take a look now that i am in the trunk
-d

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To post to this group, send email to masstrans...@googlegroups.com
To unsubscribe from this group, send email to masstransit-dis...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/masstransit-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---


Reply all
Reply to author
Forward
0 new messages