AWS Elasticbeanstalk上的Django:命令02_createadmin失败

时间:2014-02-10 19:42:42

标签: python django amazon-web-services elastic-beanstalk

我正在尝试部署我的第一个django应用程序,并选择具有弹性beanstalk的AWS,因为它似乎是最直接的方式。我一直在努力完成(过时的)official docs,但我完全陷入了尝试配置管理站点的困境(步骤7)。我也一直在使用this blog post和随附的肉鸡板代码。 我正在使用Python 2.7,Django 1.6.1,(本地)Windows 8和Powershell。

当我尝试部署我的应用程序时,出现错误:

  

[实例:i-03f98f2d模块:AWSEBAutoScalingGroup ConfigSet:null]实例上的命令失败。返回码:1输出:构建期间发生错误:命令02_createadmin失败。

以下是(我认为)日志的相关部分,如果这还不够,我很乐意更新更新:

2014-02-10 19:07:17,373 [INFO] (25971 MainThread) [command.py-130] [root command execute] Command returned: (code: 1, stdout: Error occurred during build: Command 02_createadmin failed
, stderr: None)
2014-02-10 19:07:17,375 [DEBUG] (25971 MainThread) [commandWrapper.py-60] [root commandWrapper main] Command result: {'status': 'FAILURE', 'results': [{'status': 'FAILURE', 'config_sets': ['Infra-WriteRuntimeConfig', 'Infra-WriteApplication1', 'Infra-WriteApplication2', 'Infra-EmbeddedPreBuild', 'Hook-PreAppDeploy', 'Infra-EmbeddedPostBuild', 'Hook-EnactAppDeploy', 'Hook-PostAppDeploy'], 'returncode': 1, 'events': [], 'msg': 'Error occurred during build: Command 02_createadmin failed\n'}], 'api_version': '1.0'}

...

2014-02-10 19:07:17,234 [DEBUG] Running command 02_createadmin
2014-02-10 19:07:17,235 [DEBUG] Generating defaults for command 02_createadmin
<<<

2014-02-10 19:07:17,319 [DEBUG] Running test for command 02_createadmin
2014-02-10 19:07:17,330 [DEBUG] Test command output: 
2014-02-10 19:07:17,331 [DEBUG] Test for command 02_createadmin passed
2014-02-10 19:07:17,340 [ERROR] Command 02_createadmin (scripts/createadmin.py) failed
2014-02-10 19:07:17,341 [DEBUG] Command 02_createadmin output: /bin/sh: scripts/createadmin.py: Permission denied

2014-02-10 19:07:17,341 [ERROR] Error encountered during build of postbuild_0_legi_track_prod: Command 02_createadmin failed
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 511, in run_config
    CloudFormationCarpenter(config, self._auth_config).build(worklog)
  File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 247, in build
    changes['commands'] = CommandTool().apply(self._config.commands)
  File "/usr/lib/python2.6/site-packages/cfnbootstrap/command_tool.py", line 113, in apply
    raise ToolError(u"Command %s failed" % name)
ToolError: Command 02_createadmin failed
2014-02-10 19:07:17,342 [ERROR] Unhandled exception during build: Command 02_createadmin failed
Traceback (most recent call last):
  File "/opt/aws/bin/cfn-init", line 122, in <module>
    worklog.build(detail.metadata, configSets)
  File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 117, in build
    Contractor(metadata).build(configSets, self)
  File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 502, in build
    self.run_config(config, worklog)
  File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 511, in run_config
    CloudFormationCarpenter(config, self._auth_config).build(worklog)
  File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 247, in build
    changes['commands'] = CommandTool().apply(self._config.commands)
  File "/usr/lib/python2.6/site-packages/cfnbootstrap/command_tool.py", line 113, in apply
    raise ToolError(u"Command %s failed" % name)
ToolError: Command 02_createadmin failed

我的档案:

legi_track_prod.config:

