52
52
}
53
53
}
54
54
55
+
55
56
def get_dist ():
56
57
return platform .linux_distribution ()[0 ]
57
58
@@ -111,10 +112,11 @@ def set_docker_config(mirror):
111
112
f .write (new_line )
112
113
f .writelines (options )
113
114
115
+
114
116
def set_docker_config_ce (mirror ):
115
117
dist = get_dist ()
116
118
docker_config = get_config_ce (dist )
117
- config_dict = {}
119
+ config_dict = {}
118
120
if os .path .exists (docker_config ) != True :
119
121
# if file not exist, create it first.
120
122
os .mknod (docker_config , 0o644 )
@@ -127,6 +129,7 @@ def set_docker_config_ce(mirror):
127
129
with open (docker_config , "w" ) as f :
128
130
json .dump (config_dict , f )
129
131
132
+
130
133
def restart_docker_daemon ():
131
134
execute_sys_cmd ("systemctl restart docker" )
132
135
@@ -136,7 +139,7 @@ def get_speed(mirror, mirror_url):
136
139
set_docker_config_ce (mirror_url )
137
140
else :
138
141
set_docker_config (mirror_url )
139
-
142
+
140
143
restart_docker_daemon ()
141
144
142
145
# try to delete busybox image in case.
@@ -155,7 +158,7 @@ def get_speed(mirror, mirror_url):
155
158
execute_sys_cmd ("docker rmi registry:2 -f 1> /dev/null 2>&1" )
156
159
157
160
return cost_time
158
- #return 204800 / cost_time
161
+
159
162
160
163
if __name__ == "__main__" :
161
164
print ("restart docker daemon" )
@@ -179,11 +182,11 @@ def get_speed(mirror, mirror_url):
179
182
restart_count += 1
180
183
total_time += cost_time
181
184
if restart_count >= 2 and total_time < 60 :
182
- # to avoid the error of docker daeom: Start request repeated too quickly
183
- print ("oh.. docker daemon restart too quickly, have a rest" )
184
- restart_count = 0
185
- total_time = 0
186
- time .sleep (60 - total_time )
185
+ # to avoid the error of docker daeom: Start request repeated too quickly
186
+ print ("oh.. docker daemon restart too quickly, have a rest" )
187
+ restart_count = 0
188
+ total_time = 0
189
+ time .sleep (60 - total_time )
187
190
188
191
print ("best mirror is: {mirror}, set docker config and restart docker daemon now." .format (mirror = best_mirror ))
189
192
if "ce" in version :
0 commit comments