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:
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:
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.
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?)
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?
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
Added additional command to instal.config to stop the service before the webdeploy package is applied as the service.exe locks some deployment files.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With