Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have been doing some reading and have come to the understanding that if you wish to use a launchConfig with Ubuntu you will need to install the cfn-init file yourself which I have done:

  "Properties" : {
    "KeyName" : { "Ref" : "KeyName" },
    "SpotPrice" : "0.05",
    "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" },
                                      { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" },
                                      "Arch" ] } ] },
    "SecurityGroups" : [ { "Ref" : "InstanceSecurityGroup" } ],
    "InstanceType" : { "Ref" : "InstanceType" },
    "UserData"       : { "Fn::Base64" : { "Fn::Join" : ["", [
      "#!/bin/bash\n",
      "apt-get -y install python-setuptools\n",
      "easy_install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-1.0-6.tar.gz\n",
      "cfn-init ",
      "         --stack ", { "Ref" : "AWS::StackName" },
      "         --resource LaunchConfig ",
      "         --configset ALL",
      "         --access-key ", { "Ref" : "WorkerKeys" },
      "         --secret-key ", {"Fn::GetAtt": ["WorkerKeys", "SecretAccessKey"]},
      "         --region ", { "Ref" : "AWS::Region" }, " || error_exit 'Failed to run cfn-init'\n"
    ]]}}

But I have a problem with this setup that I cannot seem to get a decent answer to. I keep getting this error in the logs:

Jun 15 12:02:34 ip-0 [CLOUDINIT] __init__.py[DEBUG]: config-scripts-per-once already ran once
Jun 15 12:02:34 ip-0 [CLOUDINIT] __init__.py[DEBUG]: handling scripts-per-boot with freq=None and args=[]
Jun 15 12:02:34 ip-0 [CLOUDINIT] __init__.py[DEBUG]: handling scripts-per-instance with freq=None and args=[]
Jun 15 12:02:34 ip-0 [CLOUDINIT] __init__.py[DEBUG]: handling scripts-user with freq=None and args=[]
Jun 15 12:02:34 ip-0 [CLOUDINIT] cc_scripts_user.py[WARNING]: failed to run-parts in /var/lib/cloud/instance/scripts
Jun 15 12:02:34 ip-0 [CLOUDINIT] __init__.py[WARNING]: Traceback (most recent call last):#012  File "/usr/lib/python2.7/dist-packages/cloudinit/CloudConfig/__init__.py", line 117, in run_cc_modules#012    cc.handle(name, run_args, freq=freq)#012  File "/usr/lib/python2.7/dist-packages/cloudinit/CloudConfig/__init__.py", line 78, in handle#012    [name, self.cfg, self.cloud, cloudinit.log, args])#012  File "/usr/lib/python2.7/dist-packages/cloudinit/__init__.py", line 326, in sem_and_run#012    func(*args)#012  File "/usr/lib/python2.7/dist-packages/cloudinit/CloudConfig/cc_scripts_user.py", line 31, in handle#012    util.runparts(runparts_path)#012  File "/usr/lib/python2.7/dist-packages/cloudinit/util.py", line 223, in runparts#012    raise RuntimeError('runparts: %i failures' % failed)#012RuntimeError: runparts: 1 failures
Jun 15 12:02:34 ip-0 [CLOUDINIT] __init__.py[ERROR]: config handling of scripts-user, None, [] failed
Jun 15 12:02:34 ip-0 [CLOUDINIT] __init__.py[DEBUG]: handling keys-to-console with freq=None and args=[]
Jun 15 12:02:34 ip-0 [CLOUDINIT] __init__.py[DEBUG]: handling phone-home with freq=None and args=[]
Jun 15 12:02:34 ip-0 [CLOUDINIT] __init__.py[DEBUG]: handling final-message with freq=None and args=[]
Jun 15 12:02:34 ip-0 [CLOUDINIT] cloud-init-cfg[ERROR]: errors running cloud_config [final]: ['scripts-user']

I have absolutely no idea what scripts-user means and Google is not helping much here either. I can, when I ssh into the server, see that it runs the userdata script since I can access cfn-init as a command whereas I cannot in the original AMI the instance is made from.

