Exemple #1
0
        public static void Start()
        {
            javaStartCmd           = @"cd " + Configuration.JavaBackendPath + " && Run.bat";
            erlStartCmd            = @"cd " + Configuration.ErlangPath + " && Run.bat";
            erlInstallCmd          = @"cd " + Configuration.ErlangPath + " && RegisterService.bat";
            erlStartInteractiveCmd = @"cd " + Configuration.ErlangPath + " && InteractiveRun.bat";

            DelPids();

            KillProcByName("erl");
            KillProcByName("werl");
            KillProcByName("java");

            EnvVar[] erlEnv = new EnvVar[] {
                new EnvVar("MYDLP_CONF", GetShortPath(Configuration.MydlpConfPath).Replace(@"\", @"/")),
                new EnvVar("MYDLPBEAMDIR", GetShortPath(Configuration.ErlangPath)),
                new EnvVar("MYDLP_APPDIR", GetShortPath(Configuration.AppPath)),
                new EnvVar("ERLANG_HOME", GetShortPath(Configuration.ErlangHome))
            };

            int phyMemory  = GetPhysicalMemory();
            int javaMemory = 256;

            if (phyMemory < 300)
            {
                Logger.GetInstance().Error("Not enough memory, MyDLP Engine can not function under 300 MB memory");
                Engine.Stop();
                return;
            }

            else if (phyMemory < 600)
            {
                javaMemory = 256;
            }

            else
            {
                javaMemory = 256 + ((phyMemory - 600) / 4);

                if (javaMemory > xmx32BitLimit)
                {
                    javaMemory = xmx32BitLimit;
                }
            }

            Logger.GetInstance().Info("Setting Java memory: " + javaMemory);


            EnvVar[] javaEnv = new EnvVar[] {
                new EnvVar("JRE_BIN_DIR", GetShortPath(Configuration.JavaBinPaths)),
                new EnvVar("BACKEND_DIR", GetShortPath(Configuration.JavaPath)),
                new EnvVar("MYDLP_APPDIR", GetShortPath(Configuration.AppPath)),
                new EnvVar("JAVAXMX", javaMemory.ToString())
            };


            if (!System.Environment.UserInteractive && SvcController.IsServiceInstalled("mydlpengine"))
            {
                if (SvcController.IsServiceRunning("mydlpengine"))
                {
                    SvcController.StopService("mydlpengine", 5000);
                }

                ProcessControl.ExecuteCommandSync(new ExecuteParameters("sc delete mydlpengine", "SC", erlEnv));
            }

            try
            {
                using (RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Ericsson\\Erlang", true))
                {
                    key.DeleteSubKeyTree("ErlSrv");
                }
            }
            catch
            {
                //Logger.GetInstance().Info("Unable to delete uneccessary keys or keys do not exists");
            }

            Logger.GetInstance().Info("Starting Java Backend");


            ProcessControl.ExecuteCommandAsync(javaStartCmd, "JAVA:", javaEnv);

            Configuration.SetErlConf();

            Logger.GetInstance().Info("Starting Erlang Backend");
            if (System.Environment.UserInteractive)
            {
                ProcessControl.ExecuteCommandAsync(erlStartInteractiveCmd, "WERL", erlEnv);
            }
            else
            {
                ProcessControl.ExecuteCommandAsync(erlStartCmd, "ERL", erlEnv);
            }
        }
Exemple #2
0
        public static void Stop()
        {
            Logger.GetInstance().Info("Stopping Erlang Backend");

            /*
             * Logger.GetInstance().Debug("Kill erlang by pid:" + Configuration.ErlPid);
             * if (Configuration.ErlPid != 0)
             * {
             *  try
             *  {
             *      Process p = Process.GetProcessById(Configuration.ErlPid);
             *      p.Kill();
             *  }
             *  catch
             *  {
             *      Logger.GetInstance().Debug("Kill erlang by pid failed:" + Configuration.ErlPid);
             *  }
             * }*/

            if (System.Environment.UserInteractive)
            {
                KillProcByName("werl");
            }
            else
            {
                KillProcByName("erl");
            }
            KillProcByName("epmd");

            Logger.GetInstance().Info("Stopping Java Backend");

            /*
             * Logger.GetInstance().Debug("Kill java by pid:" + Configuration.JavaPid);
             * if (Configuration.JavaPid != 0)
             * {
             *  try
             *  {
             *      Process p = Process.GetProcessById(Configuration.JavaPid);
             *      p.Kill();
             *  }
             *  catch
             *  {
             *      Logger.GetInstance().Debug("Kill java by pid failed:" + Configuration.JavaPid);
             *  }
             * }*/

            KillProcByName("java");


            if (!System.Environment.UserInteractive && SvcController.IsServiceInstalled("mydlpengine"))
            {
                if (SvcController.IsServiceRunning("mydlpengine"))
                {
                    SvcController.StopService("mydlpengine", 5000);
                }


                EnvVar[] erlEnv = new EnvVar[] {
                    new EnvVar("MYDLP_CONF", GetShortPath(Configuration.MydlpConfPath).Replace(@"\", @"/")),
                    new EnvVar("MYDLPBEAMDIR", GetShortPath(Configuration.ErlangPath)),
                    new EnvVar("MYDLP_APPDIR", GetShortPath(Configuration.AppPath)),
                    new EnvVar("ERLANG_HOME", GetShortPath(Configuration.ErlangHome))
                };

                ProcessControl.ExecuteCommandSync(new ExecuteParameters("sc delete mydlpengine", "SC", erlEnv));
            }

            DelPids();

            try
            {
                using (RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Ericsson\\Erlang", true))
                {
                    key.DeleteSubKeyTree("ErlSrv");
                }
            }
            catch
            {
                //Logger.GetInstance().Info("Unable to delete uneccessary keys or keys do not exists");
            }
        }
 public ExecuteParameters(String command, String prefix, EnvVar[] env)
 {
     Command = command;
     Prefix = prefix;
     Env = env;
 }
 public static void ExecuteCommandAsync(string command, string prefix, EnvVar[] env)
 {
     try
     {
         Thread objThread = new Thread(new ParameterizedThreadStart(ExecuteCommandSync));
         objThread.Start(new ExecuteParameters(command, prefix, env));
     }
     catch (ThreadStartException e)
     {
         Logger.GetInstance().Error(e);
     }
     catch (ThreadAbortException e)
     {
         Logger.GetInstance().Error(e);
     }
     catch (Exception e)
     {
         Logger.GetInstance().Error(e);
     }
 }
        public static void Stop()
        {
            Logger.GetInstance().Info("Stopping Erlang Backend");
            /*
            Logger.GetInstance().Debug("Kill erlang by pid:" + Configuration.ErlPid);
            if (Configuration.ErlPid != 0)
            {
                try
                {
                    Process p = Process.GetProcessById(Configuration.ErlPid);
                    p.Kill();
                }
                catch
                {
                    Logger.GetInstance().Debug("Kill erlang by pid failed:" + Configuration.ErlPid);
                }
            }*/

            if (System.Environment.UserInteractive)
            {
                KillProcByName("werl");
            }
            else
            {
                KillProcByName("erl");
            }
            KillProcByName("epmd");

            Logger.GetInstance().Info("Stopping Java Backend");
            /*
            Logger.GetInstance().Debug("Kill java by pid:" + Configuration.JavaPid);
            if (Configuration.JavaPid != 0)
            {
                try
                {
                    Process p = Process.GetProcessById(Configuration.JavaPid);
                    p.Kill();
                }
                catch
                {
                    Logger.GetInstance().Debug("Kill java by pid failed:" + Configuration.JavaPid);
                }
            }*/

            KillProcByName("java");

            if (!System.Environment.UserInteractive && SvcController.IsServiceInstalled("mydlpengine"))
            {
                if (SvcController.IsServiceRunning("mydlpengine"))
                {
                    SvcController.StopService("mydlpengine", 5000);
                }

                EnvVar[] erlEnv = new EnvVar[] {
                new EnvVar("MYDLP_CONF", GetShortPath(Configuration.MydlpConfPath).Replace(@"\", @"/")),
                new EnvVar("MYDLPBEAMDIR",GetShortPath(Configuration.ErlangPath)),
                new EnvVar("MYDLP_APPDIR",GetShortPath(Configuration.AppPath)),
                new EnvVar("ERLANG_HOME", GetShortPath(Configuration.ErlangHome))
                };

                ProcessControl.ExecuteCommandSync(new ExecuteParameters("sc delete mydlpengine", "SC", erlEnv));
            }

            DelPids();

            try
            {
                using (RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Ericsson\\Erlang", true))
                {
                    key.DeleteSubKeyTree("ErlSrv");
                }
            }
            catch
            {
                //Logger.GetInstance().Info("Unable to delete uneccessary keys or keys do not exists");
            }
        }
        public static void Start()
        {
            javaStartCmd = @"cd " + Configuration.JavaBackendPath + " && Run.bat";
            erlStartCmd = @"cd " + Configuration.ErlangPath + " && Run.bat";
            erlInstallCmd = @"cd " + Configuration.ErlangPath + " && RegisterService.bat";
            erlStartInteractiveCmd = @"cd " + Configuration.ErlangPath + " && InteractiveRun.bat";

            DelPids();

            KillProcByName("erl");
            KillProcByName("werl");
            KillProcByName("java");

            EnvVar[] erlEnv = new EnvVar[] {
                new EnvVar("MYDLP_CONF", GetShortPath(Configuration.MydlpConfPath).Replace(@"\", @"/")),
                new EnvVar("MYDLPBEAMDIR",GetShortPath(Configuration.ErlangPath)),
                new EnvVar("MYDLP_APPDIR",GetShortPath(Configuration.AppPath)),
                new EnvVar("ERLANG_HOME", GetShortPath(Configuration.ErlangHome))
            };

            int phyMemory = GetPhysicalMemory();
            int javaMemory = 256;

            if (phyMemory < 300)
            {
                Logger.GetInstance().Error("Not enough memory, MyDLP Engine can not function under 300 MB memory");
                Engine.Stop();
                return;
            }

            else if (phyMemory < 600)
            {
                javaMemory = 256;
            }

            else
            {
                javaMemory = 256 + ((phyMemory - 600) / 4);

                if (javaMemory > xmx32BitLimit)
                    javaMemory = xmx32BitLimit;
            }

            Logger.GetInstance().Info("Setting Java memory: " + javaMemory);

            EnvVar[] javaEnv = new EnvVar[] {
                new EnvVar("JRE_BIN_DIR", GetShortPath(Configuration.JavaBinPaths)),
                new EnvVar("BACKEND_DIR", GetShortPath(Configuration.JavaPath)),
                new EnvVar("MYDLP_APPDIR", GetShortPath(Configuration.AppPath)),
                new EnvVar("JAVAXMX",javaMemory.ToString())
            };

            if (!System.Environment.UserInteractive && SvcController.IsServiceInstalled("mydlpengine"))
            {
                if (SvcController.IsServiceRunning("mydlpengine"))
                {
                    SvcController.StopService("mydlpengine", 5000);
                }

                ProcessControl.ExecuteCommandSync(new ExecuteParameters("sc delete mydlpengine", "SC", erlEnv));
            }

            try
            {
                using (RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Ericsson\\Erlang", true))
                {
                    key.DeleteSubKeyTree("ErlSrv");
                }
            }
            catch
            {
                //Logger.GetInstance().Info("Unable to delete uneccessary keys or keys do not exists");
            }

            Logger.GetInstance().Info("Starting Java Backend");

            ProcessControl.ExecuteCommandAsync(javaStartCmd, "JAVA:", javaEnv);

            Configuration.SetErlConf();

            Logger.GetInstance().Info("Starting Erlang Backend");
            if (System.Environment.UserInteractive)
            {
                ProcessControl.ExecuteCommandAsync(erlStartInteractiveCmd, "WERL", erlEnv);
            }
            else
            {
                ProcessControl.ExecuteCommandAsync(erlStartCmd, "ERL", erlEnv);
            }
        }