Console-less OpenSim

From OpenSimulator

Revision as of 07:08, 29 April 2008 by DrScofield (Talk | contribs)

Jump to: navigation, search

normally opensim will only run in console mode: whenever you start OpenSim you will end up at a prompt inside OpenSim's very own console — which is very convenient if you want to manage it that way. it is rather inconvenient if you want to start OpenSim as a daemon in the background (e.g., from /etc/init.d/opensim) and control it via the RemoteAdminPlugin, for example.

as of OpenSim's subversion release r4400 the basic support for running OpenSim without such a console is in the code base and all you need to do is invoke OpenSim with the -background True commandline parameter:

   % mono --debug OpenSim.exe -background True

note: that is just a single dash for the -background option!

to shutdown a console-less OpenSim instance, use the following shutdown.py script (also located in share/python/console):

#!/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

you can either pass in the server URI and password to use via commandline parameters, or you can create .opensim-console.rc in your home directory and set default values:

[opensim]
server = http://127.0.0.1:9000/
password = secret

then all you need to do to shutdown your OpenSim server is invoke shutdown.py

the goal is to extend shutdown.py into a remote console of sorts.

(adapted from xyzzy xyzzy)'

Personal tools
General
About This Wiki