However I have a launchConfig:

    "Comment" : "Install a simple PHP application",
    "AWS::CloudFormation::Init" : {
      "configSets" : {
        "ALL" : ["WorkerRole"]
      },
      "WorkerRole" : {
        "files" : {
          "/etc/cron.d/worker.cron" : {
            "content" : "*/1 * * * * ubuntu /home/ubuntu/worker_cron.php &> /home/ubuntu/worker.log\n",
            "mode"    : "000644",
            "owner"   : "root",
            "group"   : "root"
          },

          "/home/ubuntu/worker_cron.php" : {
            "content" : { "Fn::Join" : ["", [
                "#!/usr/bin/env php",
                "<?php",
                "define('ROOT', dirname(__FILE__));",
                "const AWS_KEY = \"", { "Ref" : "WorkerKeys" }, "\";",
                "const AWS_SECRET = \"", { "Fn::GetAtt": ["WorkerKeys", "SecretAccessKey"]}, "\";",
                "const QUEUE = \"", { "Ref" : "InputQueue" }, "\";",
                "exec('git clone x '.ROOT.'/worker');",
                "if(!file_exists(ROOT.'/worker/worker_despatcher.php')){",
                "echo 'git not downloaded right';",
                "exit();",
                "}",
                "echo 'git downloaded';",
                "include_once ROOT.'/worker/worker_despatcher.php';"
            ]]},
            "mode"    : "000755",
            "owner"   : "ubuntu",
            "group"   : "ubuntu"
          }
        }
      }
    }

Which does not seem to run at all. I have checked for the files existance in my home directory and it's not there. I have checked for the cronjob entry and it's not there either. I cannot, after reading through the documentation, seem to see what's potentially wrong with my code.

Any thoughts on why this is not working? Am I missing something blatant?

share|improve this question
    
cc_scripts_user.py[WARNING]: failed to run-parts in /var/lib/cloud/instance/scripts: One of the scripts in that directory executed unsuccessfully. Run the scripts in there manually to see why. –  mgorven Jun 16 '12 at 5:22
    
Will do! thanks for the tip :) –  Sammaye Jun 16 '12 at 11:12

1 Answer 1

up vote 0 down vote accepted

Ok Solved.

I randomly decided that, to better debug, I would make a min instance count of 1. This threw up an error about my launchConfig. After some trolling around I found out that I had made a really big mistake with my template. So I changed the launchConfig to:

"LaunchConfig" : {
  "Type" : "AWS::AutoScaling::LaunchConfiguration",
  "Metadata" : {
    "Comment" : "Install a simple PHP application",
    "AWS::CloudFormation::Init" : {
       "config" : {
        "files" : {
          "/etc/cron.d/worker" : {
            "content" : "*/1 * * * * ubuntu /home/ubuntu/worker_cronjob &> /home/ubuntu/worker.log\n",
            "mode"    : "000644",
            "owner"   : "root",
            "group"   : "root"
          },

          "/home/ubuntu/worker_cronjob" : {
            "content" : { "Fn::Join" : ["", [
                "#!/usr/bin/env php\n",
                "<?php\n",
                "define('ROOT', dirname(__FILE__));",
                "const AWS_KEY = \"", { "Ref" : "WorkerKeys" }, "\";",
                "const AWS_SECRET = \"", { "Fn::GetAtt": ["WorkerKeys", "SecretAccessKey"]}, "\";",
                "const QUEUE = \"", { "Ref" : "InputQueue" }, "\";",
                "exec('git clone x '.ROOT.'/worker');",
                "if(!file_exists(ROOT.'/worker/worker_despatcher.php')){",
                "echo 'git not downloaded right';",
                "exit();",
                "}",
                "echo 'git downloaded';",
                "include_once ROOT.'/worker/worker_despatcher.php';"
            ]]},
            "mode"    : "000755",
            "owner"   : "ubuntu",
            "group"   : "ubuntu"
          }
        }
      }
    }
  },

And my userdata to:

    "UserData"       : { "Fn::Base64" : { "Fn::Join" : ["", [
      "#!/bin/bash\n",
      "apt-get -y install python-setuptools\n",
      "easy_install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz\n",
      "cfn-init -v ",
      "         -s ", { "Ref" : "AWS::StackName" },
      "         -r LaunchConfig ",
      "         --access-key ", { "Ref" : "WorkerKeys" },
      "         --secret-key ", {"Fn::GetAtt": ["WorkerKeys", "SecretAccessKey"]},
      "         --region ", { "Ref" : "AWS::Region" }, "\n"
    ]]}

And now everything works dandy.

So if you get the users-script error it means that your launch config is wrong and you should look at it again.

Thanks for the help :)

share|improve this answer
    
It'd be helpful if you could explain what the "really big error" in you template was so that others can avoid it :) –  chrisbunney May 19 at 10:38
    
@chrisbunney Sorry abut that, I found the big error to be formatting, basically syntactical errors which cloudformation didn't seem to break on. –  Sammaye May 19 at 11:43
    
Thanks for the clarification :) –  chrisbunney May 21 at 14:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.