|
3 | 3 | abort,
|
4 | 4 | )
|
5 | 5 | import os
|
| 6 | +import json |
| 7 | +from functools import wraps |
| 8 | +import subprocess |
| 9 | +import time |
6 | 10 |
|
7 | 11 |
|
8 | 12 | # Flask app
|
9 |
| -app = Flask(__name__, |
10 |
| - static_folder='static', static_url_path='', |
11 |
| - instance_relative_config=True) |
| 13 | +app = Flask( |
| 14 | + __name__, |
| 15 | + static_folder='static', static_url_path='', |
| 16 | + instance_relative_config=True |
| 17 | +) |
12 | 18 | CONFIG = os.environ.get('CONFIG') or 'config.Development'
|
13 | 19 | app.config.from_object('config.Default')
|
14 | 20 | app.config.from_object(CONFIG)
|
|
18 | 24 | from log.config import LoggingConfiguration
|
19 | 25 | LoggingConfiguration.set(
|
20 | 26 | logging.DEBUG if os.getenv('DEBUG') else logging.INFO,
|
21 |
| - 'lightop.log', name='Web') |
22 |
| - |
23 |
| - |
24 |
| -import json |
25 |
| -from functools import wraps |
26 |
| -import subprocess |
27 |
| -import time |
28 |
| - |
29 |
| - |
30 |
| -FIRST = True |
| 27 | + '/var/log/web.log' |
| 28 | +) |
31 | 29 |
|
32 | 30 |
|
33 | 31 | def exception_to_json(func):
|
@@ -68,7 +66,8 @@ class BadRequest(Exception):
|
68 | 66 | g = d.getElementsByTagName('body')[0],
|
69 | 67 | x = w.innerWidth || e.clientWidth || g.clientWidth,
|
70 | 68 | y = w.innerHeight|| e.clientHeight|| g.clientHeight;
|
71 |
| - window.location.href = "redirect.html?width=" + x + "&height=" + (parseInt(y)); |
| 69 | + var url = "redirect.html?width=" + x + "&height=" + (parseInt(y)); |
| 70 | + window.location.href = url; |
72 | 71 | </script>
|
73 | 72 | <title>Page Redirection</title>
|
74 | 73 | </head><body></body></html>'''
|
@@ -104,18 +103,28 @@ def redirectme():
|
104 | 103 | env['height'] = request.args['height']
|
105 | 104 |
|
106 | 105 | # sed
|
107 |
| - subprocess.check_call(r"sed -i 's#^command=/usr/bin/Xvfb.*$#command=/usr/bin/Xvfb :1 -screen 0 {width}x{height}x16#' /etc/supervisor/conf.d/supervisord.conf".format(**env), |
108 |
| - shell=True) |
| 106 | + cmd = ( |
| 107 | + 'sed -i \'s#' |
| 108 | + '^command=/usr/bin/Xvfb.*$' |
| 109 | + '#' |
| 110 | + 'command=/usr/bin/Xvfb :1 -screen 0 {width}x{height}x16' |
| 111 | + '#\' /etc/supervisor/conf.d/supervisord.conf' |
| 112 | + ).format(**env), |
| 113 | + subprocess.check_call(cmd, shell=True) |
109 | 114 | # supervisorctrl reload
|
110 |
| - subprocess.check_call(r"supervisorctl reload", shell=True) |
| 115 | + subprocess.check_call(['supervisorctl', 'reload']) |
111 | 116 |
|
112 | 117 | # check all running
|
113 |
| - for i in xrange(20): |
114 |
| - output = subprocess.check_output(r"supervisorctl status | grep RUNNING | wc -l", shell=True) |
115 |
| - if output.strip() == "6": |
| 118 | + for i in range(40): |
| 119 | + output = subprocess.check_output(['supervisorctl', 'status']) |
| 120 | + for line in output.strip().split('\n'): |
| 121 | + if line.find('RUNNING') < 0: |
| 122 | + break |
| 123 | + else: |
116 | 124 | FIRST = False
|
117 | 125 | return HTML_REDIRECT
|
118 |
| - time.sleep(2) |
| 126 | + time.sleep(1) |
| 127 | + logging.info('wait services is ready...') |
119 | 128 | abort(500, 'service is not ready, please restart container')
|
120 | 129 |
|
121 | 130 |
|
|
0 commit comments