Re: [topshelf-discuss] install and uninstall commands do not return

1,641 views
Skip to first unread message

Dru Sellers

unread,
Jun 5, 2013, 4:06:23 PM6/5/13
to topshelf...@googlegroups.com
it should return. something about the command is wrong and it is running in console mode. run the 'help' command and verify the correct command.

-d


On Wed, Jun 5, 2013 at 2:55 PM, Bruno Fiorentino <bruno.fi...@gmail.com> wrote:
I'm trying to automate installation via powershell in order to manage multiple services. Topshelf never returns when I execute "Service.exe install -servicename:Service -instance:01" or "Service.exe uninstall -servicename:Service -instance:01", so I need to CTLR+C.

It seems a bug that prevents automation, right? Any workarround?

--
You received this message because you are subscribed to the Google Groups "topshelf-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to topshelf-discu...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Bruno Fiorentino

unread,
Jun 5, 2013, 4:20:00 PM6/5/13
to topshelf...@googlegroups.com
I ran Service.exe help and checked the usage instructions, it seems I'm doing it ok. I also tried (from a Console2 based powershell console):

> powershell -noninteractive -noprofile -command ".\service.exe install -servicename:service -instance:01" 

And still does not return... 

Dru Sellers

unread,
Jun 5, 2013, 4:21:31 PM6/5/13
to topshelf...@googlegroups.com
what about from CMD

Bruno Fiorentino

unread,
Jun 5, 2013, 4:33:45 PM6/5/13
to topshelf...@googlegroups.com
Same problem. 
First i tried cmd "inside" powershell, later I openned a "pure cmd window".

Dru Sellers

unread,
Jun 5, 2013, 4:35:11 PM6/5/13
to topshelf...@googlegroups.com
what does your TS config look like. - what do teh logs say?

Bruno Fiorentino

unread,
Jun 5, 2013, 4:39:43 PM6/5/13
to topshelf...@googlegroups.com
I will enable logging with Log4Net.
The command line is:
> .\ACME.Host.exe install -servicename:Service -instance:01

Except for ACME, this is the code: 

using Topshelf;

namespace ACME.Host
{
    public static class Hoster
    {
        public static int Host(IWorker worker)
        {
            var topshelfExitCode =
                HostFactory.Run(
                    hostConfig =>
                    {
                        if (worker.CanPauseAndContinue())
                            hostConfig.EnablePauseAndContinue();

                        hostConfig.Service<IWorker>(
                            serviceConfig =>
                            {
                                serviceConfig.ConstructUsing(_ => worker);
                                serviceConfig.WhenStarted(x => x.Start());
                                serviceConfig.WhenPaused(x => x.Pause());
                                serviceConfig.WhenContinued(x => x.Continue());
                                serviceConfig.WhenStopped(x => x.Stop());
                                serviceConfig.WhenShutdown(x => x.Stop());
                            }
                        );

                        hostConfig.RunAsPrompt();
                    }
                );

            return (int)topshelfExitCode;

Bruno Fiorentino

unread,
Jun 5, 2013, 4:42:21 PM6/5/13
to topshelf...@googlegroups.com
And here is 'Main', which calls Hoster.Host(worker):

    static class Program
    {
        static int Main()
        {
            //using (var container = new WindsorContainer(new XmlInterpreter()))
            var container = new WindsorContainer(new XmlInterpreter());
            //{
                var mainWorker = container.Resolve<IWorker>("mainWorker");
                return Hoster.Host(mainWorker);
            //}

Dru Sellers

unread,
Jun 5, 2013, 4:45:48 PM6/5/13
to topshelf...@googlegroups.com
you will want to have your container spin up happen the TS start call. this allows for a cleaner / start stop.

-d

Dru Sellers

unread,
Jun 5, 2013, 4:46:16 PM6/5/13
to topshelf...@googlegroups.com
try a bare minimum TS (no biz code) and verify that it is working as expected. sometimes something else can hold a thread open.

Bruno Fiorentino

unread,
Jun 5, 2013, 5:21:53 PM6/5/13
to topshelf...@googlegroups.com
you are right: I tried a bare minimum setup and it returned/worked...
I'm going to fix my initialization.
Thanks!

Bruno Fiorentino

unread,
Jun 5, 2013, 5:50:27 PM6/5/13
to topshelf...@googlegroups.com
Fixed. Note for people using Topshelf and Quartz.Net:
Once you have instantiated a scheduler (Quartz) you have to call scheduler.Shutdown in order to properly dispose the instance *even* if you have not called scheduler.Start... the scheduler inner workings were preventing Topshelf to return/exit.

Chris Patterson

unread,
Jun 5, 2013, 7:04:39 PM6/5/13
to topshelf...@googlegroups.com
Yes, you are correct.

Also, you should do ALL container setup, everything, INSIDE of the constructUsing() service configuration method so that it is not invoked during service installation.

Travis Smith

unread,
Jun 7, 2013, 5:24:21 PM6/7/13
to topshelf...@googlegroups.com
Yeah, I just got jammed up today not disposing of something in Stop and it was hanging a shutdown. Dispose of your junk ;)

-Travis

Bruno Fiorentino

unread,
Jun 7, 2013, 10:39:48 PM6/7/13
to topshelf...@googlegroups.com
I'm usually very systematic in regard to resource disposal and, despite the container initialization out of Topshelf.ConstructUsing, the glue between my library and Topshelf was ok... but [internally] Quartz caught me off guard... as I had not called scheduler.Start() up to that point I thought the absence of an IDisposable implementation meant it wasn't "awake", but it was. 

Fixed these two bugs and everything works fine now: fast, "returnable" and automated batch installation. 

Thank you all.
Reply all
Reply to author
Forward
0 new messages