Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django on AWS Elasticbeanstalk: Command 02_createadmin failed

I'm trying to deploy my first django application, and chose AWS with elastic beanstalk because it seemed like the most straightforward way to do so. I have been haltingly working through the (outdated) official docs, but am completely stuck trying to configure the admin site (step 7). I've also been using this blog post and the accompanying broilerplate code. I'm using Python 2.7, Django 1.6.1, (locally) Windows 8 with Powershell.

When I try to deploy my application, I get the error:

[Instance: i-03f98f2d Module: AWSEBAutoScalingGroup ConfigSet: null] Command failed on instance. Return code: 1 Output: Error occurred during build: Command 02_createadmin failed.

Here's what (I think) the relevant part of the logs looks like, I'd be happy to update with more if this isn't enough:

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

My files:

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 (I've tried several versions of this, none of them seem to work):

#!/usr/bin/env python

from django.contrib.auth.models import User
if User.objects.count() == 0:
    admin = User.objects.create_superuser('admin', '[email protected]', 'passwd')
    admin.save()

Also tried:

#!/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()

File-structure:

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

What I've Tried:

  • Like the docs say, I run chmod +x scripts/createadmin.py I've been doing this every time I save the file to be safe, I don't know if re-saving it overwrites the existing permissions. I also tried inserting another command into the .config file to do the same thing. I'm not sure if this is the problem, but there is that line 2014-02-10 19:07:17,341 [DEBUG] Command 02_createadmin output: /bin/sh: scripts/createadmin.py: Permission denied in the logs.

  • I've seen a couple different versions of the line: "#!/usr/bin/env python" in my googling, and have tried changing it to "#!/usr/bin/env/python", "#!/usr/bin/env/python2.7", "#!/usr/bin/env python manage.py", etc.

  • When developing the app locally, running "syncdb" and responding to the prompts sets up the admin user automatically. Is there some way to have command 01_syncdb take care of that for me?

  • When working through the tutorial, I actually did skip a step in the shell: alias eb="python2.7 ../AWS-ElasticBeanstalk-CLI-2.4.0/eb/linux/python2.7/eb" I couldn't figure out the powershell equivalent of the command, and all of the "eb init" and "eb start" commands worked fine anyways without setting up the alias. I don't think this is the issue, but I'm also not really sure what this line does.

I would just skip this step if I could, but I can't figure out any other way to get access to the app's database. I have been banging my head against this particular wall for about two days now, and would really appreciate any help. I can't be the only one to have had this problem, but all the internet reveals to me is problems/solutions for commands 01_syncdb and 03_collectstatics. Any advice on how to get this setup to work, or (alternatively) get by without scripting the creation of the admin?

Update

I'm running it exactly, and not getting any error. The filepath for the command looks like its coming from git, so I'm not sure if it's doing the same thing as the bash chmod. Googling "powershell chmod" turns up a fairly complicated workaround, so I'll try that. But when I use the GUI to look at the file's permissions, SYSTEM, admin, and regular user (locally) all have all permissions for createadmin.py, so I'm not the permissions haven't been set correctly, at least locally. I'll try the powershell version of chmod, and then I guess ssh into the aws server (which I really don't know how to do at the moment) and update with the results.

like image 957
J.Necker Avatar asked Feb 10 '14 19:02

J.Necker


1 Answers

container_commands:
    00_make_executable:
        command: "chmod +x scripts/createadmin.py"
    01_...
like image 68
kukido Avatar answered Nov 08 '22 03:11

kukido