Updated to 2.2.2.0, Now Cannot start Windows service

1,246 views
Skip to first unread message

Andrei Sedoi

unread,
Jul 7, 2011, 4:16:43 PM7/7/11
to topshelf-discuss
Updated Topshelf library to 2.2.2.0. Now I cannot start Windows
service. The following error appears:
"Error 1053: The service did not respond to the start or control
request in a timely fashion."
Are there some breaking changes in 2.2.2.0?

Dru Sellers

unread,
Jul 7, 2011, 4:38:07 PM7/7/11
to topshelf...@googlegroups.com
There should not be.

How are you using topshelf? (your own exe?, topshelf.host.exe?)

-d

Chris Patterson

unread,
Jul 7, 2011, 4:45:46 PM7/7/11
to topshelf...@googlegroups.com
Also, what version did you upgrade from?

On Thu, Jul 7, 2011 at 3:16 PM, Andrei Sedoi <bsn...@gmail.com> wrote:

Travis Smith

unread,
Jul 7, 2011, 5:01:28 PM7/7/11
to topshelf...@googlegroups.com, topshelf...@googlegroups.com
If you uninstall then reinstall the service, it might correct the issue. When we changed some command line options, this could have messed things up, especially related to named instances. 

Failing that, can you provide log4net output or event log entry of it failing? 

-Travis

bsnote

unread,
Jul 8, 2011, 4:35:06 AM7/8/11
to topshelf-discuss
I don't use Topshelf as a service host, so I don't use topshelf.host.exe.
Upgraded from the version 2.2.1.11103

>> If you uninstall then reinstall the service, it might correct the issue.
it doesn't help

here is how I use it:

        HostFactory.Run(
                c =>
                {
                    c.Service<IMyService>(
                        s =>
                        {
                            s.ConstructUsing(() => kernel.Get<IMyService>());
                            s.WhenStarted(service => service.Start());
                            s.WhenStopped(service => service.Stop());
                        });

                    c.RunAsLocalSystem();
                    c.SetDescription(WindowsServiceDescription);
                    c.SetDisplayName(WindowsServiceName);
                    c.SetServiceName(WindowsServiceName);
                    c.StartAutomatically();
                });

And here is my installer class:

    [RunInstaller(true)]
    public class WindowsServiceInstaller : Installer
    {
        const string AssemblyIdentifier = "MyServiceAssembly";
        const string InstallUtilAssemblyParameter = "assemblypath";
        const string ArgumentInstall = "install";
        const string ArgumentUninstall = "uninstall";

        public override void Install(IDictionary stateSaver)
        {
            var topshelfAssembly = Context.Parameters[InstallUtilAssemblyParameter];
            stateSaver.Add(AssemblyIdentifier, topshelfAssembly);

            RunHidden(topshelfAssembly, ArgumentInstall);

            base.Install(stateSaver);
        }

        public override void Uninstall(IDictionary savedState)
        {
            var topshelfAssembly = savedState[AssemblyIdentifier].ToString();

            RunHidden(topshelfAssembly, ArgumentUninstall);

            base.Uninstall(savedState);
        }

        static void RunHidden(string primaryOutputAssembly, string arguments)
        {
            var startInfo = new ProcessStartInfo(primaryOutputAssembly, arguments)
            {
                WindowStyle = ProcessWindowStyle.Hidden,
            };

            using (var process = Process.Start(startInfo))
            {
                process.WaitForExit();

Dru Sellers

unread,
Jul 8, 2011, 7:18:56 AM7/8/11
to topshelf...@googlegroups.com
Well we can get rid of the installer class. Topshelf does all of that for you. Maybe that's the problem. Take a look at the sample app "stuff" in the sources at http://github.com/topshelf/topshelf

-d

Chris Patterson

unread,
Jul 8, 2011, 10:58:54 AM7/8/11
to topshelf...@googlegroups.com
Yeah, get rid of that installer, that's all handled by Topshelf. Are you trying to use InstallUtil or something with it? That's all internalized into Topshelf itself.

bsnote

unread,
Jul 10, 2011, 11:19:19 AM7/10/11
to topshelf...@googlegroups.com
Well, I removed the installer class. Now the service is not installed when I run MSI package. I wonder how does Topshelf do all this for me? MSI just runs the code from Installer classes.

Thanks

Dru Sellers

unread,
Jul 10, 2011, 11:27:05 AM7/10/11
to topshelf...@googlegroups.com
Hello,

I am not a user of MSI's so I don't know much about what's going on there. The the use case is usually one where you can copy all of the dlls to a folder, then in a console window just type 'yourApplication.exe install' and its done. i am not sure how this would be done from an MSI. Is that a key part of your delivery solution?

-d

-d

bsnote

unread,
Jul 10, 2011, 11:57:41 AM7/10/11
to topshelf...@googlegroups.com
Hello,

That is exactly what my installer class does. It just runs 'myApp.exe install' and hides console window. I've tried to install it manually just typing 'myApp.exe install'. It is installed successfully but when I try to run the service it shows the original error: "Error 1053: The service did not respond to the start or control request in a timely fashion." Topshelf logs nothing (should I just copy log4net.dll and log4net.config files to my myApp.exe directory?) Windows Event Viewer shows two events:

1) Event 7009: A timeout was reached (30000 milliseconds) while waiting for the My Service service to connect.
2) Event 7000: The My Service service failed to start due to the following error: The service did not respond to the start or control request in a timely fashion.

It seems to be some a problem in my code. But it works ok with the previous version of Topshelf library.


Andrei

Dru Sellers

unread,
Jul 10, 2011, 12:00:59 PM7/10/11
to topshelf...@googlegroups.com
does it work ok, when run as a console?

-d

bsnote

unread,
Jul 10, 2011, 1:12:04 PM7/10/11
to topshelf...@googlegroups.com
yes, it works when I run it as a console.

Dru Sellers

unread,
Jul 10, 2011, 1:15:06 PM7/10/11
to topshelf...@googlegroups.com
does it start if you just install the service by hand and the run the service?

-d

bsnote

unread,
Jul 10, 2011, 1:49:16 PM7/10/11
to topshelf...@googlegroups.com
No, it doesn't start. Well, I can reproduce it with Stuff sample service. Just add Debugger.Break() line in the beginning of main method. It breaks at that place when I install it like this "TownCrier.exe install". Just continue after breaking, it installs successfully. Try to start the service "sc start TownCrier". It shows the error 1053.

        static void Main(string[] args)
        {
            Debugger.Break();

            HostFactory.Run(x =>
            {
                x.Service<TownCrier>(s =>
                {
                    s.ConstructUsing(name => new TownCrier());
                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Stop());
                });

                x.RunAsLocalSystem();
                x.SetServiceName("TownCrier");
            });
        }

    public class TownCrier
    {
        readonly Timer timer;

        public TownCrier()
        {
            timer = new Timer(1000) { AutoReset = true };
            timer.Elapsed += (sender, eventArgs) => Console.WriteLine("It is {0} an all is well", DateTime.Now);
        }

        public void Start()
        {
            timer.Start();
        }

        public void Stop()
        {
            timer.Stop();
        }
    }

