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 re, sys, exceptions
18 import fileinput
19 from path import path
20
21 DIR = path(".")
22 ETC = DIR / "etc"
23 GRID = ETC / "grid"
24
26 m = re.match("^.*?\D%s\D.*?$" % port, line)
27 if not m:
28 m = re.match("^.*?\D%s$" % port, line)
29 return m
30
31 -def change_ports(glacier2, glacier2insecure, registry, revert = False):
32 """
33 Parses the etc configuration files to change
34 the current port values. If the files have
35 been noticeably changed, this method may fail.
36
37 Example::
38
39 ./grid/default.xml: <variable name="ROUTERPORT" value="4064"/>
40 ./grid/windefault.xml: <variable name="ROUTERPORT" value="4064"/>
41 ./internal.cfg:Ice.Default.Locator=IceGrid/Locator:tcp -h 127.0.0.1 -p 4061
42 ./master.cfg:IceGrid.Registry.Client.Endpoints=tcp -h 127.0.0.1 -p 4061
43
44 """
45
46 if revert:
47 f_glacier2 = str(int(glacier2))
48 f_glacier2insecure = str(int(glacier2insecure))
49 f_registry = str(int(registry))
50 t_glacier2 = "4064"
51 t_glacier2insecure = "4063"
52 t_registry = "4061"
53 else:
54 t_glacier2 = str(int(glacier2))
55 t_glacier2insecure = str(int(glacier2insecure))
56 t_registry = str(int(registry))
57 f_glacier2 = "4064"
58 f_glacier2insecure = "4063"
59 f_registry = "4061"
60
61 def check_line (l, s, f, t, done):
62 """
63 @param l: the line
64 @param s: the string that denotes this line is supposed to change
65 @param f: from port
66 @param t: to port
67 @return: the line, changed if needed
68 """
69 if l.find(s) >= 0 and line_has_port(l, f):
70 print l.replace(f, t),
71 done.add(fileinput.filename())
72 return True
73 return False
74
75 cfgs = [ str(x) for x in ETC.files("*.cfg") ]
76 found_reg = set()
77 for line in fileinput.input(cfgs, inplace=1):
78 if check_line(line, "Ice.Default.Locator", f_registry, t_registry, found_reg):
79 continue
80 elif check_line(line, "IceGrid.Registry.Client.Endpoints", f_registry, t_registry, found_reg):
81 continue
82 print line,
83 fileinput.close()
84
85 xmls = [ str(x) for x in GRID.files("*.xml") ]
86
87 found_ssl = set()
88 found_tcp = set()
89 for line in fileinput.input(xmls, inplace=1):
90 if check_line(line, "ROUTERPORT", f_glacier2, t_glacier2, found_ssl):
91 continue
92 elif check_line(line, "ROUTER", f_glacier2insecure, t_glacier2insecure, found_tcp):
93 continue
94 print line,
95 fileinput.close()
96
97 for x in ((found_reg, f_registry, t_registry), (found_tcp, f_glacier2insecure, t_glacier2insecure), (found_ssl, f_glacier2, t_glacier2)):
98 if x[0]:
99 print "Converted: %s=>%s in %s" % (x[1], x[2], ", ".join(x[0]))
100 else:
101 print "No values found for %s" % x[1]
102
103 if __name__ == "__main__":
104 try:
105 if len(sys.argv) < 3 or len(sys.argv) > 5:
106 print """ %s [--revert] <glacier2 port> <icegrid registry port> [<glacier2 insecure port>]
107
108 Changes all 4064 ports to the given glacier2 port
109 and all 4061 ports to the given registry port. You will
110 need to give your clients the new glacier2 port.""" % sys.argv[0]
111 sys.exit(2)
112 else:
113 args = sys.argv[1:]
114 try:
115 idx = args.index("--revert")
116 args.pop(idx)
117 revert = True
118 except ValueError:
119 revert = False
120 glacier2 = int(args[0])
121 registry = int(args[1])
122 glacier2insecure = len(args) > 2 and int(args[2]) or 4063
123 change_ports(glacier2, glacier2insecure, registry, revert)
124 sys.exit(0)
125 except exceptions.Exception, e:
126 print "Failed to set ports: ", e
127 sys.exit(1)
128