Fixing Codesign Issues with Helper Apps

I’ve been getting “Invalid binary” errors, while trying to upload a binary to the AppStore. The solution can be found in stackoverflow, i’m just pasting it here, for future reference…

1. Re-Codesign the Helper app from terminal:

codesign -f -s "3rd Party mac Developer Application:" -i "com.bundle.YOUR.HELPER" --entitlements path/to/helper/entitlements YOUR-HELPER.app

2. 

Remove provisioning profile from Helper app, adding a “Run script” into the “Build Phases”:

rm "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/Contents/Library/LoginItems/YOUR-HELPER.app/Contents/embedded.provisionprofile"

After this, i managed to upload the binary!

 

Route53 Failover Mechanism!

Situation: you run your own website on an Amazon EC2 instance. Something happens: maybe the box runs out of resources (ddos, high traffic, you pick one!).
All of the sudden, your website is offline. Downtime means that Google will push it down in the ranking. So what do we do?.

Well, AWS Route53 has a new, and super cool mechanism, that allows you to set Health Checks. If the website doesn’t pass it, the DNS record will switch to a failover entry.

How can we achieve this?. Amazon itself posted a detailed guide here. Just for the record, here you will find details about when a website is considered healthy.

A couple details:

  1. I’ve used SiteSucker, a free OSX tool, that allows you to create a simple HTML backup. Running a static S3 backup is way cheaper than running two instances!.
  2. If your apache logfile grows **a lot** due to the HealthCheck hits, you can disable the logs, if the user agent is “Route 53”. Simply put the following in your .htaccess:

    SetEnvIfNoCase User-Agent .*Route 53.* dontlog

    Don’t forget about tweaking your website.com.conf apache file, to look like this:

    CustomLog logs/access_log common env=!dontlog

This is just… sooooo cool!

OSX: Fixing SSH hangs!

This glitch is pretty annoying. You’re following a log, while connected to a server (through ssh), and after a while, your ssh connection hangs.
The solution?.

Fire up Terminal, and type the following: nano ~/.ssh/config

Once there, fill up the following:

ServerAliveInterval 300
ServerAliveCountMax 120

That should keep your connection alive for the next 10 hours, without further issues.

Waiting until two async blocks are executed

The following snippet of code.. which is super interesting, is based on this post. This allows to dispatch a block, on Main Thread, once two async operations are completed.

dispatch_group_t group = dispatch_group_create();

dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^ {
  NSLog(@"Block1");
  [NSThread sleepForTimeInterval:5.0];
  NSLog(@"Block1 End");
});

dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^ {
  NSLog(@"Block2");
  [NSThread sleepForTimeInterval:8.0];
  NSLog(@"Block2 End");
});

dispatch_group_notify(group, dispatch_get_main_queue(), ^ {
  NSLog(@"Block3 :: %d", [NSThread isMainThread]);
});

dispatch_release(group);

Fixing High I/O usage on Amazon EBS

This humble wordpress blog is running on an AWS micro instance. We’ve got somewhere around 1k visitors each month, which is pretty awesome. But… to my surprise, the whole system is using over 14 million I/O operations.

I suspected there was something wrong with this… so i proceeded to do a small research.
By means of the application ‘iotop’, i managed to spot the I/O hog: apache!.

Specifically, i ran iotop with the following parameters:

sudo iotop -a -P

I ran a quick search on google, and found this post.  (Thank you George, for sharing your solution!).

Long short story, Apache’s APC plugin was using a memory mapped file, and it was writing… almost all the time.
The solution?. Edit your /etc/php.d/apc.ini file, and make sure that the mmap_file_mask parameter is se to use Shared Memory, as follows:

apc.mmap_file_mask=/apc.shm.XXXXXX

That should fix it!