我在AWS上有一个现有的Elastic Beanstalk flask应用程序,该应用程序有时不会初始化并给出以下错误:
[Mon Jan 23 10:06:51.550205 2017] [core:error] [pid 7331] [client 127.0.0.1:43790] script timed out before returning headers: application.py
[Mon Jan 23 10:10:43.910014 2017] [core:error] [pid 7329] [client 127.0.0.1:43782] End of script output before headers: application.py
任何想法为什么会这样?最近,我改变了项目的requirements.txt
包括pandas==0.19.2
。在进行此更改之前,该程序将运行几天,然后返回相同的错误。更多日志/程序详细信息:
[Mon Jan 23 10:05:36.877664 2017] [suexec:notice] [pid 7323] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Mon Jan 23 10:05:36.886151 2017] [so:warn] [pid 7323] AH01574: module wsgi_module is already loaded, skipping
AH00557: httpd: apr_sockaddr_info_get() failed for ip-10-55-254-33
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
[Mon Jan 23 10:05:36.887302 2017] [auth_digest:notice] [pid 7323] AH01757: generating secret for digest authentication ...
[Mon Jan 23 10:05:36.887797 2017] [lbmethod_heartbeat:notice] [pid 7323] AH02282: No slotmem from mod_heartmonitor
[Mon Jan 23 10:05:36.887828 2017] [:warn] [pid 7323] mod_wsgi: Compiled for Python/2.7.10.
[Mon Jan 23 10:05:36.887832 2017] [:warn] [pid 7323] mod_wsgi: Runtime using Python/2.7.12.
[Mon Jan 23 10:05:36.889729 2017] [mpm_prefork:notice] [pid 7323] AH00163: Apache/2.4.23 (Amazon) mod_wsgi/3.5 Python/2.7.12 configured -- resuming normal operations
[Mon Jan 23 10:05:36.889744 2017] [core:notice] [pid 7323] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Mon Jan 23 10:06:43.542607 2017] [core:error] [pid 7328] [client 127.0.0.1:43786] Script timed out before returning headers: application.py
[Mon Jan 23 10:06:47.548360 2017] [core:error] [pid 7330] [client 127.0.0.1:43788] Script timed out before returning headers: application.py
[Mon Jan 23 10:06:51.550205 2017] [core:error] [pid 7331] [client 127.0.0.1:43790] Script timed out before returning headers: application.py
[Mon Jan 23 10:10:43.910014 2017] [core:error] [pid 7329] [client 127.0.0.1:43782] End of script output before headers: application.py
application.py
import flask
from flask import request, Response
import logging
import json
import JobType1
import JobType2
import sys
application = flask.Flask(__name__)
application.config.from_object('default_config')
application.debug = application.config['FLASK_DEBUG'] in ['true', 'True']`
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
@application.route('/', methods=['GET'])
def index():
logger.info("The message received was '/', no action taken")
response = Response("Success", status=200)
return response
@application.route('/StartJob', methods=['POST'])
def StartJob():
logger.info("!!start_job message received! This is the start job logger")
print("!!start_job message received! This is the start job printer")
response = None
if request.json is None:
response = Response("Error, no job specified.", status=400)
else:
message = dict()
try:
if request.json.has_key('TopicArn') and request.json.has_key('Message'):
message = json.loads(request.json['Message'])
job = message['job']
else:
message = request.json
job = message['job']
date_key = None
try:
date_key = message['runkey']
except Exception as e:
print "printing Exception:"
print e
pass
start_job(job, date_key)
response = Response("Called Job", status=200)
except Exception as ex:
logging.exception("There was an error processing this message: %s" % request.json)
response = Response("Error processing message", status=400)
return response
@application.route('/CronMessage', methods=['POST'])
def cron_message():
logger.info("!!Cron message received! This is the Cron Start Logger")
response = None
logger.info("About to print headers of CRON***")
job = request.headers.get('X-Aws-Sqsd-Taskname')
start_job(job, None)
response = Response("Called Job", status=200)
return response
def start_job(job_name, date_key):
logger.info("JOB NAME SUBMITTED IS:")
logger.info(job_name)
if job_name == 'JobType1':
start_job_if_not_running(job_name, JobType1.main, True, date_key)
if job_name == 'JobType2':
start_job_if_not_running(job_name, JobType2.main, True, date_key)
else:
print "Submitted job nome is invalid, no job started. The invalid submitted job name was %s" % job_name
def start_job_if_not_running(job_name, program_to_execute, uses_date_key_flag, date_key):
global running_jobs
logger.info("running_jobs are:")
logger.info(running_jobs)
if job_name in running_jobs:
logger.info("Currently running job " + job_name + ", will not start again.")
return False
else:
try:
running_jobs.append(job_name)
if uses_date_key_flag:
logger.info("")
program_to_execute(date_key)
else:
program_to_execute()
except Exception as e:
handle_job_end(job_name)
print "Error in " + job_name
error_message = str(e) + "-" + str(sys.exc_info()[0])
print error_message
EmailUsers.main(subject="Error in " + job_name,
message=error_message,
message_type='error',
date_key=date_key,
job_name=job_name,
process_name='application.py',
notification_group='bp_only')
handle_job_end(job_name)
def handle_job_end(job_name):
while job_name in running_jobs:
running_jobs.remove(job_name)
logger.info("Process Complete")
if __name__ == '__main__':
application.run(host='0.0.0.0', threaded=True)
此外,如果我导航到,则会/etc/httpd/conf.d/wsgi.conf
看到:
LoadModule wsgi_module modules/mod_wsgi.so
WSGIPythonHome /opt/python/run/baselinenv
WSGISocketPrefix run/wsgi
WSGIRestrictEmbedded On
<VirtualHost *:80>
Alias /static/ /opt/python/current/app/static/
<Directory /opt/python/current/app/static/>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias / /opt/python/current/app/application.py
<Directory /opt/python/current/app/>
Require all granted
</Directory>
WSGIDaemonProcess wsgi processes=1 threads=15 display-name=%{GROUP} \
python-path=/opt/python/current/app:/opt/python/run/venv/lib64/python2.7/site-packages:/opt/python/run/venv/lib/python2.7/site-packages user=wsgi group=wsgi \
home=/opt/python/current/app
WSGIProcessGroup wsgi
</VirtualHost>
LogFormat "%h (%{X-Forwarded-For}i) %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
@ user2752159的答案突出了该问题,但是我将添加此内容以显示如何在AWS
Beanstalk的上下文中解决此问题(即,如果新实例或您部署更多代码,则该问题将得以解决,而不必每次都在ssh框中修改wsgi.conf
)。
创建文件。(请注意,它以* .config结尾而不是conf)
nano .ebextensions/<some_name>.config
将以下内容添加到some_name.config
(mod_wsgi
docs
)
files:
"/etc/httpd/conf.d/wsgi_custom.conf":
mode: "000644"
owner: root
group: root
content: |
WSGIApplicationGroup %{GLOBAL}
添加到git
git add .ebextensions/<some_name>.config
git commit -m 'message here'
部署到beantalk
eb deploy
现在,每次部署时,WSGIApplicationGroup %{GLOBAL}
都会添加到中wsgi_custom.conf
,解决了该问题。
问题内容: 根据Docker文档:Dockerfile中只能有一条CMD指令。如果您列出多个CMD,则只有最后一个CMD才会生效。 我希望在CMD命令(本例中为init)之前执行一个简单的bash脚本(处理docker环境变量)。 有什么办法吗? 问题答案: 使用自定义入口点 创建一个可以执行所需操作的自定义入口点,然后最后执行您的CMD。 注意 :如果您的映像已经定义了一个自定义入口点,则可能需
我正在尝试检索电子表格的pdf。无论何时尝试,都会出现以下错误: 对的请求失败https://docs.google.com/a/firstcallres.com/spreadsheets/d/1ZPcW5cOQT5w28VUbr_JG9U-r7m6Uf-MDQcSmFOyhbE8/export?exportFormat=pdf 如果我在登录时单击上述URL,则会下载PDF。 如果我使用以下代码,
我正在写一个php脚本,它访问远程服务器上的csv文件,处理数据,然后将数据写入本地MySQL数据库。因为要处理和插入数据库的数据太多(50000行),所以脚本运行时间超过60秒。我的问题是,脚本在60秒后超时。 为了确保这不是MySQL的问题,我创建了另一个进入无限循环的脚本,它也会在60秒时超时。 我尝试增加/更改Ubuntu服务器上的以下设置,但没有帮助:max_execution_time
问题内容: 我想从PHP脚本返回JSON。 我只是回应结果吗?我必须设置标题吗? 问题答案: 通常,没有它会没事,但是您可以并且应该设置Content-Type标头: 如果不使用特定的框架,通常会允许一些请求参数来修改输出行为。通常,为了快速进行故障排除,不发送标头,或者有时将数据有效载荷print_r盯着它很有用(尽管在大多数情况下,它不是必需的)。