Package omero :: Package plugins :: Module node
[hide private]
[frames] | no frames]

Source Code for Module omero.plugins.node

  1  #!/usr/bin/env python 
  2  """ 
  3   :author: Josh Moore, josh at glencoesoftware.com 
  4   
  5   OMERO Grid node controller 
  6   
  7   This is a python wrapper around icegridnode. 
  8   
  9   Copyright 2008 Glencoe Software, Inc.  All Rights Reserved. 
 10   Use is subject to license terms supplied in LICENSE.txt 
 11   
 12  """ 
 13   
 14  from omero.cli import BaseControl, CLI, NonZeroReturnCode 
 15  from omero.util import tail_lines 
 16  from omero_ext.strings import shlex 
 17  from omero.plugins.admin import AdminControl 
 18  import re, os, sys, signal 
 19  from exceptions import Exception as Exc 
 20  from path import path 
 21   
 22  HELP = """Control icegridnode. 
 23             start       -- Start the node via icegridnode. With sync doesn't return until reachable. 
 24             stop        -- Stop the node via icegridadmin. With sync doesn't return until stopped. 
 25             status      -- Prints a status message. Return code is non-zero if there is a problem. 
 26             restart     -- Calls "sync start" then "stop" ("sync stop" if sync is specified) 
 27   
 28          node-name cannot be "start", "stop", "restart", "status", or "sync". 
 29  """ 
 30   
31 -class NodeControl(BaseControl):
32
33 - def _configure(self, parser):
34 parser.add_argument("name", nargs="?", help="Optional name of this node.", default=self._node()) 35 parser.add_argument("sync", nargs="?", choices=("sync",), help="Whether or not to call wait on results") 36 parser.add_argument("command", nargs="+", choices=("start","stop","status","restart")) 37 parser.set_defaults(func=self.__call__)
38
39 - def __call__(self, args):
40 self._node(args.name) # Set environment value 41 for act in args.command: 42 c = getattr(self, act) 43 c(args)
44
45 - def _handleNZRC(self, nzrc):
46 """ 47 Set the return value from nzrc on the context, and print 48 out the last two lines of any error messages if present. 49 """ 50 props = self._properties() 51 self.ctx.rv = nzrc.rv 52 myoutput = self.dir / path(props["Ice.StdErr"]) 53 if not myoutput.exists(): 54 pass 55 else: 56 print "from %s:" % str(myoutput) 57 print tail_lines(str(myoutput),2)
58
59 - def start(self, args):
60 61 self._initDir() 62 63 try: 64 command = ["icegridnode", self._icecfg()] 65 if self._isWindows(): 66 command = command + ["--install","OMERO."+args.node] 67 self.ctx.call(command) 68 self.ctx.call(["icegridnode","--start","OMERO."+args.node]) 69 else: 70 command = command + ["--daemon", "--pidfile", str(self._pid()),"--nochdir"] 71 self.ctx.call(command) 72 except OSError, o: 73 msg = """%s\nPossibly an error finding "icegridnode". Try "icegridnode -h" from the command line.""" % o 74 raise Exc(msg) 75 except NonZeroReturnCode, nzrc: 76 self._handleNZRC(nzrc)
77
78 - def status(self, args):
79 self.ctx.invoke(["admin", "status", args.name])
80
81 - def stop(self, args):
82 if self._isWindows(): 83 try: 84 command = ["icegridnode", "--stop", "OMERO."+args.name] 85 self.ctx.call(command) 86 command = ["icegridnode", "--uninstall", "OMERO."+args.name] 87 self.ctx.call(command) 88 except NonZeroReturnCode, nzrc: 89 self._handleNZRC(nzrc) 90 else: 91 pid = open(self._pid(),"r").readline() 92 os.kill(int(pid), signal.SIGTERM)
93 # command = ["icegridadmin"] + [self._intcfg()] + ["-c", "node shutdown %s" % args.name] 94 # self.ctx.call(command) 95
96 - def kill(self, args):
97 pid = open(self._pid(),"r").readline() 98 os.kill(int(pid), signal.SIGKILL)
99 100 try: 101 register("node", NodeControl, HELP) 102 except NameError: 103 if __name__ == "__main__": 104 cli = CLI() 105 cli.loadplugins() 106 cli.invoke(sys.argv[1:]) 107