static void Init() { bool watchdog = !System.Diagnostics.Debugger.IsAttached; Log.Warning("Initializing backend. (watchdog? = {0})", watchdog); RequestDispatcher.CreateDispatchers(4); RequestBridge.CreatePipeServers(4); Edi.StartEdi(); //start health monitor. System.Diagnostics.Process.Start( Config.Get().SbmonPath, string.Format("-backend {0} -memcached {1} -mport {2} -watchdog {3}", System.Diagnostics.Process.GetCurrentProcess().Id, DataCacheInstance.ProcessId, Config.Get().MemcachedPort, watchdog)); LogService.Start(); Talk = new InternalTalk(true); Talk.OnTalk += Talk_OnTalk; }
static void Main(string[] args) { bool enableWatchdog; Log.Init("sbmon"); Log.EnableAll(); int backendPid, memcachedPid; var opts = Helper.ParseOptions(string.Join(" ", args)); talk = new InternalTalk(false); backendPid = GetVal <int>(opts, "-backend", 0); memcachedPid = GetVal <int>(opts, "-memcached", 0); MEMCACHED_PORT = GetVal <ushort>(opts, "-mport", 0); enableWatchdog = GetVal <bool>(opts, "-watchdog", true); if (backendPid == 0 && memcachedPid == 0) { Log.Critical("There are no pids supplied to monitor"); return; } if (!InstanceCheck()) { return; } if (enableWatchdog) { watchdog = new Watchdog(); watchdog.Start(); } else { Log.Warning("Watchdog disabled."); } if (backendPid > 0) { new HealthMonitor(backendPid, HealthMonitor.ProcessType.BackendProcess , RecoverPolicy.RecoverBackendAndPassExistedMemcachedInstance).Start(); } if (memcachedPid > 0) { new HealthMonitor(memcachedPid, HealthMonitor.ProcessType.MemcachedProcess, RecoverPolicy.RecoverMemcachedAndPassNewMemcachedInstance).Start(); } Console.CancelKeyPress += Console_CancelKeyPress; while (running) { Thread.Sleep(10); } if (enableWatchdog) { watchdog.Dispose(); } talk.Stop(); mutant.Dispose(); Log._Finalize(); }