Changing Elastic Beanstalk (Ruby) Passenger ngnix Config

January 19, 2014 16:20 by docbliny 

Is that title geeky enough for you? If so, keep reading…

Problem

I had to get Amazon CloudFront CDN configured this weekend for a Ruby project. This was mostly straightforward, and there are plenty of instructions on the web on how to go about that.

However, static assets are delivered by Phusion Passenger Standalone under the Ruby container for Amazon Elastic Beanstalk. This means you can’t set headers for those files in Ruby. Why is this an issue? Well, if you’ve got custom fonts, you’ll need to set CORS headers for those fonts to work on Internet Explorer and Firefox:

Access-Control-Allow-Origin: *

Solution

OK, this is where it gets to the usual “I just lost a day” situation. All the pieces were available, but getting everything glued together, and going through a rather slow deployment to test each iteration was a time sink. What you need to do is:

  1. Change the nginx configuration to add the CORS header to all font files by patching the Passenger config.erb template file.
  2. Patch Amazon’s broken /etc/init.d/passenger file so you can actually restart the service.

Note: I'm leaving the layout of this page broken in the file examples below to avoid confusion with line wrapping.

Modifying the nginx config template

You’ll need to create a file in the projects .ebextensions folder similar to the following:

00-passenger.config

files:
  "/home/ec2-user/inject_headers.sh" :
    mode: "000777"
    owner: ec2-user
    group: ec2-user
    content: |
      #!/bin/bash
      CONFIG_FILE=$(passenger-config --root)/resources/templates/standalone/config.erb
      MATCH=$(grep '(eot)|(ttf)|(woff)' $CONFIG_FILE)
      if [ -z "$MATCH" ]; then
        cp -f $CONFIG_FILE $CONFIG_FILE.bak
        sed -e'/location @static_asset {/a \\t if ($request_filename ~* ^.*?\.(eot)|(ttf)|(woff)$){ add_header Access-Control-Allow-Origin *; }' $CONFIG_FILE.bak >$CONFIG_FILE
      fi
commands:
  00-inject-font-headers:
    command: sh /home/ec2-user/inject_headers.sh
    cwd: /home/ec2-user

Then patch /etc/init.d/passenger:

01-patch-passenger.config

commands:
  01-patch-passenger-init:
    command: sed -i 's/passenger stop \$OPTS/passenger stop -p \$EB_CONFIG_HTTP_PORT --pid-file \$EB_CONFIG_APP_PIDS\/passenger.pid/' /etc/init.d/passenger

...and finally restart passenger so this goes into effect before CloudFront can hit font files and cache them without the correct headers:

02-restart-passenger.config

commands:
  02-restart-passenger:
    command: /etc/init.d/passenger restart

notes

  • This was done on the 64bit Amazon Linux 2013.09 running Ruby 1.9.3 container.
  • The real runtime nginx configuration file ends up under /tmp/passenger-standalone.[random]/config. Check it to make sure the changes are applied.
  • /log/var/cfn-init.log is your friend when debugging the .ebextensions.
  • I was having issues with the initial deployment for a newly created environment not being applied (I just got the placeholder page from Amazon). This was always resolved by pushing the same application version again to the environment. The error in the Beanstalk event console was: The following instances have not responded in the allowed command timeout time (they might still finish eventually on their own)

Latest Google Chrome kills “Most Recent Tabs” feature

September 27, 2013 12:59 by docbliny 

UPDATE 2/22/2014: Google kills the workaround without fixing the original issue. Total cluster-fail. #chromefail

Well, not completely (unless you’re an unlucky sod like me), but makes it unusable. You now have to reopen each previously closed tab one-by-one. No more clicking on “21 closed tabs” to open up what you were working on previously. Unfortunately, the new menu item is greyed out completely for me and doesn’t show _any_ recently closed tabs.

Luckily, there’s a way to disable this new feature (along with the new big search box and not seeing Chrome Apps in the start window):

  1. Open a new tab, and enter chrome://flags .
  2. Search for Enable Instant Extended API for Mac, Windows, Chrome OS.
  3. Select Disabled from the dropdown.
  4. Restart Chrome.

Wave licensing center suddenly think you’re on a different machine?

September 15, 2013 16:02 by docbliny 

I started up Cubase for the first time in a few weeks, and I immediately got an error from my Waves plug-ins stating that its licenses couldn’t be found. This obviously freaked me out; I started the Wave License Center, and noticed that it couldn’t identify my machine anymore, and all my old licenses were listed under View All Licenses under the real name of the computer.

Long story short, I’d installed Visual Studio 2013 Pro Preview and along with that the Windows Phone dev kit (Don’t get me started how bad an idea it is to have everything on one machine…). Anyway, Waves didn’t recognize the machine because the network traffic was going through the Hyper-V vEthernet (External Switch) adapter with a different MAC address.

The fix:

  1. Start Hyper-V Manager.
  2. Click Virtual Switch Manager under the Actions pane.
  3. Select External Switch under the Virtual Switches pane/group.
  4. Select Internal Network, and then click OK.
  5. Close the Hyper-V Manager control panel.
  6. Open up your Network Connections control panel, and then disable vEthernet (External Switch) and vEthernet (Internal … Windows Phone Emulator…).
  7. Reboot (to be safe).

After a restart (and writing this post), I was good to go (but where’d my musical inspiration run off to in the meantime?)


Surface Pro and Screen Rotation Issue

February 17, 2013 10:10 by docbliny 

I was having the rather irritating issue with my Surface Pro where I’d hop on the train for my morning or afternoon commute, and the screen wouldn’t rotate (change the orientation) when I was trying to read with my Kindle app. What made it frustrating was that it’d start working again when I arrived. I read the troubleshooting document and then contacted Microsoft support and they weren’t able to reproduce the issue. This morning, I finally figured out what was going on.

More...


XBox Live MTU Error

February 4, 2012 13:37 by docbliny 

Had issues with XBox Live complaining about the MTU size not being sufficient. Well, that wasn’t actually the cause for me. In the end, I had to turn off uPnP on my Cisco RV082 firewall to get the network connection test to pass and to be able to sign into XBox Live.


FlexCover Startup Problem

April 30, 2009 16:09 by docbliny 

If you get the error “Another program has already opened a LocalConnection with id ‘_flexcover’. No coverage data will be recorded.”, do the following:

  1. Open Task Manager and kill any instances of CoverageViewer.exe (or your Mac equivalent).
  2. Close all browsers.
  3. Close FlexBuilder.
  4. Close Yahoo! Messenger (or other client that hosts the Flash Player).

#3 did it for me.

I was using FlexCover 0.81.