Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to start multiple services from one Console Application by Topshelf?

As TosShelf says:

"You can only have ONE service! As of 3.x Topshelf the base product no longer support hosting multiple services. "

as of version 3.x I need to figure out how to integrate the new version of Topshelf.

Question: Is it possible to start multiple separate services from one Console Application using Topshelf? How can I achieve that?

like image 243
pencilCake Avatar asked Feb 20 '13 07:02

pencilCake


2 Answers

Topshelf no longer supports this but a possible work around would be to implement a class to start multiple services.

Example:

// ServiceManager is used to start and stop multiple services
hostConfigurator.Service<ServiceManager>(s => 
{
        s.ConstructUsingNinject(); // service1 and service2 injected into ServiceManager
        s.WhenStarted(tc => tc.Start());
        s.WhenStopped(tc => tc.Stop());
});

The ServiceManager class then would just start and stop multiple services.

public class ServiceManager
{
    private readonly Service1 service1;
    private readonly Service2 service2;

    public ServiceManager(Service1 service1, Service2 service2)
    {
        this.service1= service1;
        this.service2= service2;
    }

    public void Start()
    {
        service1.Start();
        service2.Start();
    }

    public void Stop()
    {
        service1.Stop();
        service2.Stop();
    }
}
like image 146
Jason Rowe Avatar answered Nov 20 '22 12:11

Jason Rowe


As of now there is not a method to host multiple services in a single windows service nor are there plans to implement this functionality. Monitoring and managing these services isn't possible with existing tools which is one of the primary drivers for this decision.

like image 1
Travis Avatar answered Nov 20 '22 13:11

Travis