Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the EC2 Startup Script Working #13

Open
robksawyer opened this issue Jun 18, 2015 · 4 comments
Open

Get the EC2 Startup Script Working #13

robksawyer opened this issue Jun 18, 2015 · 4 comments

Comments

@robksawyer
Copy link
Owner

This script handles sending the SQS queue messages to the EC2 instances. This is located in api/services/amazon.js -> startupScript.

It looks something like this:

startupScript: function(){
        //def startup_script(opts, conf, istore_dev):
        var login_dir = "/root";

        var head = "#!/bin/bash\n";
        var script = "";

        // use EC2 instance store on render farm instance?
        //var use_istore = int(conf.get('USE_ISTORE', '1' if istore_dev else '0'))

        /*if use_istore{
                # script to start brenda-node running
                # on the EC2 instance store
                iswd = conf.get('WORK_DIR', '/mnt/brenda')
                if iswd != login_dir:
                    head += """\
        # run Brenda on the EC2 instance store volume
        B="%s"
        if ! [ -d "$B" ]; then
          for f in brenda.pid log task_count task_last DONE ; do
            ln -s "$B/$f" "%s/$f"
          done
        fi
        export BRENDA_WORK_DIR="."
        mkdir -p "$B"
        cd "$B"
        """ % (iswd, login_dir)
                else:
                    head += 'cd "%s"\n' % (login_dir,)
            else:
                head += 'cd "%s"\n' % (login_dir,)

            head += "/usr/local/bin/brenda-node --daemon <<EOF\n"
            tail = "EOF\n"
            keys = [
                'AWS_ACCESS_KEY',
                'AWS_SECRET_KEY',
                'BLENDER_PROJECT',
                'WORK_QUEUE',
                'RENDER_OUTPUT'
                ]
            optional_keys = [
                "S3_REGION",
                "SQS_REGION",
                "CURL_MAX_THREADS",
                "CURL_N_RETRIES",
                "CURL_DEBUG",
                "VISIBILITY_TIMEOUT",
                "VISIBILITY_TIMEOUT_REASSERT",
                "N_RETRIES",
                "ERROR_PAUSE",
                "RESET_PERIOD",
                "BLENDER_PROJECT_ALWAYS_REFETCH",
                "WORK_DIR",
                "SHUTDOWN",
                "DONE"
                ] + list(aws.additional_ebs_iterator(conf))

            script = head
            for k in keys:
                v = conf.get(k)
                if not v:
                    raise ValueError("config key %r must be defined" % (k,))
                script += "%s=%s\n" % (k, v)
            for k in optional_keys:
                if k == "WORK_DIR" and use_istore:
                    continue
                v = conf.get(k)
                if v:
                    script += "%s=%s\n" % (k, v)
            script += tail*/
        return script
    },
@robksawyer
Copy link
Owner Author

I have it writing a script similar to the following. So, I'm hoping this will work.

#!/bin/bash
cd "/root"
/usr/local/bin/brenda-node --daemon <<EOF
AWS_ACCESS_KEY=HIDDEN
AWS_SECRET_KEY=HIDDEN
BLENDER_PROJECT=s3://HIDDEN/Chinchillax_YellowParticleMesh.gz
WORK_QUEUE=sqs://HIDDEN
RENDER_OUTPUT=s3://HIDDEN
S3_REGION=us-west-2
SQS_REGION=us-west-2
DONE=shutdown
EOF

@robksawyer
Copy link
Owner Author

Bummer, it seems like this didn't work.
Uploading Screen Shot 2015-06-19 at 2.13.37 AM.png…
screen shot 2015-06-19 at 2 14 00 am

robksawyer added a commit that referenced this issue Jun 19, 2015
@robksawyer
Copy link
Owner Author

The following articles were good leads to what hopefully solves the problem. The UserData apparently needs to be in base64 format.

http://stackoverflow.com/questions/6182315/how-to-do-base64-encoding-in-node-js
http://serverfault.com/questions/592423/how-do-i-launch-an-amazon-ec2-spot-instance-with-userdata

@robksawyer
Copy link
Owner Author

screen shot 2015-06-19 at 1 31 36 pm

Well it worked. Now I need to ensure it actually pulls from the SQS queue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant