How to setup supervisord on Elastic Beanstalk? - amazon-elastic-beanstalk

I am migrating from DotCloud to Elastic Beanstalk.
Using DotCloud, they clearly explained how to set up Python Worker, and how to use supervisord.
Moving to Elastic Beanstalk, I am lost on how I could do that.
I have a script myworker.py and want to make sure it is always running. How?

Elastic Beanstalk is just a stack configuration tools over EC2, ELB and autoscaling.
One approach you can use, is create your own AMI, but since October last year, there is another approach that probably will be more suitable for your needs: ebextensions.
.ebextension is just a directory in your application, that get's detected once your application has been loaded by AWS.
Here is the full documentation: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers.html

With Amazon Linux 2 you need to use the .platform folder to supply elastic beanstalk with installation scripts.
We recommend using platform hooks to run custom code on your environment instances. You can still use commands and container commands in .ebextensions configuration files, but they aren't as easy to work with. For example, writing command scripts inside a YAML file can be cumbersome and difficult to test.
So you should add a prebuild hook (example) into a .platform folder to install supervisor and a postdeploy hook (example) to restart supervisor after each deployment.
There is an ini file (example) used in the script; which is made for laravel specific.
Make sure that the .sh files from the .platform folder are executable before deploying your project:
$ chmod +x .platform/hooks/prebuild/*.sh
$ chmod +x .platform/hooks/postdeploy/*.sh

Related

How to perform batch jobs after Elastic Beanstalk deployment unzipping uploaded file

I need to make some files executable after AWS elastic-beanstalk unzip my uploaded zipped file. I need elastic-beanstalk automatically do chmod before the application can work properly such as:
sudo chmod 755 /var/www/html/mybin/executablefile1
sudo chmod 755 /var/www/html/mybin/executablefile2
How to do this properly?
You can write the commands you want to execute (including chmod) in container_commands section of your .ebextensions:
Container commands run after the application and web server have been set up and the application version archive has been extracted, but before the application version is deployed.
Alternatively, you can also use one of deployment platform hooks. For example your custom script in postdeploy:
Files here run after the Elastic Beanstalk platform engine deploys the application and proxy server. This is the last deployment workflow step.

Deploying Code and Managing configuration with Terraform

Just to give context:
I am planning to use Terraform to bring up new separate environments with ec2 machines, elb etc. and then maintaining configuration as well.
Doing that with terraform and using AWS provider sounds fairly simple.
Problem 1:
While launching those instances I want to install few packages etc. so that when Terraform launches the instances (servers) things/ apps should be up and running.
Assuming the above is up and running:
Problem 2:
How do I deploy new code on the servers in this environment launched by Terraform?
Should I use for eg. ansible playbooks/chef recipes/puppet manifests for that? or Terraform gives some other options/ways?
Brief answers:
Problem 1: While launching those instances I want to install few packages etc. so that when Terraform launches the instances (servers) things/ apps should be up and running.
A couple of options:
Create an AMI of your instance with the installed packages and specify that in the resource.
Use the user data script to install the packages that you need when the instance starts.
Use ansible playbooks/chef recipes/puppet to install packages once the instance is running (e.g. creating an opsworks stack with terraform)
Problem 2: How do I deploy new code on the servers in this environment
launched by Terraform? Should I use for eg. ansible playbooks/chef
recipes/puppet manifests for that? or Terraform gives some other
options/ways?
Not the intended use case for terraform, use other tools like jenkins or aws services like codepipeline or codedeploy. Ansible/chef/puppet can also help (e.g. with opsworks)

Run command on the client during eb deploy

My specific problem is that I would like to include the output of git rev-parse HEAD in a text file before deployment to ElasticBeanstalk. I believe the best way to solve it is to hook into the eb deploy command. I don't want to wrap eb deploy in a script.
I know .ebextensions defines commands that are executed on the ec2 instance during different phases of the deployment. Is there a similar utility for the client side?

Alternative ways to deploy code to Openshift

I am trying to setup Travis CI to deploy my repository to Openshift on a successful build. Is there a way to deploy a repository besides using Git?
Git is the official mechanism for how your code is update, however depending on the type of application that you are deploying you may not need to deploy your entire code base.
For example Java application (war, ear, etc) can be deployed to JBoss or Tomcat servers, by simply taking the built application and checking it into the OpenShift git repositories, webapps or deploy directories.
An alternative to this (and it will be unsupported), is to scp your application to the gear using the SSH key. However any time the application is moved or updated (with git) this content stands a good chance of getting deleted(cleaned), by the gear.
We're working on direct binary deploys ("push") and "pull" style deploys (Openshift downloads a binary for you. The design/process is described here:
https://github.com/openshift/openshift-pep/blob/master/openshift-pep-006-deploy.md
You can do a SCP to the app-root/dependencies/jbossews/webapps directory direcly. I was able to do that successfully and have the app working. Here is the link
Here is the code which I had in the after_success blck
after_success:
- sudo apt-get -y install sshpass
- openssl aes-256-cbc -K $encrypted_8544f7cb7a3c_key -iv $encrypted_8544f7cb7a3c_iv
-in id_rsa.enc -out ~/id_rsa_dpl -d
- chmod 600 ~/id_rsa_dpl
- sshpass scp -i ~/id_rsa_dpl webapps/ROOT.war $DEPLOY_HOST:$DEPLOY_PATH
Hope this helps

Run a task before svn check-out

I would like to run a task (stop a running vm machine) before Jenkins starts the check-out.
The reason is: VM blocks access to some files I have to update via subversion.
Is this possible?
There are two plugins for controlling virtual machines, depending on whether you are using VirtualBox or VMWare.
I'm quite sure you can configure the pre-build step to be "Suspend" as shown in the images, at least for VMWare.
VMware Plugin
VirtualBox Plugin
Edit your project and set:
Configure M2 Extra Build Steps --> Execute shell --> Type in whatever you'd like to do. For example:
# Wipe the local repository before each build.
rm -rf $WORKSPACE/.repository
Have a look at How do I trigger another job from hudson as a pre-build step?. I think this has been asked before there.