container_commands:
  01_syncdb:    
    command: "django-admin.py syncdb --noinput"
    leader_only: true
  02_createadmin:
    command: "scripts/createadmin.py"
    leader_only: true
  03_collectstatic:
    command: "django-admin.py collectstatic --noinput"

option_settings:
  - namespace: aws:elasticbeanstalk:container:python
    option_name: WSGIPath
    value: legi_track_prod/wsgi.py
  - namespace: aws:elasticbeanstalk:container:python:staticfiles
    option_name: /static/
    value: static/
  - option_name: DJANGO_SETTINGS_MODULE
    value: legi_track_prod.settings
  - option_name: AWS_SECRET_KEY
    value: key
  - option_name: AWS_ACCESS_KEY_ID
    value: key

/scripts/createadmin.py(我已经尝试了几个版本,它们似乎都不起作用):

#!/usr/bin/env python

from django.contrib.auth.models import User
if User.objects.count() == 0:
    admin = User.objects.create_superuser('admin', 'test@example.com', 'passwd')
    admin.save()

也尝试过:

#!/usr/bin/env python

from django.contrib.auth.models import User
if User.objects.count() == 0:
    admin = User.objects.create(username='admin')
    admin.set_password('admin')
    admin.is_superuser = True
    admin.is_staff = True
    admin.save()

文件的结构:

+---.ebextensions
+---.elasticbeanstalk
+---legi_track_prod
+---scripts
\---tracker
    +---api
    +---static
    |   \---tracker
    \---templates
        \---admin

我试过的:

  • 就像文档说的那样,我跑了 chmod + x scripts / createadmin.py 我每次保存文件都是安全的,我一直这样做,我不知道是否重新保存它会覆盖现有的权限。 我也尝试在.config文件中插入另一个命令来做同样的事情。我不确定这是不是问题,但有一条线 2014-02-10 19:07:17,341 [DEBUG]命令02_createadmin输出:/ bin / sh:scripts / createadmin.py:权限被拒绝 在日志中。

  • 我见过几行不同版本: 在我的谷歌搜索“#!/ usr / bin / env python”,并尝试将其更改为“#!/ usr / bin / env / python”,“#!/ usr / bin / env / python2.7”,“ #!/ usr / bin / env python manage.py“等。

  • 在本地开发应用程序时,运行“syncdb”并响应提示会自动设置管理员用户。有没有办法让命令01_syncdb为我处理?

  • 在完成本教程时,我确实跳过了shell中的一个步骤: 别名eb =“python2.7 ../AWS-ElasticBeanstalk-CLI-2.4.0/eb/linux/python2.7/eb” 我无法弄清楚命令的powershell等价物,并且所有“eb init”和“eb start”命令都能正常工作而无需设置别名。我不认为这是问题,但我也不确定这条线是做什么的。

如果可以的话,我会跳过这一步,但我无法找到任何其他方式来访问应用程序的数据库。我现在已经在这个特定的墙上撞了大约两天了,非常感谢任何帮助。我不可能是唯一一个遇到这个问题的人,但所有互联网都向我揭示了命令01_syncdb和03_collectstatics的问题/解决方案。关于如何使这个设置工作的任何建议,或者(或者)没有编写管理员创建的脚本?

更新

我正在运行它,并没有收到任何错误。该命令的文件路径看起来像是来自git,所以我不确定它是否与bash chmod做同样的事情。谷歌搜索“powershell chmod”变成了一个相当复杂的解决方法,所以我会试试。但是当我使用GUI查看文件的权限时,SYSTEM,admin和普通用户(本地)都拥有createadmin.py的所有权限,所以我不是权限没有正确设置,至少在本地。我将尝试使用powersmod版本的chmod,然后我想ssh进入aws服务器(我现在真的不知道该怎么做)并更新结果。

1 个答案:

答案 0 :(得分:4)

container_commands:
    00_make_executable:
        command: "chmod +x scripts/createadmin.py"
    01_...