Archive for December, 2013

Deploy a Windows Service on Elastic Beanstalk

I recently needed to add a Windows Service to a web app solution to handle some long-processing operations asynchronously. The web app is being deployed to Elastic Beanstalk (EB). You can log into the EC2 instance that EB creates and install the service manually, but this won’t last. EB can delete your instance at any time and create another one, and redeploy the app from it’s own git repository. So in order for the service to persist, it also has to be installed during the deployment. Fortunately for us, Amazon already supports this and there is a introductory article explaining how to do it and some sparse documentation.

Basically, you are adding a new directory called .ebextensions to your .Net project.  In that directory you place YAML files with a .config extension. The YAML files contain the commands you can execute, as described in the docs. You can have more than one file, they execute in alphabetical order. The series of commands you create allow you to install the Windows Service when deploying a web application to EB.

Unfortunately, the procedure in the article only works on the initial install. If you need to push incremental updates, the script just doesn’t work because you can’t copy files over the versions currently in use by the Windows Service. Stopping the service wasn’t working for me because the account performing the deployment didn’t seem to have enough permissions to stop the service.  But it did have enough permissions to uninstall and install the service.

The solution ended up being similar to the article, but with some variation. The correct steps for me turned out to be:

  1. Fetch the zipped files from S3, unzipping to a temp location
  2. Create the destination directory, ignoring errors (it already exists for updates)
  3. Uninstall the existing Windows Service, also ignoring errors (the service doesn’t exist on the first install)
  4. Copy the unzipped files in the temp directory to the destination directory
  5. Install the Windows Service
  6. Start the Windows Service

This translates to the following YAML file:

command: mkdir c:\\service\\serviceName\\Release
    cwd: “c:/service/temp/”
    waitAfterCompletion: 0
    ignoreErrors: true
    command: C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\installutil NameOfService.exe /u > “Remove.txt”
    cwd: “c:/service/serviceNamer/Release”
    waitAfterCompletion: 11
    ignoreErrors: true
    command: copy c:\\service\\temp\\Release c:\\service\\vserviceName\\Release
    cwd: “c:/service/temp/”
    waitAfterCompletion: 0
    command: C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\installutil NameOfService.exe > “Install.txt”
    cwd: “c:/service/serviceName/Release”
    waitAfterCompletion: 0
    enabled: true
    ensureRunning: true
    commands: d-install-service
The service uninstall/install commands are piping out their results to text files, so that if there is an error during execution I can RDP to the server and take a look at the specific error message. Also of note for troubleshooting, there is a directory created by the EB install process at c:\cfn. It contains a log directory, and in there is cfn-init.txt. If your install process fails, the errors can be found there.

Posted on:
Posted in .Net 4.5, ASP.NET, Cloud | Comments Off on Deploy a Windows Service on Elastic Beanstalk

Mobile Development Is New or Different?

The Mobile Problem

In a mobile device, we have four factors that are different from contemporary desktop computers. They are:

  • Less memory
  • Less CPU capacity
  • Constrained network bandwidth
  • Small screen size

These thing may seem difficult, but really we experienced this before in the early days of the web explosion. PC’s were much less powerful, common screen resolutions were 640 x 480, and network access was over a 14.4k modem or less. We’ve just gotten lazy in the days of blazing networks and a dozen iterations of Moore’s law, and some of us developing for mobile today never even lived through any of that.

Memory constraints certainly keep us on our toes. We can’t be sure our app will survive consistently in the phone OS, it could be terminated at any time due to memory constraints based on user activity. So we solve problems by making objects parcelable in Android, or persisting the state of any given network call in a database so we can pick up again at a later time if necessary.

These constraints are driving how we design apps and the systems that support them. REST + JSON gives us smaller network messages. We minimize CPU usage by preferring JSON over XML so there is less effort serializing, and we offload complex or data-intensive calculations to a server somewhere in the cloud.

Mobile has rightfully caused the rise of graphic design as a regular component in app development, not just something start-ups are doing. Apps are getting more user-friendly despite the small screen size, and focused in their functionality as a result of good design. Users like apps, no longer is it something they are forced to use because they have choices. Also, users finally get a vote (in $$) on whether or not an app succeeds. We are getting away from monolithic web apps. Smaller apps have fewer paths which make them more testable and have fewer bugs  as a result which is better for users.

This time around developers have the benefit of having lived through the web explosion and learned what not to do. I hope more companies build enterprise-level mobile apps keeping this in mind and don’t recreate the nightmarish internal web apps on phones.

Posted on:
Posted in Mobile | Comments Off on Mobile Development Is New or Different?