Enable mumo to retrieve slice file from server on startup and make that the default behavior
This commit is contained in:
6
mumo.ini
6
mumo.ini
@@ -10,9 +10,11 @@
|
|||||||
host = 127.0.0.1
|
host = 127.0.0.1
|
||||||
port = 6502
|
port = 6502
|
||||||
|
|
||||||
; Slicefile to use
|
; Slicefile to use (e.g. /etc/slice/Murmur.ice),
|
||||||
|
; if empty MuMo will load the slice file from the
|
||||||
|
; target server at startup.
|
||||||
|
|
||||||
slice = Murmur.ice
|
slice =
|
||||||
|
|
||||||
; Shared secret between the MuMo and the Murmur
|
; Shared secret between the MuMo and the Murmur
|
||||||
; server. For security reason you should always
|
; server. For security reason you should always
|
||||||
|
|||||||
68
mumo.py
68
mumo.py
@@ -29,9 +29,12 @@
|
|||||||
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import Ice
|
import Ice
|
||||||
|
import IcePy
|
||||||
import logging
|
import logging
|
||||||
|
import tempfile
|
||||||
from config import (Config,
|
from config import (Config,
|
||||||
x2bool,
|
x2bool,
|
||||||
commaSeperatedIntegers)
|
commaSeperatedIntegers)
|
||||||
@@ -54,7 +57,7 @@ cfgfile = 'mumo.ini'
|
|||||||
default = MumoManager.cfg_default.copy()
|
default = MumoManager.cfg_default.copy()
|
||||||
default.update({'ice':(('host', str, '127.0.0.1'),
|
default.update({'ice':(('host', str, '127.0.0.1'),
|
||||||
('port', int, 6502),
|
('port', int, 6502),
|
||||||
('slice', str, 'Murmur.ice'),
|
('slice', str, ''),
|
||||||
('secret', str, ''),
|
('secret', str, ''),
|
||||||
('slicedir', str, '/usr/share/slice'),
|
('slicedir', str, '/usr/share/slice'),
|
||||||
('watchdog', int, 30),
|
('watchdog', int, 30),
|
||||||
@@ -67,15 +70,60 @@ default.update({'ice':(('host', str, '127.0.0.1'),
|
|||||||
'log':(('level', int, logging.DEBUG),
|
'log':(('level', int, logging.DEBUG),
|
||||||
('file', str, 'mumo.log'))})
|
('file', str, 'mumo.log'))})
|
||||||
|
|
||||||
|
def dynload_slice(prx):
|
||||||
|
#
|
||||||
|
#--- Dynamically retrieves the slice file from the target server
|
||||||
|
#
|
||||||
|
info("Loading slice from server")
|
||||||
|
try:
|
||||||
|
slice = IcePy.Operation('getSlice', Ice.OperationMode.Idempotent, Ice.OperationMode.Idempotent, True, (), (), (), IcePy._t_string, ()).invoke(prx, ((), None))
|
||||||
|
|
||||||
|
(dynslicefiledesc, dynslicefilepath) = tempfile.mkstemp(suffix = '.ice')
|
||||||
|
dynslicefile = os.fdopen(dynslicefiledesc, 'w')
|
||||||
|
dynslicefile.write(slice)
|
||||||
|
dynslicefile.flush()
|
||||||
|
Ice.loadSlice('', ['-I' + Ice.getSliceDir(), dynslicefilepath])
|
||||||
|
dynslicefile.close()
|
||||||
|
os.remove(dynslicefilepath)
|
||||||
|
except Exception, e:
|
||||||
|
error("Retrieving slice from server failed")
|
||||||
|
exception(e)
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def fsload_slice(slice):
|
||||||
|
#
|
||||||
|
#--- Load slice from file system
|
||||||
|
#
|
||||||
|
debug("Loading slice from filesystem: %s" % slice)
|
||||||
|
if not hasattr(Ice, "getSliceDir"):
|
||||||
|
Ice.loadSlice('-I%s %s' % (cfg.ice.slicedir, slice))
|
||||||
|
else:
|
||||||
|
Ice.loadSlice('', ['-I' + Ice.getSliceDir(), slice])
|
||||||
|
|
||||||
def do_main_program():
|
def do_main_program():
|
||||||
#
|
#
|
||||||
#--- Moderator implementation
|
#--- Moderator implementation
|
||||||
# All of this has to go in here so we can correctly daemonize the tool
|
# All of this has to go in here so we can correctly daemonize the tool
|
||||||
# without loosing the file descriptors opened by the Ice module
|
# without loosing the file descriptors opened by the Ice module
|
||||||
if not hasattr(Ice, "getSliceDir"):
|
|
||||||
Ice.loadSlice('-I%s %s' % (cfg.ice.slicedir, cfg.ice.slice))
|
debug('Initializing Ice')
|
||||||
|
initdata = Ice.InitializationData()
|
||||||
|
initdata.properties = Ice.createProperties([], initdata.properties)
|
||||||
|
for prop, val in cfg.iceraw:
|
||||||
|
initdata.properties.setProperty(prop, val)
|
||||||
|
|
||||||
|
initdata.properties.setProperty('Ice.ImplicitContext', 'Shared')
|
||||||
|
initdata.logger = CustomLogger()
|
||||||
|
|
||||||
|
ice = Ice.initialize(initdata)
|
||||||
|
prxstr = 'Meta:tcp -h %s -p %d' % (cfg.ice.host, cfg.ice.port)
|
||||||
|
prx = ice.stringToProxy(prxstr)
|
||||||
|
|
||||||
|
if not cfg.ice.slice:
|
||||||
|
dynload_slice(prx)
|
||||||
else:
|
else:
|
||||||
Ice.loadSlice('', ['-I' + Ice.getSliceDir(), cfg.ice.slice])
|
fsload_slice(cfg.ice.slice)
|
||||||
|
|
||||||
import Murmur
|
import Murmur
|
||||||
|
|
||||||
@@ -117,7 +165,7 @@ def do_main_program():
|
|||||||
warning('Consider using an ice secret to improve security')
|
warning('Consider using an ice secret to improve security')
|
||||||
|
|
||||||
info('Connecting to Ice server (%s:%d)', cfg.ice.host, cfg.ice.port)
|
info('Connecting to Ice server (%s:%d)', cfg.ice.host, cfg.ice.port)
|
||||||
base = ice.stringToProxy('Meta:tcp -h %s -p %d' % (cfg.ice.host, cfg.ice.port))
|
base = ice.stringToProxy(prxstr)
|
||||||
self.meta =Murmur.MetaPrx.uncheckedCast(base)
|
self.meta =Murmur.MetaPrx.uncheckedCast(base)
|
||||||
|
|
||||||
if cfg.ice.callback_port > 0:
|
if cfg.ice.callback_port > 0:
|
||||||
@@ -368,15 +416,7 @@ def do_main_program():
|
|||||||
manager.loadModules()
|
manager.loadModules()
|
||||||
manager.startModules()
|
manager.startModules()
|
||||||
|
|
||||||
debug('Initializing Ice')
|
debug("Initializing mumoIceApp")
|
||||||
initdata = Ice.InitializationData()
|
|
||||||
initdata.properties = Ice.createProperties([], initdata.properties)
|
|
||||||
for prop, val in cfg.iceraw:
|
|
||||||
initdata.properties.setProperty(prop, val)
|
|
||||||
|
|
||||||
initdata.properties.setProperty('Ice.ImplicitContext', 'Shared')
|
|
||||||
initdata.logger = CustomLogger()
|
|
||||||
|
|
||||||
app = mumoIceApp(manager)
|
app = mumoIceApp(manager)
|
||||||
state = app.main(sys.argv[:1], initData=initdata)
|
state = app.main(sys.argv[:1], initData=initdata)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user