Is there any way to restart a windows service from the same service , as Application.Restart() in Windows forms, I don't want to launch another process from the service to rest开发者_运维知识库art the service.
I am a developer for an open source windows service hosting framework called Daemoniq. Setting service recovery options is one of its features. You can download it from http://daemoniq.org
Current features include:
- container agnostic service location via the CommonServiceLocator
- set common service properties like serviceName, displayName, description and serviceStartMode via app.config
- run multiple windows services on the same process
- set recovery options via app.config
- set services depended on via app.config
- set service process credentials via command-line
- install, uninstall, debug services via command-line
Thanks!
You also can add Custom Action to Commit folder of Custom Actions in your setup project. It must be a primary output of class library project with class inherited from System.Configuration.Install.Installer with [RunInstaller(true)] attribute. In this class you need to override one base method:
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
ProcessStartInfo psi = new ProcessStartInfo("sc", "failure \"You service name\" reset= 60 actions= restart/1000");
psi.CreateNoWindow = true;
Process proc = Process.Start(psi);
proc.WaitForExit();
}
It's configuring your service to restart automaticaly after failure.
Than when you need to restart your service you can do
Environment.FailFast("Self restarting service...");
But it has one drawback - it will be fired an error message in event log.
精彩评论