我正在尝试按照https://cloud.google.com/python/django/flexible-environment上的Google教程
在GCP上部署我的django后端rest apis我能够成功部署示例应用,但是当我尝试部署我的django应用时,我得到以下错误:
latest: digest:
sha256:d43a6f7d84335f8d724e44cee16de03fd50685d6713107a83b70f44d3c6b5e8f
size: 2835
DONE
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Updating service [default] (this may take several minutes)...failed.
ERROR: (gcloud.app.deploy) Error Response: [9]
Application startup error:
[2018-04-03 13:01:35 +0000] [1] [INFO] Starting gunicorn 19.7.1
[2018-04-03 13:01:35 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
[2018-04-03 13:01:35 +0000] [1] [INFO] Using worker: sync
[2018-04-03 13:01:35 +0000] [7] [INFO] Booting worker with pid: 7
[2018-04-03 13:01:35 +0000] [1] [INFO] Shutting down: Master
[2018-04-03 13:01:35 +0000] [1] [INFO] Reason: Worker failed to boot.
在构建历史中,它显示了成功:
Build information
Status
Build successful
Build id
b2f2ab39-18df-420e-8fac-eeda74dc7a75
Image
eu.gcr.io/bcbackend-200008/appengine/default.20180403t182207:latest
Trigger
—
Source
gs://staging.bcbackend-200008.appspot.com/eu.gcr.io/bcbackend-
200008/appengine/default.20180403t182207:latest
Started
April 3, 2018 at 6:23:32 PM UTC+5:30
Build time
6 min 13 sec
在GCP日志中,它也没有显示错误,但是"工作人员无法启动":
A 2018/04/03 13:01:32 Ready for new connections
A 2018/04/03 13:01:33 Listening on /cloudsql/bcbackend-200008:europe-
west3:bc-mysql-instance for bcbackend-200008:europe-west3:bc-mysql-instance
A [2018-04-03 13:01:35 +0000] [1] [INFO] Starting gunicorn 19.7.1
A [2018-04-03 13:01:35 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
A [2018-04-03 13:01:35 +0000] [1] [INFO] Using worker: sync
A [2018-04-03 13:01:35 +0000] [7] [INFO] Booting worker with pid: 7
A [2018-04-03 13:01:35 +0000] [1] [INFO] Shutting down: Master
A [2018-04-03 13:01:35 +0000] [1] [INFO] Reason: Worker failed to boot.
A 2018/04/03 13:01:40 Ready for new connections
A 2018/04/03 13:01:41 Listening on /cloudsql/bcbackend-200008:europe-west3:bc-mysql-instance for bcbackend-200008:europe-west3:bc-mysql-instance
当我尝试打开" https://bcbackend-200008.appspot.com/"我得到了以下信息:
Error: Not Found
The requested URL / was not found on this server.
尝试用" - verbosity = debug"运行它选项及以下是日志:
DEBUG: (gcloud.app.deploy) Error Response: [9]
Application startup error:
[2018-04-04 12:34:42 +0000] [1] [INFO] Starting gunicorn 19.7.1
[2018-04-04 12:34:42 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
[2018-04-04 12:34:42 +0000] [1] [INFO] Using worker: sync
[2018-04-04 12:34:42 +0000] [7] [INFO] Booting worker with pid: 7
[2018-04-04 12:34:43 +0000] [1] [INFO] Shutting down: Master
[2018-04-04 12:34:43 +0000] [1] [INFO] Reason: Worker failed to boot.
Traceback (most recent call last):
File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line
788, in Execute
resources = calliope_command.Run(cli=self, args=args)
File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py",
line 760, in Run
resources = command_instance.Run(args)
File "/usr/lib/google-cloud-sdk/lib/surface/app/deploy.py", line 81, in
Run
parallel_build=False)
File "/usr/lib/google-cloud-
sdk/lib/googlecloudsdk/command_lib/app/deploy_util.py", line 583, in
RunDeploy
flex_image_build_option=flex_image_build_option)
File "/usr/lib/google-cloud-
sdk/lib/googlecloudsdk/command_lib/app/deploy_util.py", line 392, in Deploy
extra_config_settings)
File "/usr/lib/google-cloud-
sdk/lib/googlecloudsdk/api_lib/app/appengine_api_client.py", line 200, in
DeployService
poller=done_poller)
File "/usr/lib/google-cloud-
sdk/lib/googlecloudsdk/api_lib/app/operations_util.py", line 310, in
WaitForOperation
sleep_ms=retry_interval)
File "/usr/lib/google-cloud-
sdk/lib/googlecloudsdk/api_lib/util/waiter.py", line 251, in WaitFor
sleep_ms, _StatusUpdate)
File "/usr/lib/google-cloud-
sdk/lib/googlecloudsdk/api_lib/util/waiter.py", line 309, in PollUntilDone
sleep_ms=sleep_ms)
File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/core/util/retry.py",
line 226, in RetryOnResult
if not should_retry(result, state):
File "/usr/lib/google-cloud-
sdk/lib/googlecloudsdk/api_lib/util/waiter.py", line 303, in _IsNotDone
return not poller.IsDone(operation)
File "/usr/lib/google-cloud-
sdk/lib/googlecloudsdk/api_lib/app/operations_util.py", line 179, in IsDone
encoding.MessageToPyValue(operation.error)))
OperationError: Error Response: [9]
Application startup error:
[2018-04-04 12:34:42 +0000] [1] [INFO] Starting gunicorn 19.7.1
[2018-04-04 12:34:42 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
答案 0 :(得分:0)
尝试在app.yaml中将--preload
作为参数添加到gunicorn命令。这将在尝试启动工作人员时向您显示错误。这些错误将为您提供部署失败原因的线索。
您的app.yaml
应该是这样的:
runtime: python
env: flex
entrypoint: gunicorn --preload -b :$PORT mysite.wsgi
beta_settings:
cloud_sql_instances: <your-cloudsql-connection-string>
runtime_config:
python_version: 3