Topshlef 3.1.107.0 Service not starting only on windows server 2012 #183
Comments
I am having a similar issue - I get 1053 almost immediately when trying to start the service. Runs fine if I just run the exe. Happens on 2 servers (one of which is a Win7 machine), but not any others. I did upgrade the software on both of those locations and users were locking files at the time (I closed the file locks to install). I uninstalled and reinstalled the service, and rebooted the server (hoping it would release any file locking issues), but still no luck. |
I have possibly the same issue. Service remains in start pending status forever, but the service is working fine. The annoying thing is I cannot stop the service from the local services console. OS: Windows Server 2012 R2 DataCenter |
I have the same issue in windows 7. Service remains in start pending and for stopping it I should use "taskkill". |
The interesting thing is the services running account. I have multiple services that one doesn't start on any account but local "local system account" and others don't start on that but others. |
After a lot of searches finally, I found the issue. The problem was in my "start" method. This method has to call a service that doesn't respond in time. so windows service throws the timeout exception. I've changed the method and now I'm calling the service in the thread. |
@AliShahrivarian can you throw-up a quick line of code for me. I've been coding in F# so long my C# is very rusty. Just the simple C# TopShelf wrapper for my F# ddl is the only C# I've seriously looked at in a long time...thanks! |
So the "bug" is really in the sample code and documentation. Should show calling in a thread. Makes sense. |
Sorry for my late @jackfoxy . The bottom code is from the topshelf documentation https://topshelf.readthedocs.org/en/latest/configuration/quickstart.html: public class Program
{
public static void Main()
{
HostFactory.Run(x => //1
{
x.Service<TownCrier>(s => //2
{
s.ConstructUsing(name=> new TownCrier()); //3
s.WhenStarted(tc => tc.Start()); //4
s.WhenStopped(tc => tc.Stop()); //5
});
x.RunAsLocalSystem(); //6
x.SetDescription("Sample Topshelf Host"); //7
x.SetDisplayName("Stuff"); //8
x.SetServiceName("Stuff"); //9
}); //10
}
} The thing you'll get from the code commented Suppose you have this public bool start(){
// to do other config which run fast
while(true){
// to do something forever
}
return true;
} This method doesn't return anything to the Windows Service and works forever. Windows Service is waiting for a response and when it gets nothing it'll throw an exception. public bool start(){
// to do other configs which run fast
var myThread = new Thread(new ThreadStart(foreverWhile));
myThread.Start();
return true;
}
public void foreverWhile(){
while(true){
// to do something forever
}
} The thread will work independently and service will start. Update:For preventing the thread from working after service stop we use the public bool start(){
// to do other config which run fast
var myThread = new Thread(new ThreadStart(foreverWhile));
myThread.IsBackground = true; // This line will prevent thread from working after service stop.
myThread.Start();
return true;
}
public void foreverWhile(){
while(true){
// to do something forever
}
} |
And technically you should signal your background thread when Stop is called so that it can exit cleanly. |
Thanks, all. This worked out well for me. I suggest adding this tip prominently in documentation. I'm sure a lot of installations must run into similar situations, and its easy to overlook threading. |
@phatboyg if you could provide an example of how you would signal the thread on exit. |
I'm facing a similar problem here, my service works fine if I run on debug or release, but when I try to install and run via cmd the Start() method apparently is not being called. MyService.cs public bool Start()
{
var t = new Thread(new ThreadStart(Run));
t.Start();
return true;
}
public bool Stop()
{
return true;
}
private void Run()
{
while (true)
{
Logger.Info(interval.ToString());
interval++;
Thread.Sleep(1000);
}
} |
Thanks Ali Shahrivarian! Your suggestion saved the day. Creating the looping process code on a separate thread worked. It is strange, because I did not have to do this on an older version of Windows using .net 4.7.2, but I had to do this on the latest version of windows using .net version 4.8.0. |
Hi Guys,
I am having a problem where my topshelf service is not starting on Windows server 2012 but starts on all other windows servers.
As soon as I start the windows service I am instantly presented with a 1053 error: Did not respond in a timely fashion. even though it did not try to run for 30 secs but rather 1 second.
Once again note that this same service runs on all other Windows servers except for 2012. My Start() method does not even get fired.
I have not idea where else to look.
I have tried the following:
After the logging failed I replaced all logging with writing to the windows event log. No errors aside from the error 1053.
Here's an example of my Main constructor.
static void Main()
{
try
{
Your help is GREATLY appreciated.
The text was updated successfully, but these errors were encountered: