From 763ae779ffb43ea9d33a9bf2a1c6c4ca78ef243d Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Tue, 29 Apr 2008 14:50:27 +0000 Subject: From: Dr Scofield * Fixes the admin_shutdown xmlrpc method * Adds a share/python/console/shutdown.py script for shutting down a background OpenSim * For more details see http://xyzzyxyzzy.net/2008/04/29/console-less-opensim/ * There should also be instructions in the opensimulator wiki soon as well --- .../RemoteController/RemoteAdminPlugin.cs | 31 ++++++++--------- OpenSim/Region/Application/Application.cs | 1 - OpenSim/Region/Application/OpenSimMain.cs | 14 +++++--- share/python/console/shutdown.py | 39 ++++++++++++++++++++++ 4 files changed, 62 insertions(+), 23 deletions(-) create mode 100644 share/python/console/shutdown.py diff --git a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs index 2cb5375..fed7d9b 100644 --- a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs +++ b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs @@ -218,9 +218,6 @@ namespace OpenSim.ApplicationPlugins.LoadRegions Hashtable responseData = new Hashtable(); try { - checkStringParameters(request, new string[] { "password", "shutdown" }); - checkIntegerParams(request, new string[] { "milliseconds"}); - if (requiredPassword != String.Empty && (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword)) throw new Exception("wrong password"); @@ -228,28 +225,28 @@ namespace OpenSim.ApplicationPlugins.LoadRegions responseData["accepted"] = "true"; response.Value = responseData; - if ((string) requestData["shutdown"] == "delayed") + int timeout = 2000; + + if (requestData.ContainsKey("shutdown") && + ((string) requestData["shutdown"] == "delayed") && + requestData.ContainsKey("milliseconds")) { - int timeout = (Int32) requestData["milliseconds"]; + timeout = (Int32) requestData["milliseconds"]; m_app.SceneManager.SendGeneralMessage("Region is going down in " + ((int) (timeout/1000)).ToString() + " second(s). Please save what you are doing and log out."); - - // Perform shutdown - Timer shutdownTimer = new Timer(timeout); // Wait before firing - shutdownTimer.AutoReset = false; - shutdownTimer.Elapsed += new ElapsedEventHandler(shutdownTimer_Elapsed); - shutdownTimer.Start(); } else { m_app.SceneManager.SendGeneralMessage("Region is going down now."); - - // Perform shutdown - Timer shutdownTimer = new Timer(2000); // Wait 2 seconds before firing - shutdownTimer.AutoReset = false; - shutdownTimer.Elapsed += new ElapsedEventHandler(shutdownTimer_Elapsed); - shutdownTimer.Start(); } + + // Perform shutdown + Timer shutdownTimer = new Timer(timeout); // Wait before firing + shutdownTimer.AutoReset = false; + shutdownTimer.Elapsed += new ElapsedEventHandler(shutdownTimer_Elapsed); + shutdownTimer.Start(); + + responseData["success"] = "true"; } catch (Exception e) { diff --git a/OpenSim/Region/Application/Application.cs b/OpenSim/Region/Application/Application.cs index 828490a..bdce0f0 100644 --- a/OpenSim/Region/Application/Application.cs +++ b/OpenSim/Region/Application/Application.cs @@ -83,7 +83,6 @@ namespace OpenSim if (background) { - Console.WriteLine("background mode"); OpenSimMain sim = new OpenSimMain(configSource); sim.StartUp(); } diff --git a/OpenSim/Region/Application/OpenSimMain.cs b/OpenSim/Region/Application/OpenSimMain.cs index 3bee7f3..d05a632 100644 --- a/OpenSim/Region/Application/OpenSimMain.cs +++ b/OpenSim/Region/Application/OpenSimMain.cs @@ -323,15 +323,19 @@ namespace OpenSim // // Called from app startup (OpenSim.Application) // - - m_log.Info("[OPENSIM]: Starting Opensim"); - m_log.InfoFormat("[OPENSIM MAIN]: Running in {0} mode", (m_sandbox ? "sandbox" : "grid")); + m_log.Info("===================================================================="); + m_log.Info("========================= STARTING OPENSIM ========================="); + m_log.Info("===================================================================="); + m_log.InfoFormat("[OPENSIM MAIN]: Running in background {0} mode", m_sandbox ? "sandbox" : "grid"); InternalStartUp(); // We are done with startup - m_log.Info("[OPENSIM MAIN]: Startup complete, serving " + m_udpServers.Count.ToString() + " region(s)"); + m_log.InfoFormat("[OPENSIM MAIN]: Startup complete, serving {0} region{1}", + m_udpServers.Count.ToString(), m_udpServers.Count > 1 ? "s" : ""); WorldHasComeToAnEnd.WaitOne(); + m_log.Info("[OPENSIM MAIN]: Shutdown complete, goodbye."); + Environment.Exit(0); } @@ -684,7 +688,7 @@ namespace OpenSim public virtual void Shutdown() { InternalShutdown(); - Environment.Exit(0); + ApocalypseNow(); } /// diff --git a/share/python/console/shutdown.py b/share/python/console/shutdown.py new file mode 100644 index 0000000..65f8255 --- /dev/null +++ b/share/python/console/shutdown.py @@ -0,0 +1,39 @@ +#!/usr/bin/python +# -*- encoding: utf-8 -*- + +import ConfigParser +import xmlrpclib +import optparse +import os.path + +if __name__ == '__main__': + parser = optparse.OptionParser() + parser.add_option('-c', '--config', dest = 'config', help = 'config file', metavar = 'CONFIG') + parser.add_option('-s', '--server', dest = 'server', help = 'URI for the grid server', metavar = 'SERVER') + parser.add_option('-p', '--password', dest = 'password', help = 'password for the grid server', metavar = 'PASSWD') + (options, args) = parser.parse_args() + + configFile = options.config + if not configFile: + if os.path.isfile(os.path.expanduser('~/.opensim-console.rc')): + configFile = os.path.expanduser('~/.opensim-console.rc') + if not configFile: + parser.error('missing option config') + sys.exit(1) + + config = ConfigParser.ConfigParser() + config.readfp(open(configFile)) + + server = config.get('opensim', 'server') + password = config.get('opensim', 'password') + + if options.server: server = options.server + if options.password: password = options.password + + gridServer = xmlrpclib.Server(server) + res = gridServer.admin_shutdown({'password': password}) + + if res['success'] == 'true': + print 'shutdown of %s initiated' % server + else: + print 'shutdown of %s failed' % server -- cgit v1.1