robksawyer / brenda-web

Web interface for submitting Blender render jobs to Amazon Web Services.
15 stars 4 forks source link

Get the EC2 Startup Script Working #13

Open robksawyer opened 9 years ago

robksawyer commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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.