/// <summary> /// Application_End /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Application_End(Object sender, EventArgs e) { if (verbose) { Console.Error.WriteLine("Simias Process Starting Shutdown"); } if (serviceManager != null) { // Send the simias down event and wait for 1/2 second for the message to be routed. EventPublisher eventPub = new EventPublisher(); eventPub.RaiseEvent(new NotifyEventArgs("Simias-Down", "The simias service is terminating", DateTime.Now)); Thread.Sleep(500); serviceManager.StopServices(); serviceManager.WaitForServicesStopped(); serviceManager = null; } if (verbose) { Console.Error.WriteLine("Simias Process Shutdown"); } quit = true; // Exiting here immediately as delay in this exit usually means that the next process started will // will not get FLAIM Resources. if (runAsServer) { int param = 0; KillStrayProcesses(param); Console.Error.WriteLine("ALL Simias Threads are stopped, Exiting from Simias process"); Environment.Exit(0); } }
/// <summary> /// Application_Start /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Application_Start(Object sender, EventArgs e) { #if WINDOWS // update the prefix of the installed directory // but only if we are on windows SimiasSetup.prefix = Path.Combine(Server.MapPath(null), "..\\..\\.."); #endif Environment.CurrentDirectory = SimiasSetup.webbindir; if (verbose) { Console.Error.WriteLine("Simias Process Starting"); } if (runAsServer) { string certString = System.Configuration.ConfigurationSettings.AppSettings.Get("SimiasCert"); if (certString != null && certString != "" && certString != String.Empty) { Console.Error.WriteLine("Certstring {0}", certString); // certificate policy ServicePointManager.CertificatePolicy = new SingleCertificatePolicy( new X509Certificate(Convert.FromBase64String(System.Configuration.ConfigurationSettings.AppSettings.Get("SimiasCert")))); } } serviceManager = Simias.Service.Manager.GetManager(); serviceManager.RunAsServer = runAsServer; serviceManager.StartServices(); serviceManager.WaitForServicesStarted(); // Send the simias up event. EventPublisher eventPub = new EventPublisher(); eventPub.RaiseEvent(new NotifyEventArgs("Simias-Up", "The simias service is running", DateTime.Now)); if (verbose) { Console.Error.WriteLine("Simias Process Running"); } // start keep alive // NOTE: We have seen a FLAIM corruption because the database was not given // the opportunity to close on shutdown. The solution is to work with // Dispose() methods with the native calls and to control our own life cycle // (which in a web application is difficult). It would mean separating the // database application from the web application, which is not very practical // today. We can bend the rules in the web application by using a foreground // thread. This is a brittle solution, but it seems to work today. keepAliveThread = new Thread(new ThreadStart(this.KeepAlive)); keepAliveThread.Name = "Keep Alive Thread"; keepAliveThread.Priority = ThreadPriority.BelowNormal; quit = false; keepAliveThread.Start(); }
public void Cleanup() { try { if (serviceManager != null) { serviceManager.StopServices(); serviceManager.WaitForServicesStopped(); serviceManager.Uninstall(threadServiceName); serviceManager.Uninstall(processServiceName); serviceManager = null; } } catch {} }
public void Init() { serviceManager = Simias.Service.Manager.GetManager(); serviceManager.Install(new ThreadServiceCtl(conf, threadServiceName, "ThreadServiceTest.dll", "Simias.Service.ThreadServiceTest")); serviceManager.Install(new ProcessServiceCtl(conf, processServiceName, "ProcessServiceTest.exe")); }