1
2
3 """
4
5 Function for changing the ports used by Glacier2
6 and the IceGrid registry. To run more than one OMERO
7 instance on a machine, it's necessary to modify these.
8
9 Copyright 2009 Glencoe Software, Inc. All rights reserved.
10 Use is subject to license terms supplied in LICENSE.txt
11
12 :author: Josh Moore <josh@glencoesoftware.com>
13
14 """
15
16
17 import sys, exceptions
18 import fileinput
19 from path import path
20
21 dir = path(".")
22 etc = dir / "etc"
23 grid = etc / "grid"
24
26 """
27 Parses the etc configuration files to change
28 the current port values. If the files have
29 been noticeably changed, this method may fail.
30
31 Example::
32
33 ./grid/default.xml: <variable name="ROUTERPORT" value="4063"/>
34 ./grid/windefault.xml: <variable name="ROUTERPORT" value="4063"/>
35 ./internal.cfg:Ice.Default.Locator=IceGrid/Locator:tcp -h 127.0.0.1 -p 4061
36 ./master.cfg:IceGrid.Registry.Client.Endpoints=tcp -h 127.0.0.1 -p 4061
37
38 """
39
40 if revert:
41 f_glacier2 = str(int(glacier2))
42 f_registry = str(int(registry))
43 t_glacier2 = "4063"
44 t_registry = "4061"
45 else:
46 t_glacier2 = str(int(glacier2))
47 t_registry = str(int(registry))
48 f_glacier2 = "4063"
49 f_registry = "4061"
50
51 cfgs = [ str(x) for x in etc.files("*.cfg") ]
52 done = set()
53 for line in fileinput.input(cfgs, inplace=1):
54 if line.find("Ice.Default.Locator") >= 0:
55 if line.find(f_registry) >= 0:
56 print line.replace(f_registry, t_registry),
57 done.add(fileinput.filename())
58 continue
59 elif line.find("IceGrid.Registry.Client.Endpoints") >= 0:
60 if line.find(f_registry) >= 0:
61 print line.replace(f_registry, t_registry),
62 done.add(fileinput.filename())
63 continue
64 print line,
65 fileinput.close()
66 if done:
67 print "Converted: %s=>%s in %s" % (f_registry, t_registry, ", ".join(done))
68 else:
69 print "No values found for %s" % f_registry
70
71 xmls = [ str(x) for x in grid.files("*.xml") ]
72 done = set()
73 for line in fileinput.input(xmls, inplace=1):
74 if line.find("ROUTERPORT") >= 0:
75 if line.find(f_glacier2) >= 0:
76 print line.replace(f_glacier2, t_glacier2),
77 done.add(fileinput.filename())
78 continue
79 print line,
80 fileinput.close()
81 if done:
82 print "Converted: %s=>%s in %s" % (f_glacier2, t_glacier2, ", ".join(done))
83 else:
84 print "No values found for %s" % f_glacier2
85
86 if __name__ == "__main__":
87 try:
88 if len(sys.argv) < 3 or len(sys.argv) > 4:
89 print """ %s [--revert] <glacier2 port> <icegrid registry port>
90
91 Changes all 4063 ports to the given glacier2 port
92 and all 4061 ports to the given registry port. You will
93 need to give your clients the new glacier2 port.""" % sys.argv[0]
94 sys.exit(2)
95 else:
96 args = sys.argv[1:]
97 try:
98 idx = args.index("--revert")
99 args.pop(idx)
100 revert = True
101 except ValueError:
102 revert = False
103 glacier2 = int(args[0])
104 registry = int(args[1])
105 change_ports(glacier2, registry, revert)
106 sys.exit(0)
107 except exceptions.Exception, e:
108 print "Failed to set ports: ", e
109 sys.exit(1)
110