GridServerManager.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) Contributors, http://www.openmetaverse.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. */
  28. using System;
  29. using System.Collections;
  30. using System.Threading;
  31. using libsecondlife;
  32. using Nwc.XmlRpc;
  33. namespace OpenSim.Framework.Manager {
  34. /// <summary>
  35. /// A remote management system for the grid server
  36. /// </summary>
  37. public class GridServerManager
  38. {
  39. /// <summary>
  40. /// Triggers events from the grid manager
  41. /// </summary>
  42. public static GridManagerCallback thecallback;
  43. /// <summary>
  44. /// Security keys
  45. /// </summary>
  46. public static string sendkey;
  47. public static string recvkey;
  48. /// <summary>
  49. /// Disconnects the grid server and shuts it down
  50. /// </summary>
  51. /// <param name="request">XmlRpc Request</param>
  52. /// <returns>An XmlRpc response containing either a "msg" or an "error"</returns>
  53. public static XmlRpcResponse XmlRpcShutdownMethod(XmlRpcRequest request)
  54. {
  55. XmlRpcResponse response = new XmlRpcResponse();
  56. Hashtable requestData = (Hashtable)request.Params[0];
  57. Hashtable responseData = new Hashtable();
  58. if(requestData.ContainsKey("session_id")) {
  59. if(GridManagementAgent.SessionExists(new LLUUID((string)requestData["session_id"]))) {
  60. responseData["msg"]="Shutdown command accepted";
  61. (new Thread(new ThreadStart(ShutdownServer))).Start();
  62. } else {
  63. response.IsFault=true;
  64. responseData["error"]="bad session ID";
  65. }
  66. } else {
  67. response.IsFault=true;
  68. responseData["error"]="no session ID";
  69. }
  70. response.Value = responseData;
  71. return response;
  72. }
  73. /// <summary>
  74. /// Shuts down the grid server
  75. /// </summary>
  76. public static void ShutdownServer()
  77. {
  78. Console.WriteLine("Shutting down the grid server - recieved a grid manager request");
  79. Console.WriteLine("Terminating in three seconds...");
  80. Thread.Sleep(3000);
  81. thecallback("shutdown");
  82. }
  83. }
  84. }