Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying windows service and web app on AWS Elastic Beanstalk

We want to deploy an ASP.NET MVC web application and windows service to elastic beanstalk. We use awsdeploy.exe to handle the deployment of the web application. The service and the web application share a configuration and libraries. To deploy the service my plan was:

  1. Include the windows service exe in the web deployment package \bin directory and deploy the service and web application together
  2. Use an .ebextensions file to install the service

However, this doens't seem to work as the .ebextensions actions are executed before the webdeploy package is installed so the service exe isn't available to be installed.

It seems that my options are:

S3

Zip the service exe and publish it to S3 so it is available to be installed by .ebextensions when the web application is deployed.

This isn't ideal as the service and web app share dependencies + configuration. The service would need to be installed with a separate set of dependencies and config as it would need to be up and running before the web application can be updated.

Post Deploy Scripts

Use the unsupported post deployment script technique which I'd need to translate into the windows world.

Windows directory = C:\Program Files\Amazon\ElasticBeanstalk\hooks\appdeploy\post There is a .ps1 script file there. (Is .cmd supported?)

Use the Web Deploy Package as a .ebextensions zip source

We could be able to use the webdeploy package @ "C:\cfn\ebdata\source_bundle.zip" as a source, unzip it and install the service from there. The problem is the internal paths in the zip are dependent on how the user's machine how built it was setup so finding the exe in the unzipped file structure would be tricky. Example path = "Content\C_C\gitdeploy\blah\blahSolution\blahProject\obj\awsTestDebug\Package\PackageTmp\bin\myservice.exe"

Any suggestions on which approach to take?

Edit

Taking Jim's advice I used container_commands and it works nicely. My .ebextensions/install.config looks like this..

...
container_commands:
  installTaskRunner:
    command: C:\\inetpub\\wwwroot\\App_Data\\installTaskRunner.cmd >> C:\\inetpub\\wwwroot\\App_Data\\installTaskRunner.log
commands:
  stop_service:
    command: net stop MyService
    ignoreErrors: true
...

The batch file looks like this...

pushd C:\inetpub\wwwroot\bin
C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\installutil  MyService.exe
net start MyService
popd

Edit #2

Added additional command to instal.config to stop the service before the webdeploy package is applied as the service.exe locks some deployment files.

like image 555
Sam Sippe Avatar asked Dec 18 '13 01:12

Sam Sippe


1 Answers

Regarding the post deploy scripts, any file in one of those folders with a .ps1, .bat, or .exe will be run during that stage. This is the method to use if you require fine control over when things happen on the instance.

There's a third option, which is to use container_commands: instead of commands:

container_commands: will be run after the application is deployed.

The documentation for this can be found in the Elastic Beanstalk Developer Guide.

like image 190
Jim Flanagan Avatar answered Sep 28 '22 06:09

Jim Flanagan