bsnote

unread,
Jul 10, 2011, 2:01:38 PM7/10/11
to topshelf...@googlegroups.com
Just to add: the sample below doesn't work with the previous version (2.2.1.11103) of Topshelf library as well.

bsnote

unread,
Jul 11, 2011, 11:53:43 AM7/11/11
to topshelf...@googlegroups.com
I sorted it out. The problem is that the service name contains spaces ("A a"). Below is the reproduction:

static void Main()
{
    HostFactory.Run(c =>
    {
        c.Service<Service>(
            s =>
            {
                s.ConstructUsing(() => new Service());
                s.WhenStarted(service => service.Start());
                s.WhenStopped(service => service.Stop());
            }).
            SetServiceName("A a");
    });
}

I wonder why a service name should not contain spaces? And what is the difference between setting service name inside the lambda expression and outside.

Also what does c.EnableDashboard() do for me?


Thanks,
Andrei

Dru Sellers

unread,
Jul 11, 2011, 11:54:54 AM7/11/11
to topshelf...@googlegroups.com
EnableDashboard is an alpha feature for an html dashboard to control the services.

that's odd that a space is causing an issue.

-d

bsnote

unread,
Jul 11, 2011, 11:58:30 AM7/11/11
to topshelf...@googlegroups.com
Probably because Topshelf inserts the service name as is without quotes.

Chris Patterson

unread,
Jul 11, 2011, 7:55:42 PM7/11/11
to topshelf...@googlegroups.com
I'm pretty sure Windows Service Control Manager does not allow spaces for service names either.

Victor Hugues

unread,
Jul 24, 2013, 12:03:34 PM7/24/13
to topshelf...@googlegroups.com
All Native Windows Service Names contains spaces, so, this is a Topshelf's bug.

Travis Smith

unread,
Jul 24, 2013, 12:52:40 PM7/24/13
to topshelf...@googlegroups.com
The Display Name in service manager can have spaces. The "Service Name" cannot. This is not a bug in Topshelf. 

You can check yourself, double click on each service in service manager and look at the "Service Name" field - the first one on the General tab. 

For example, the service listed as "Microsoft .NET Framework NGEN v4.0.30319_X86" shows the service name of "clr_optimization_v4.0.30319_32". 

-Travis


--
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.
 
 

Reply all
Reply to author
Forward
0 new messages