Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install and enable a service in amazon Elastic Beanstalk?

I'm banging my head against a wall trying to both install and then enable a service in elastic beanstalk. What I want to do is:

  1. Install a service in /etc/init.d that points to my python app in /opt/python/current/app/

  2. Have Elastic Beanstalk start and keep-alive the service, as specified in an .ebextensions/myapp.config file.

(Reference: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-services)

Here's my .ebextensions/myapp.config file:

container_commands:
  01_copy_service:
    command: "cp /opt/python/ondeck/app/my_service /etc/init.d/"
  02_chmod_service:
    command: "chmod +x /etc/init.d/my_service"

services:
  sysvinit:
    my_service:
      enabled: true
      ensureRunning: true
      files : [/etc/init.d/my_service]

This fails because services are run before container_commands. If I comment out services, deploy, then uncomment services, then deploy again, it will work. But I want to have a single-step deploy, because this will be an auto-scaling node.

Is there a solution? Thanks!

like image 924
Nate Avatar asked Feb 10 '14 16:02

Nate


People also ask

Which AWS services can be used with Elastic Beanstalk?

Elastic Beanstalk uses core AWS services such as Amazon Elastic Compute Cloud (EC2), Amazon Elastic Container Service (ECS), AWS Auto Scaling, and Elastic Load Balancing (ELB) to easily support applications that need to scale to serve millions of users.

How do I launch apps in Elastic Beanstalk?

Open the Elastic Beanstalk console , and in the Regions list, select your AWS Region. In the navigation pane, choose Applications, and then choose Create a new application. Use the on-screen form to provide an application name. Optionally, provide a description, and add tag keys and values.


2 Answers

Nate, I have the exact same scenario as you and I solved it this way:

Drop the "services" section and add a "restart" command.

container_commands:
  ...
  03_restart_service:
    command: /sbin/service my_service restart
like image 117
SureshKS Avatar answered Oct 15 '22 00:10

SureshKS


You can cause the service to restart after a command is run by using a commands: key under the services: key. The documentation for the services: key is here:

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-services

like image 44
Jim Flanagan Avatar answered Oct 14 '22 22:10

Jim Flanagan