/
cluster_run
executable file
·84 lines (67 loc) · 2.21 KB
/
cluster_run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python
import os, subprocess, sys, signal, termios, atexit
def testament_child_death():
rv = os.fork()
if rv == 0:
os.kill(os.getpid(), signal.SIGSTOP)
os._exit(0)
os.waitpid(rv, os.WUNTRACED)
def start_cluster(num_nodes, extra_args):
path_str = subprocess.Popen(["find", ".", "-name", "ebin", "-type", "d"],
stdout=subprocess.PIPE).communicate()[0]
path = path_str.split()
base_direct_port = 12000
base_api_port = 9000
def start_node(i):
logdir = "logs/n_{0}".format(i)
try:
os.makedirs(logdir)
except:
pass
args = ["erl", "+A", "16", "-pa"] + path + [
"-setcookie", "nocookie",
"-run", "ns_bootstrap",
"-kernel", "inet_dist_listen_min", "21100",
"inet_dist_listen_max", "21199",
"-ns_server", "error_logger_mf_dir", '"{0}"'.format(logdir),
"error_logger_mf_maxbytes", "10485760",
"error_logger_mf_maxfiles", "10",
"path_prefix", '"n_{0}"'.format(i),
"rest_port", str(base_api_port + i),
"memcached_port", str(base_direct_port + i * 2),
"moxi_port", str(base_direct_port + i * 2 + 1),
"short_name", '"n_{0}"'.format(i)
] + extra_args
if i == 0:
return subprocess.Popen(args)
else:
return subprocess.Popen(args + ["-noshell"], stdin=subprocess.PIPE)
return [start_node(i) for i in xrange(num_nodes)]
def usage():
sys.exit("Usage: {0} num_nodes")
def main():
try:
num_nodes = int(sys.argv[1])
except:
usage()
nodes = []
def kill_nodes(*args):
for n in nodes:
try:
n.kill()
except OSError:
pass
atexit.register(kill_nodes)
testament_child_death()
terminal_attrs = None
try:
terminal_attrs = termios.tcgetattr(sys.stdin)
except:
pass
nodes = start_cluster(num_nodes, sys.argv[1:])
for node in nodes:
node.wait()
if terminal_attrs != None:
termios.tcsetattr(sys.stdin, termios.TCSANOW, terminal_attrs)
if __name__ == '__main__':
main()