Search code examples
rubyamazon-ec2monitoringamazon-elastic-beanstalkworker

Keeping a Ruby Service running on Elastic Beanstalk


I have been looking for a while now on setting up worker nodes in a cloud native application. I plan to have an autoscaling group of worker nodes pulling jobs from a queue, nothing special there.

I am just wondering, is there any best practice way to ensure that a (eg. ruby) script is running at all times? My current assumption is that you have a script running that polls the queue for jobs and sleeps for a few seconds or so if a job query returns no new job.

What really caught my attention was the Services key in the Linux Custom Config section of AWS Elastic Beanstalk Documentation.

00_start_service.config

services: 
  sysvinit:
    <name of service>:
      enabled: true
      ensureRunning: true
      files: "<file name>"
      sources: "<directory>"    
      packages: 
          <name of package manager>:
          <package name>: <version>
      commands: 
         <name of command>:

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

The example they give is this..

services: 
  sysvinit:
    myservice:
      enabled: true
      ensureRunning: true

I find the example and documentation extremely vague and I have no idea how to get my own service up and running using this config key, which means I do not even know if this is what I want or need to use. I have tried creating a ruby executable file and putting the name in the field, but no luck.

I asked the AWS forums for more clarification and have received no response.

If anyone has any insight or direction on how this can be achieved, I would greatly appreciate it. Thank you!


Solution

  • I decided not to use the "services" section of the EB config files, instead just using the "commands" ..

    I build a service monitor in ruby that monitors a given system process (in this case my service).

    The service itself is a script looping infinitely with delays based on long polling times to the queue service.

    A cron job runs the monitor every minute and if the service is down it is restarted.