console-less opensim

until a couple of days ago, opensim would only run in console mode: whenever you started OpenSim you would 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 (and control it via the RemoteAdminPlugin, for example).

as of OpenSim’s subversion release r4390 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’s just a single dash for -background True!

another patch is on its way that not only adds code to properly shutdown OpenSim when the admin_shutdown XmlRpc method is invoked but it also adds the shutdown.py script:1

[python]
#!/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

[/python]

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


  1. to be found in share/python/console/shutdown.py