From cccfd1db3478d20ea63c009b01bdc3479c046cbf Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 26 Nov 2010 03:21:51 +0100 Subject: Add marker files to the restart module so external scripts can be used to kill a process that hasn't restarted properly --- .../CoreModules/World/Region/RestartModule.cs | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/World/Region/RestartModule.cs b/OpenSim/Region/CoreModules/World/Region/RestartModule.cs index c65aa6a..6e1ee10 100644 --- a/OpenSim/Region/CoreModules/World/Region/RestartModule.cs +++ b/OpenSim/Region/CoreModules/World/Region/RestartModule.cs @@ -28,6 +28,8 @@ using System; using System.Reflection; using System.Timers; +using System.IO; +using System.Diagnostics; using System.Threading; using System.Collections.Generic; using log4net; @@ -56,13 +58,23 @@ namespace OpenSim.Region.CoreModules.World.Region protected UUID m_Initiator; protected bool m_Notice = false; protected IDialogModule m_DialogModule = null; + protected string m_MarkerPath; public void Initialise(IConfigSource config) { + IConfig restartConfig = config.Configs["RestartModule"]; + if (restartConfig != null) + { + m_MarkerPath = restartConfig.GetString("MarkerPath", String.Empty); + } } public void AddRegion(Scene scene) { + if (m_MarkerPath != String.Empty) + File.Delete(Path.Combine(m_MarkerPath, + scene.RegionInfo.RegionID.ToString())); + m_Scene = scene; scene.RegisterModuleInterface(this); MainConsole.Instance.Commands.AddCommand("RestartModule", @@ -114,6 +126,7 @@ namespace OpenSim.Region.CoreModules.World.Region if (alerts == null) { + CreateMarkerFile(); m_Scene.RestartNow(); return; } @@ -127,6 +140,7 @@ namespace OpenSim.Region.CoreModules.World.Region if (m_Alerts[0] == 0) { + CreateMarkerFile(); m_Scene.RestartNow(); return; } @@ -140,6 +154,7 @@ namespace OpenSim.Region.CoreModules.World.Region { if (m_Alerts.Count == 0 || m_Alerts[0] == 0) { + CreateMarkerFile(); m_Scene.RestartNow(); return 0; } @@ -259,5 +274,25 @@ namespace OpenSim.Region.CoreModules.World.Region ScheduleRestart(UUID.Zero, args[3], times.ToArray(), notice); } + + protected void CreateMarkerFile() + { + if (m_MarkerPath == String.Empty) + return; + + string path = Path.Combine(m_MarkerPath, m_Scene.RegionInfo.RegionID.ToString()); + try + { + string pidstring = System.Diagnostics.Process.GetCurrentProcess().Id.ToString(); + FileStream fs = File.Create(path); + System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); + Byte[] buf = enc.GetBytes(pidstring); + fs.Write(buf, 0, buf.Length); + fs.Close(); + } + catch (Exception) + { + } + } } } -- cgit v1.1