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