@@ -43,31 +43,50 @@ def start_local_master_node():
43
43
44
44
def start_instance (local_ip_address ,instance ,directories ):
45
45
'''
46
- Starts a mongodb instance and its matchbox instance
46
+ Starts a matchbox instance
47
47
'''
48
- print 'working on:' , directories ['prefix' ],directories
48
+ print ( 'working on: %s, %s' % ( directories ['prefix' ],directories ))
49
49
err = None
50
50
os .chdir (directories ['matchbox_dir' ])
51
51
if not os .path .exists ('matchbox' ):
52
52
p = subprocess .Popen (['git' ,'clone' ,'-b' ,'dev' ,'https://github.com/macarthur-lab/matchbox' ],stdout = subprocess .PIPE )
53
53
(output , err ) = p .communicate ()
54
54
else :
55
- print '----WARNING:' , ' that repo already exists, not cloning a new copy:' , directories ['matchbox_dir' ]
55
+ print ( '----WARNING: that repo already exists, not cloning a new copy: %s' % directories ['matchbox_dir' ])
56
56
if err is None :
57
- mongo_port = start_dockerized_mongodb (instance ,directories )
58
- start_dockerized_matchbox (local_ip_address ,mongo_port ,instance ,directories )
57
+ start_dockerized_matchbox (local_ip_address ,instance ,directories )
59
58
return
60
59
61
60
62
- def start_dockerized_matchbox (local_ip_address ,mongo_port , instance ,directories ):
61
+ def start_dockerized_matchbox (local_ip_address ,instance ,directories ):
63
62
'''
64
63
Starts a single HTTPS matchbox instance
65
64
Args:
66
- mongo_port: the port of the MongoDB instance slated for this matchbox instance
67
65
instance: int representing this instance
68
- dictories : information on path and prefixes for this instance
66
+ directories : information on path and prefixes for this instance
69
67
'''
68
+ mongo_port = 27017
70
69
instance_port = 8443 + instance
70
+
71
+ #----------------update entrypoint file
72
+ existing_entrypointfile = 'matchbox/deploy/docker/with_data_in_container/entrypoint.sh'
73
+ updated_entrypointfile = 'matchbox/deploy/docker/with_data_in_container/entrypoint_updated.sh'
74
+ with open (existing_entrypointfile ,'r' ) as ei :
75
+ entrypointfile_lines = ei .readlines ()
76
+ ei .close ()
77
+ with open (updated_entrypointfile ,'w' ) as eo :
78
+ l = 0
79
+ while l < len (entrypointfile_lines ):
80
+ line = entrypointfile_lines [l ]
81
+ if l == 2 :
82
+ eo .write ('mongod --dbpath=. --fork --logpath mongo_log.txt' )
83
+ eo .write ('\n ' )
84
+ eo .write (line )
85
+ l += 1
86
+ eo .close ()
87
+ os .chmod (updated_entrypointfile , 777 )
88
+
89
+ #----------------update Docker file
71
90
existing_dockerfile = 'matchbox/deploy/docker/with_data_in_container/Dockerfile'
72
91
updated_dockerfile = 'matchbox/deploy/docker/with_data_in_container/Dockerfile.net'
73
92
with open (existing_dockerfile ,'r' ) as di :
@@ -78,11 +97,11 @@ def start_dockerized_matchbox(local_ip_address,mongo_port,instance,directories):
78
97
while l < len (dockerfile_lines ):
79
98
line = dockerfile_lines [l ]
80
99
if "env MONGODB_HOSTNAME" in line :
81
- do .write (line .strip ()+ local_ip_address )
100
+ do .write (line .strip ()+ 'localhost' )
82
101
elif "MONGODB_DATABASE" in line :
83
102
do .write (line .strip ()+ "mme_primary" )
84
103
elif "env MONGODB_PORT" in line :
85
- do .write (line .strip ().split ("=" )[0 ]+ '=' + mongo_port )
104
+ do .write (line .strip ().split ("=" )[0 ]+ '=' + str ( mongo_port ) )
86
105
elif "env USE_HTTPS" in line :
87
106
do .write (line .strip ().split ("=" )[0 ]+ '=' + 'true\n ' )
88
107
l += 1
@@ -93,6 +112,10 @@ def start_dockerized_matchbox(local_ip_address,mongo_port,instance,directories):
93
112
do .write (dockerfile_lines [l ].replace ("#" ,"" ))
94
113
l += 1
95
114
do .write (dockerfile_lines [l ].replace ("#" ,"" ))
115
+ elif "entrypoint.sh" in line :
116
+ do .write ('RUN apt-get -y install mongodb' )
117
+ do .write ('\n ' )
118
+ do .write (line .replace ("entrypoint.sh" , "entrypoint_updated.sh" ))
96
119
else :
97
120
do .write (line .strip ())
98
121
do .write ('\n ' )
@@ -101,41 +124,20 @@ def start_dockerized_matchbox(local_ip_address,mongo_port,instance,directories):
101
124
image_name = directories ['prefix' ] + '_img'
102
125
os .chdir ('matchbox/deploy/docker/with_data_in_container/' )
103
126
p = subprocess .Popen (['docker' ,'build' ,'-t' ,image_name ,'-f' ,updated_dockerfile .split ('/' )[- 1 ],'.' ],stdout = subprocess .PIPE )
104
- (output , err ) = p .communicate ()
105
- print output ,err
127
+ (output , build_err ) = p .communicate ()
128
+ print ("build output: %s, build error(if any):%s " % (output ,build_err ))
129
+ if not build_err :
130
+ print (' ' .join (['docker' ,'run' ,'-dti' ,'-p' , str (instance_port )+ ":" + str (instance_port ),image_name ]))
131
+ p = subprocess .Popen (['docker' ,'run' ,'-dti' ,'-p' , str (instance_port )+ ":" + str (instance_port ),image_name ],stdout = subprocess .PIPE )
132
+ (output , run_err ) = p .communicate ()
133
+ print ("image run output: %s, run error(if any): %s " % (output ,run_err ))
106
134
return
107
135
108
136
109
137
110
138
111
139
112
140
113
-
114
- def start_dockerized_mongodb (instance ,directories ):
115
- '''
116
- Starts a mongodb instance
117
- Args:
118
- instance: an int representing the instance number
119
- directories: a dictionary of various related dirs to this instance
120
- Returns:
121
- The mongo port this instance runs on
122
- '''
123
- if instance > 9 :
124
- print "----WARNING:" ,"skipping instance (too high!):" ,instance
125
- return
126
- mongo_port = '2701' + str (instance )
127
- mongo_prefix = directories ['prefix' ]+ '_mongo'
128
- cmd = ['docker' ,'run' ,'--name' ,mongo_prefix ,'-d' ,'-p' ,mongo_port + ':27017' , '-v' ,directories ['mongo_data_dir' ].split ('/' )[- 1 ]+ ':/data/db' ,'mongo' ]
129
- p = subprocess .Popen (cmd ,stdout = subprocess .PIPE , stderr = subprocess .PIPE )
130
- (output , err ) = p .communicate ()
131
- if not err :
132
- return mongo_port
133
- if "Conflict" in err and mongo_prefix in err :
134
- print "----WARNING:" ,"skipping creating new mongo container, looks like one is still up:" ,mongo_prefix
135
- return mongo_port
136
- return None
137
-
138
-
139
141
def buid_dir_struct (root_path ,timestamp ,num_instances ):
140
142
'''
141
143
Build a directory structure for network
@@ -146,16 +148,11 @@ def buid_dir_struct(root_path,timestamp,num_instances):
146
148
for i in xrange (0 ,num_instances ):
147
149
prefix = 'matchbox_' + str (i )
148
150
matchbox_dir = timestamp + '/' + prefix
149
- mongo_data_dir = matchbox_dir + '/mongo_data_dir_' + prefix
150
- directories [i ]= {'matchbox_dir' :matchbox_dir , 'mongo_data_dir' :mongo_data_dir ,"prefix" :prefix ,"root_path" :root_path }
151
+ directories [i ]= {'matchbox_dir' :matchbox_dir ,"prefix" :prefix ,"root_path" :root_path }
151
152
if not os .path .exists (matchbox_dir ):
152
153
os .makedirs (matchbox_dir )
153
154
else :
154
- print "----WARNING:" ,matchbox_dir ,"exists, skipping directory creation"
155
- if not os .path .exists (mongo_data_dir ):
156
- os .makedirs (mongo_data_dir )
157
- else :
158
- print "----WARNING:" ,mongo_data_dir ,"exists, skipping directory creation"
155
+ print ("----WARNING: %s exists, skipping directory creation" % matchbox_dir )
159
156
return directories
160
157
161
158
0 commit comments